/*
 * This class file was automatically generated by ASN1bean v1.12.0 (http://www.beanit.com)
 */

package com.beanit.asn1dsrc.dsrc;

import java.io.IOException;
import java.io.EOFException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.io.Serializable;
import com.beanit.asn1bean.ber.*;
import com.beanit.asn1bean.ber.types.*;
import com.beanit.asn1bean.ber.types.string.*;


public class CurrentLinkStateRoadSide implements BerType, Serializable {

	private static final long serialVersionUID = 1L;

	public static class LinkLinkidNumber implements BerType, Serializable {

		private static final long serialVersionUID = 1L;

		public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
		private byte[] code = null;
		private List<BerUTF8String> seqOf = null;

		public LinkLinkidNumber() {
			seqOf = new ArrayList<BerUTF8String>();
		}

		public LinkLinkidNumber(byte[] code) {
			this.code = code;
		}

		public List<BerUTF8String> getBerUTF8String() {
			if (seqOf == null) {
				seqOf = new ArrayList<BerUTF8String>();
			}
			return seqOf;
		}

		@Override public int encode(OutputStream reverseOS) throws IOException {
			return encode(reverseOS, true);
		}

		public int encode(OutputStream reverseOS, boolean withTag) throws IOException {

			if (code != null) {
				reverseOS.write(code);
				if (withTag) {
					return tag.encode(reverseOS) + code.length;
				}
				return code.length;
			}

			int codeLength = 0;
			for (int i = (seqOf.size() - 1); i >= 0; i--) {
				codeLength += seqOf.get(i).encode(reverseOS, true);
			}

			codeLength += BerLength.encodeLength(reverseOS, codeLength);

			if (withTag) {
				codeLength += tag.encode(reverseOS);
			}

			return codeLength;
		}

		@Override public int decode(InputStream is) throws IOException {
			return decode(is, true);
		}

		public int decode(InputStream is, boolean withTag) throws IOException {
			int tlByteCount = 0;
			int vByteCount = 0;
			BerTag berTag = new BerTag();
			if (withTag) {
				tlByteCount += tag.decodeAndCheck(is);
			}

			BerLength length = new BerLength();
			tlByteCount += length.decode(is);
			int lengthVal = length.val;

			while (vByteCount < lengthVal || lengthVal < 0) {
				vByteCount += berTag.decode(is);

				if (lengthVal < 0 && berTag.equals(0, 0, 0)) {
					vByteCount += BerLength.readEocByte(is);
					break;
				}

				if (!berTag.equals(BerUTF8String.tag)) {
					throw new IOException("Tag does not match mandatory sequence of/set of component.");
				}
				BerUTF8String element = new BerUTF8String();
				vByteCount += element.decode(is, false);
				seqOf.add(element);
			}
			if (lengthVal >= 0 && vByteCount != lengthVal) {
				throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + lengthVal + " but has " + vByteCount);

			}
			return tlByteCount + vByteCount;
		}

		public void encodeAndSave(int encodingSizeGuess) throws IOException {
			ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
			encode(reverseOS, false);
			code = reverseOS.getArray();
		}

		@Override public String toString() {
			StringBuilder sb = new StringBuilder();
			appendAsString(sb, 0);
			return sb.toString();
		}

		public void appendAsString(StringBuilder sb, int indentLevel) {

			sb.append("{\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			if (seqOf == null) {
				sb.append("null");
			}
			else {
				Iterator<BerUTF8String> it = seqOf.iterator();
				if (it.hasNext()) {
					sb.append(it.next());
					while (it.hasNext()) {
						sb.append(",\n");
						for (int i = 0; i < indentLevel + 1; i++) {
							sb.append("\t");
						}
						sb.append(it.next());
					}
				}
			}

			sb.append("\n");
			for (int i = 0; i < indentLevel; i++) {
				sb.append("\t");
			}
			sb.append("}");
		}

	}

	public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);

	private byte[] code = null;
	private BerVisibleString trntMessageCreativeGeneralizedTime = null;
	private LinkLinkidNumber linkLinkidNumber = null;
	private BerInteger linkSpeedRate = null;
	private BerInteger linkVolumeRate = null;
	private BerInteger linkDensityRate = null;
	private BerInteger linkTravelTimeQuantity = null;
	private BerInteger linkDelayQuanity = null;
	private BerInteger tfdtVehicleQueueLengthQuantity = null;
	private BerInteger tfdtOccupancyPercent = null;
	private BerInteger pcttPredictionAverageLinkSpeedRate = null;
	private BerInteger pcttPredictionTraverTimeQuantity = null;
	private BerVisibleString pcttPredictionTimeGeneralizedTime = null;
	private BerUTF8String pcttAdditionalInformationText = null;
	
	public CurrentLinkStateRoadSide() {
	}

	public CurrentLinkStateRoadSide(byte[] code) {
		this.code = code;
	}

	public void setTrntMessageCreativeGeneralizedTime(BerVisibleString trntMessageCreativeGeneralizedTime) {
		this.trntMessageCreativeGeneralizedTime = trntMessageCreativeGeneralizedTime;
	}

	public BerVisibleString getTrntMessageCreativeGeneralizedTime() {
		return trntMessageCreativeGeneralizedTime;
	}

	public void setLinkLinkidNumber(LinkLinkidNumber linkLinkidNumber) {
		this.linkLinkidNumber = linkLinkidNumber;
	}

	public LinkLinkidNumber getLinkLinkidNumber() {
		return linkLinkidNumber;
	}

	public void setLinkSpeedRate(BerInteger linkSpeedRate) {
		this.linkSpeedRate = linkSpeedRate;
	}

	public BerInteger getLinkSpeedRate() {
		return linkSpeedRate;
	}

	public void setLinkVolumeRate(BerInteger linkVolumeRate) {
		this.linkVolumeRate = linkVolumeRate;
	}

	public BerInteger getLinkVolumeRate() {
		return linkVolumeRate;
	}

	public void setLinkDensityRate(BerInteger linkDensityRate) {
		this.linkDensityRate = linkDensityRate;
	}

	public BerInteger getLinkDensityRate() {
		return linkDensityRate;
	}

	public void setLinkTravelTimeQuantity(BerInteger linkTravelTimeQuantity) {
		this.linkTravelTimeQuantity = linkTravelTimeQuantity;
	}

	public BerInteger getLinkTravelTimeQuantity() {
		return linkTravelTimeQuantity;
	}

	public void setLinkDelayQuanity(BerInteger linkDelayQuanity) {
		this.linkDelayQuanity = linkDelayQuanity;
	}

	public BerInteger getLinkDelayQuanity() {
		return linkDelayQuanity;
	}

	public void setTfdtVehicleQueueLengthQuantity(BerInteger tfdtVehicleQueueLengthQuantity) {
		this.tfdtVehicleQueueLengthQuantity = tfdtVehicleQueueLengthQuantity;
	}

	public BerInteger getTfdtVehicleQueueLengthQuantity() {
		return tfdtVehicleQueueLengthQuantity;
	}

	public void setTfdtOccupancyPercent(BerInteger tfdtOccupancyPercent) {
		this.tfdtOccupancyPercent = tfdtOccupancyPercent;
	}

	public BerInteger getTfdtOccupancyPercent() {
		return tfdtOccupancyPercent;
	}

	public void setPcttPredictionAverageLinkSpeedRate(BerInteger pcttPredictionAverageLinkSpeedRate) {
		this.pcttPredictionAverageLinkSpeedRate = pcttPredictionAverageLinkSpeedRate;
	}

	public BerInteger getPcttPredictionAverageLinkSpeedRate() {
		return pcttPredictionAverageLinkSpeedRate;
	}

	public void setPcttPredictionTraverTimeQuantity(BerInteger pcttPredictionTraverTimeQuantity) {
		this.pcttPredictionTraverTimeQuantity = pcttPredictionTraverTimeQuantity;
	}

	public BerInteger getPcttPredictionTraverTimeQuantity() {
		return pcttPredictionTraverTimeQuantity;
	}

	public void setPcttPredictionTimeGeneralizedTime(BerVisibleString pcttPredictionTimeGeneralizedTime) {
		this.pcttPredictionTimeGeneralizedTime = pcttPredictionTimeGeneralizedTime;
	}

	public BerVisibleString getPcttPredictionTimeGeneralizedTime() {
		return pcttPredictionTimeGeneralizedTime;
	}

	public void setPcttAdditionalInformationText(BerUTF8String pcttAdditionalInformationText) {
		this.pcttAdditionalInformationText = pcttAdditionalInformationText;
	}

	public BerUTF8String getPcttAdditionalInformationText() {
		return pcttAdditionalInformationText;
	}

	@Override public int encode(OutputStream reverseOS) throws IOException {
		return encode(reverseOS, true);
	}

	public int encode(OutputStream reverseOS, boolean withTag) throws IOException {

		if (code != null) {
			reverseOS.write(code);
			if (withTag) {
				return tag.encode(reverseOS) + code.length;
			}
			return code.length;
		}

		int codeLength = 0;
		if (pcttAdditionalInformationText != null) {
			codeLength += pcttAdditionalInformationText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 12
			reverseOS.write(0x8C);
			codeLength += 1;
		}
		
		if (pcttPredictionTimeGeneralizedTime != null) {
			codeLength += pcttPredictionTimeGeneralizedTime.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 11
			reverseOS.write(0x8B);
			codeLength += 1;
		}
		
		if (pcttPredictionTraverTimeQuantity != null) {
			codeLength += pcttPredictionTraverTimeQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 10
			reverseOS.write(0x8A);
			codeLength += 1;
		}
		
		if (pcttPredictionAverageLinkSpeedRate != null) {
			codeLength += pcttPredictionAverageLinkSpeedRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 9
			reverseOS.write(0x89);
			codeLength += 1;
		}
		
		if (tfdtOccupancyPercent != null) {
			codeLength += tfdtOccupancyPercent.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 8
			reverseOS.write(0x88);
			codeLength += 1;
		}
		
		if (tfdtVehicleQueueLengthQuantity != null) {
			codeLength += tfdtVehicleQueueLengthQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 7
			reverseOS.write(0x87);
			codeLength += 1;
		}
		
		if (linkDelayQuanity != null) {
			codeLength += linkDelayQuanity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 6
			reverseOS.write(0x86);
			codeLength += 1;
		}
		
		if (linkTravelTimeQuantity != null) {
			codeLength += linkTravelTimeQuantity.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 5
			reverseOS.write(0x85);
			codeLength += 1;
		}
		
		if (linkDensityRate != null) {
			codeLength += linkDensityRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 4
			reverseOS.write(0x84);
			codeLength += 1;
		}
		
		if (linkVolumeRate != null) {
			codeLength += linkVolumeRate.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 3
			reverseOS.write(0x83);
			codeLength += 1;
		}
		
		codeLength += linkSpeedRate.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 2
		reverseOS.write(0x82);
		codeLength += 1;
		
		codeLength += linkLinkidNumber.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, CONSTRUCTED, 1
		reverseOS.write(0xA1);
		codeLength += 1;
		
		codeLength += trntMessageCreativeGeneralizedTime.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 0
		reverseOS.write(0x80);
		codeLength += 1;
		
		codeLength += BerLength.encodeLength(reverseOS, codeLength);

		if (withTag) {
			codeLength += tag.encode(reverseOS);
		}

		return codeLength;

	}

	@Override public int decode(InputStream is) throws IOException {
		return decode(is, true);
	}

	public int decode(InputStream is, boolean withTag) throws IOException {
		int tlByteCount = 0;
		int vByteCount = 0;
		BerTag berTag = new BerTag();

		if (withTag) {
			tlByteCount += tag.decodeAndCheck(is);
		}

		BerLength length = new BerLength();
		tlByteCount += length.decode(is);
		int lengthVal = length.val;
		vByteCount += berTag.decode(is);

		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
			trntMessageCreativeGeneralizedTime = new BerVisibleString();
			vByteCount += trntMessageCreativeGeneralizedTime.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
			linkLinkidNumber = new LinkLinkidNumber();
			vByteCount += linkLinkidNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
			linkSpeedRate = new BerInteger();
			vByteCount += linkSpeedRate.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
			linkVolumeRate = new BerInteger();
			vByteCount += linkVolumeRate.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 4)) {
			linkDensityRate = new BerInteger();
			vByteCount += linkDensityRate.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
			linkTravelTimeQuantity = new BerInteger();
			vByteCount += linkTravelTimeQuantity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
			linkDelayQuanity = new BerInteger();
			vByteCount += linkDelayQuanity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
			tfdtVehicleQueueLengthQuantity = new BerInteger();
			vByteCount += tfdtVehicleQueueLengthQuantity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
			tfdtOccupancyPercent = new BerInteger();
			vByteCount += tfdtOccupancyPercent.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) {
			pcttPredictionAverageLinkSpeedRate = new BerInteger();
			vByteCount += pcttPredictionAverageLinkSpeedRate.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) {
			pcttPredictionTraverTimeQuantity = new BerInteger();
			vByteCount += pcttPredictionTraverTimeQuantity.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
			pcttPredictionTimeGeneralizedTime = new BerVisibleString();
			vByteCount += pcttPredictionTimeGeneralizedTime.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) {
			pcttAdditionalInformationText = new BerUTF8String();
			vByteCount += pcttAdditionalInformationText.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (lengthVal < 0) {
			if (!berTag.equals(0, 0, 0)) {
				throw new IOException("Decoded sequence has wrong end of contents octets");
			}
			vByteCount += BerLength.readEocByte(is);
			return tlByteCount + vByteCount;
		}

		throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);

	}

	public void encodeAndSave(int encodingSizeGuess) throws IOException {
		ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
		encode(reverseOS, false);
		code = reverseOS.getArray();
	}

	@Override public String toString() {
		StringBuilder sb = new StringBuilder();
		appendAsString(sb, 0);
		return sb.toString();
	}

	public void appendAsString(StringBuilder sb, int indentLevel) {

		sb.append("{");
		sb.append("\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (trntMessageCreativeGeneralizedTime != null) {
			sb.append("trntMessageCreativeGeneralizedTime: ").append(trntMessageCreativeGeneralizedTime);
		}
		else {
			sb.append("trntMessageCreativeGeneralizedTime: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (linkLinkidNumber != null) {
			sb.append("linkLinkidNumber: ");
			linkLinkidNumber.appendAsString(sb, indentLevel + 1);
		}
		else {
			sb.append("linkLinkidNumber: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (linkSpeedRate != null) {
			sb.append("linkSpeedRate: ").append(linkSpeedRate);
		}
		else {
			sb.append("linkSpeedRate: <empty-required-field>");
		}
		
		if (linkVolumeRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkVolumeRate: ").append(linkVolumeRate);
		}
		
		if (linkDensityRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkDensityRate: ").append(linkDensityRate);
		}
		
		if (linkTravelTimeQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkTravelTimeQuantity: ").append(linkTravelTimeQuantity);
		}
		
		if (linkDelayQuanity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("linkDelayQuanity: ").append(linkDelayQuanity);
		}
		
		if (tfdtVehicleQueueLengthQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("tfdtVehicleQueueLengthQuantity: ").append(tfdtVehicleQueueLengthQuantity);
		}
		
		if (tfdtOccupancyPercent != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("tfdtOccupancyPercent: ").append(tfdtOccupancyPercent);
		}
		
		if (pcttPredictionAverageLinkSpeedRate != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("pcttPredictionAverageLinkSpeedRate: ").append(pcttPredictionAverageLinkSpeedRate);
		}
		
		if (pcttPredictionTraverTimeQuantity != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("pcttPredictionTraverTimeQuantity: ").append(pcttPredictionTraverTimeQuantity);
		}
		
		if (pcttPredictionTimeGeneralizedTime != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("pcttPredictionTimeGeneralizedTime: ").append(pcttPredictionTimeGeneralizedTime);
		}
		
		if (pcttAdditionalInformationText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("pcttAdditionalInformationText: ").append(pcttAdditionalInformationText);
		}
		
		sb.append("\n");
		for (int i = 0; i < indentLevel; i++) {
			sb.append("\t");
		}
		sb.append("}");
	}

}

