PageRenderTime 70ms CodeModel.GetById 62ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/parameter/AffectedPointCodeImpl.java

http://mobicents.googlecode.com/
Java | 109 lines | 61 code | 19 blank | 29 comment | 2 complexity | 188f36742974d0ad376c841037cbfacd MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.protocols.ss7.m3ua.impl.parameter;
 24
 25import java.util.Arrays;
 26
 27import org.mobicents.protocols.ss7.m3ua.parameter.AffectedPointCode;
 28import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
 29
 30/**
 31 * 
 32 * @author amit bhayani
 33 * 
 34 */
 35public class AffectedPointCodeImpl extends ParameterImpl implements
 36        AffectedPointCode {
 37
 38    private byte[] value;
 39    private int[] pointCodes;
 40    private short[] masks;
 41
 42    protected AffectedPointCodeImpl(byte[] value) {
 43        this.tag = Parameter.Affected_Point_Code;
 44
 45        int count = 0;
 46        int arrSize = 0;
 47        pointCodes = new int[(value.length / 4)];
 48        masks = new short[(value.length / 4)];
 49
 50        while (count < value.length) {
 51            masks[arrSize] = value[count++];
 52
 53            pointCodes[arrSize] = 0;
 54            pointCodes[arrSize] |= value[count++] & 0xFF;
 55            pointCodes[arrSize] <<= 8;
 56            pointCodes[arrSize] |= value[count++] & 0xFF;
 57            pointCodes[arrSize] <<= 8;
 58            pointCodes[arrSize++] |= value[count++] & 0xFF;
 59        }
 60        this.value = value;
 61    }
 62
 63    protected AffectedPointCodeImpl(int[] pointCodes, short[] masks) {
 64        this.tag = Parameter.Affected_Point_Code;
 65        this.pointCodes = pointCodes;
 66        this.masks = masks;
 67        encode();
 68    }
 69
 70    private void encode() {
 71        // create byte array taking into account data, point codes and
 72        // indicators;
 73
 74        this.value = new byte[(pointCodes.length * 4)];
 75
 76        int count = 0;
 77        int arrSize = 0;
 78        // encode routing context
 79        while (count < value.length) {
 80            value[count++] = (byte) (masks[arrSize]);
 81
 82            value[count++] = (byte) (pointCodes[arrSize] >>> 16);
 83            value[count++] = (byte) (pointCodes[arrSize] >>> 8);
 84            value[count++] = (byte) (pointCodes[arrSize++]);
 85        }
 86    }
 87
 88    @Override
 89    protected byte[] getValue() {
 90        return this.value;
 91    }
 92
 93    public short[] getMasks() {
 94        return this.masks;
 95    }
 96
 97    public int[] getPointCodes() {
 98        return this.pointCodes;
 99    }
100
101    @Override
102    public String toString() {
103        return String
104                .format("AffectedPointCode pointCode=%s mask=%s",
105                        Arrays.toString(this.pointCodes), Arrays
106                                .toString(this.masks));
107    }
108
109}