All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xmlobjects.xal.adapter.deprecated.helper.ParsedNumber Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
/*
 * xal-objects - A Java mapping for the OASIS eXtensible Address Language (xAL)
 * https://github.com/xmlobjects/xal-objects
 *
 * Copyright 2019-2023 Claus Nagel 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.xmlobjects.xal.adapter.deprecated.helper;

import org.xmlobjects.xal.model.types.Identifier;
import org.xmlobjects.xal.model.types.IdentifierElementType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ParsedNumber {
    private IdentifierElementType type;
    private List prefixes;
    private List numbers;
    private List suffixes;

    IdentifierElementType getType() {
        return type;
    }

    public List getPrefixes() {
        return prefixes != null ? prefixes : Collections.emptyList();
    }

    public List getNumbers() {
        return numbers != null ? numbers : Collections.emptyList();
    }

    public List getSuffixes() {
        return suffixes != null ? suffixes : Collections.emptyList();
    }

    void add(Identifier identifier) {
        IdentifierElementType type = identifier.getType();

        if (type == IdentifierElementType.PREFIX) {
            if (prefixes == null)
                prefixes = new ArrayList<>();

            prefixes.add(identifier);
        } else if (type == IdentifierElementType.SUFFIX) {
            if (suffixes == null)
                suffixes = new ArrayList<>();

            suffixes.add(identifier);
        } else {
            if (numbers == null) {
                numbers = new ArrayList<>();
                this.type = type;
            }

            numbers.add(identifier);
        }
    }

    boolean accepts(Identifier identifier) {
        IdentifierElementType type = identifier.getType();

        if (type == IdentifierElementType.PREFIX)
            return numbers == null;
        else if (type == IdentifierElementType.SUFFIX)
            return numbers != null || suffixes != null;
        else
            return suffixes == null && (numbers == null || this.type == type);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy