@Override public void putArray(boolean described, DataType type) { putElement(new ArrayElement(_parent, _current, described, type)); }
@Override public Element addChild(Element element) { if(isDescribed() || element.getDataType() == _arrayType) { _first = element; return element; } else { Element replacement = coerce(element); if(replacement != null) { _first = replacement; return replacement; } throw new IllegalArgumentException("Attempting to add instance of " + element.getDataType() + " to array of " + _arrayType); } }
@Override public int size() { if(isElementOfArray()) { final ArrayElement parent = (ArrayElement) parent(); if(parent.constructorType() == ArrayElement.SMALL) { if(-128 <= _value && _value <= 127) { return 1; } else { parent.setConstructorType(ArrayElement.LARGE); return 4; } } else { return 4; } } else { return (-128 <= _value && _value <= 127) ? 2 : 5; } }
@Override String startSymbol() { return String.format("%s%s[", isDescribed() ? "D" : "", getArrayDataType()); }
while (oldConstructorType != constructorType()); if(isDescribed()) if(isElementOfArray()) ArrayElement parent = (ArrayElement)parent(); if(parent.constructorType()==SMALL) parent.setConstructorType(LARGE); bodySize+=8;
@Override public int encode(ByteBuffer b) int size = size(); final int count = (int) count(); if(!isElementOfArray()) ArrayElement parent = (ArrayElement)parent(); if(parent.constructorType()==SMALL) if(isDescribed()) break; case UINT: switch (constructorType()) break; case ULONG: switch (constructorType())
if(parent.constructorType() == ArrayElement.SMALL)
@Override public Object[] getValue() { if(isDescribed()) { DescribedType[] rVal = new DescribedType[(int) count()]; Object descriptor = _first == null ? null : _first.getValue(); Element element = _first == null ? null : _first.next(); int i = 0; while(element != null) { rVal[i++] = new DescribedTypeImpl(descriptor, element.getValue()); element = element.next(); } return rVal; } else { Object[] rVal = new Object[(int) count()]; Element element = _first; int i = 0; while (element!=null) { rVal[i++] = element.getValue(); element = element.next(); } return rVal; } }
@Override public boolean isArrayDescribed() { if(_current instanceof ArrayElement) { return ((ArrayElement)_current).isDescribed(); } throw new IllegalStateException("Current value not array"); }
@Override public long getArray() { if(_current instanceof ArrayElement) { return ((ArrayElement)_current).count(); } throw new IllegalStateException("Current value not array"); }
@Override public Object[] getJavaArray() { if(_current instanceof ArrayElement) { return ((ArrayElement)_current).getValue(); } throw new IllegalStateException("Current value not array"); }
@Override public DataType getArrayType() { if(_current instanceof ArrayElement) { return ((ArrayElement)_current).getArrayDataType(); } throw new IllegalStateException("Current value not array"); }
@Override public Element checkChild(Element element) { if(element.getDataType() != _arrayType) { Element replacement = coerce(element); if(replacement != null) { return replacement; } throw new IllegalArgumentException("Attempting to add instance of " + element.getDataType() + " to array of " + _arrayType); } return element; }
ArrayElement(Element parent, Element prev, boolean described, Data.DataType type) { super(parent, prev); _described = described; _arrayType = type; if(_arrayType == null) { throw new NullPointerException("Array type cannot be null"); } else if(_arrayType == Data.DataType.DESCRIBED) { throw new IllegalArgumentException("Array type cannot be DESCRIBED"); } switch(_arrayType) { case UINT: case ULONG: case LIST: setConstructorType(TINY); break; default: setConstructorType(SMALL); } }
@Override public int encode(ByteBuffer b) int size = size(); final int count = (int) count(); if(!isElementOfArray()) ArrayElement parent = (ArrayElement)parent(); if(parent.constructorType()==SMALL) if(isDescribed()) break; case UINT: switch (constructorType()) break; case ULONG: switch (constructorType())
while (oldConstructorType != constructorType()); if(isDescribed()) if(isElementOfArray()) ArrayElement parent = (ArrayElement)parent(); if(parent.constructorType()==SMALL) parent.setConstructorType(LARGE); bodySize+=8;
if(parent.constructorType() == ArrayElement.SMALL)
@Override public Object[] getValue() if(isDescribed()) DescribedType[] rVal = new DescribedType[(int) count()]; Object descriptor = _first == null ? null : _first.getValue(); Element element = _first == null ? null : _first.next(); Symbol[] rVal = new Symbol[(int) count()]; SymbolElement element = (SymbolElement) _first; int i = 0; Object[] rVal = new Object[(int) count()]; Element element = _first; int i = 0;
@Override public boolean isArrayDescribed() { if(_current instanceof ArrayElement) { return ((ArrayElement)_current).isDescribed(); } throw new IllegalStateException("Current value not array"); }
@Override String startSymbol() { return String.format("%s%s[", isDescribed() ? "D" : "", getArrayDataType()); }