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

org.restcomm.protocols.ss7.map.service.lsm.AreaDefinitionImpl Maven / Gradle / Ivy

/*
 * Mobius Software LTD
 * Copyright 2019, Mobius Software LTD and individual contributors
 * by the @authors tag.
 *
 * This program is free software: you can redistribute it and/or modify
 * under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see 
 */

package org.restcomm.protocols.ss7.map.service.lsm;

import java.util.List;

import org.restcomm.protocols.ss7.map.api.service.lsm.Area;
import org.restcomm.protocols.ss7.map.api.service.lsm.AreaDefinition;

import com.mobius.software.telco.protocols.ss7.asn.ASNClass;
import com.mobius.software.telco.protocols.ss7.asn.annotations.ASNProperty;
import com.mobius.software.telco.protocols.ss7.asn.annotations.ASNTag;
import com.mobius.software.telco.protocols.ss7.asn.annotations.ASNValidate;
import com.mobius.software.telco.protocols.ss7.asn.exceptions.ASNParsingComponentException;
import com.mobius.software.telco.protocols.ss7.asn.exceptions.ASNParsingComponentExceptionReason;

/**
 * @author amit bhayani
 * @author sergey vetyutnev
 * @author yulianoifa
 *
 */
@ASNTag(asnClass=ASNClass.UNIVERSAL,tag=16,constructed=true,lengthIndefinite=false)
public class AreaDefinitionImpl implements AreaDefinition {
	@ASNProperty(asnClass=ASNClass.CONTEXT_SPECIFIC,tag=0,constructed=true,index=-1)
    private AreaListWrapperImpl areaList = null;

    /**
     *
     */
    public AreaDefinitionImpl() {
    }

    /**
     * @param areaList
     */
    public AreaDefinitionImpl(List areaList) {
        if(areaList!=null)
        	this.areaList = new AreaListWrapperImpl(areaList);
    }

    /*
     * (non-Javadoc)
     *
     * @see org.restcomm.protocols.ss7.map.api.service.lsm.AreaDefinition#getAreaList ()
     */
    public List getAreaList() {
    	if(this.areaList==null)
    		return null;
    	
        return this.areaList.getArea();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        if (this.areaList != null && this.areaList.getArea()!=null) {
            for (int i = 0; i < areaList.getArea().size(); i++) {
                Area a1 = areaList.getArea().get(i);
                result = prime * result + ((a1 == null) ? 0 : a1.hashCode());
            }
        }
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        AreaDefinitionImpl other = (AreaDefinitionImpl) obj;
        if (areaList == null || areaList.getArea() == null) {
            if (other.areaList != null && other.areaList.getArea()!=null)
                return false;
        } else {
            if (areaList.getArea().size() != other.areaList.getArea().size())
                return false;
            for (int i = 0; i < areaList.getArea().size(); i++) {
                Area a1 = areaList.getArea().get(i);
                Area a2 = other.areaList.getArea().get(i);
                if (a1 == null) {
                    if (a2 != null)
                        return false;
                } else {
                    if (!a1.equals(a2))
                        return false;
                }
            }
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("AreaDefinition [");

        if (this.areaList != null && this.areaList.getArea()!=null) {
            sb.append("areaList [");
            for (Area a1:this.areaList.getArea()) {
                sb.append("area=");
                sb.append(a1);
                sb.append(", ");
            }
            sb.append("]");
        }
        sb.append("]");

        return sb.toString();
    }
	
	@ASNValidate
	public void validateElement() throws ASNParsingComponentException {
		if(areaList==null || areaList.getArea()==null || areaList.getArea().size()==0)
			throw new ASNParsingComponentException("area list should be set for area definition", ASNParsingComponentExceptionReason.MistypedParameter);
		
		if(areaList.getArea().size()>10)
			throw new ASNParsingComponentException("area list size should be between 1 and 10 for area definition", ASNParsingComponentExceptionReason.MistypedParameter);		
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy