@Test public void testGetNumber() { final MetadataDescriptor desc = new MetadataDescriptor("name"); desc.setWordValue(555); Assert.assertEquals(555l, desc.getNumber()); desc.setDWordValue(444); Assert.assertEquals(444l, desc.getNumber()); desc.setQWordValue(333); Assert.assertEquals(333l, desc.getNumber()); desc.setBooleanValue(true); Assert.assertEquals(1l, desc.getNumber()); desc.setStringValue("Hallo"); try { desc.getNumber(); Assert.fail("Exception excpected."); } catch (UnsupportedOperationException e) { } desc.setBinaryValue(new byte[]{1, 1, 1, 1}); try { desc.getNumber(); Assert.fail("Exception excpected."); } catch (UnsupportedOperationException e) { } }
public long getNumber() { int bytesNeeded; switch (getType()) { case TYPE_BOOLEAN: bytesNeeded = 1; break; case TYPE_DWORD: bytesNeeded = 4; break; case TYPE_QWORD: bytesNeeded = 8; break; case TYPE_WORD: bytesNeeded = 2; break; default: throw new UnsupportedOperationException("The current type doesn't allow an interpretation as a number. (" + getType() + ")"); } if (bytesNeeded > this.content.length) { throw new IllegalStateException("The stored data cannot represent the type of current object."); } long result = 0; for (int i = 0; i < bytesNeeded; i++) { result |= (((long)this.content[i] & 0xFF) << (i * 8)); } return result; }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public long getNumber() { int bytesNeeded; switch (getType()) { case TYPE_BOOLEAN: bytesNeeded = 1; break; case TYPE_DWORD: bytesNeeded = 4; break; case TYPE_QWORD: bytesNeeded = 8; break; case TYPE_WORD: bytesNeeded = 2; break; default: throw new UnsupportedOperationException("The current type doesn't allow an interpretation as a number. (" + getType() + ")"); } if (bytesNeeded > this.content.length) { throw new IllegalStateException("The stored data cannot represent the type of current object."); } long result = 0; for (int i = 0; i < bytesNeeded; i++) { result |= (((long)this.content[i] & 0xFF) << (i * 8)); } return result; } }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public long getNumber() { int bytesNeeded; switch (getType()) { case TYPE_BOOLEAN: bytesNeeded = 1; break; case TYPE_DWORD: bytesNeeded = 4; break; case TYPE_QWORD: bytesNeeded = 8; break; case TYPE_WORD: bytesNeeded = 2; break; default: throw new UnsupportedOperationException("The current type doesn't allow an interpretation as a number. (" + getType() + ")"); } if (bytesNeeded > this.content.length) { throw new IllegalStateException("The stored data cannot represent the type of current object."); } long result = 0; for (int i = 0; i < bytesNeeded; i++) { result |= (((long)this.content[i] & 0xFF) << (i * 8)); } return result; } MetadataDescriptor(final ContainerType type, final String propName, final int propType);  MetadataDescriptor(final ContainerType type,
                            final String propName,
                            final int propType,
                            final int stream,
                            final int language);  MetadataDescriptor(final String propName);  MetadataDescriptor(final String propName, final int propType); }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public long getNumber() { int bytesNeeded; switch (getType()) { case TYPE_BOOLEAN: bytesNeeded = 1; break; case TYPE_DWORD: bytesNeeded = 4; break; case TYPE_QWORD: bytesNeeded = 8; break; case TYPE_WORD: bytesNeeded = 2; break; default: throw new UnsupportedOperationException("The current type doesn't allow an interpretation as a number. (" + getType() + ")"); } if (bytesNeeded > this.content.length) { throw new IllegalStateException("The stored data cannot represent the type of current object."); } long result = 0; for (int i = 0; i < bytesNeeded; i++) { result |= (((long)this.content[i] & 0xFF) << (i * 8)); } return result; } MetadataDescriptor(final ContainerType type, final String propName, final int propType);  MetadataDescriptor(final ContainerType type,
                            final String propName,
                            final int propType,
                            final int stream,
                            final int language);  MetadataDescriptor(final String propName);  MetadataDescriptor(final String propName, final int propType); @Override Object clone(); int compareTo(final MetadataDescriptor other); MetadataDescriptor createCopy(); @Override boolean equals(final Object obj); boolean getBoolean(); @Deprecated byte[] getBytes(); ContainerType getContainerType(); GUID getGuid(); String getName(); long getNumber(); byte[] getRawData(); int getRawDataSize(); String getString(); int getType(); @Override int hashCode(); boolean isEmpty(); void setBinaryValue(final byte[] data); void setBooleanValue(final boolean value); void setDWordValue(final long value); void setGUIDValue(final GUID value); void setQWordValue(final long value); void setString(final String value); void setStringValue(final String value); void setWordValue(final int value); @Override String toString(); }
MetadataDescriptor implements Comparable<MetadataDescriptor>, Cloneable { public long getNumber() { int bytesNeeded; switch (getType()) { case TYPE_BOOLEAN: bytesNeeded = 1; break; case TYPE_DWORD: bytesNeeded = 4; break; case TYPE_QWORD: bytesNeeded = 8; break; case TYPE_WORD: bytesNeeded = 2; break; default: throw new UnsupportedOperationException("The current type doesn't allow an interpretation as a number. (" + getType() + ")"); } if (bytesNeeded > this.content.length) { throw new IllegalStateException("The stored data cannot represent the type of current object."); } long result = 0; for (int i = 0; i < bytesNeeded; i++) { result |= (((long)this.content[i] & 0xFF) << (i * 8)); } return result; } MetadataDescriptor(final ContainerType type, final String propName, final int propType);  MetadataDescriptor(final ContainerType type,
                            final String propName,
                            final int propType,
                            final int stream,
                            final int language);  MetadataDescriptor(final String propName);  MetadataDescriptor(final String propName, final int propType); @Override Object clone(); int compareTo(final MetadataDescriptor other); MetadataDescriptor createCopy(); @Override boolean equals(final Object obj); boolean getBoolean(); @Deprecated byte[] getBytes(); ContainerType getContainerType(); GUID getGuid(); String getName(); long getNumber(); byte[] getRawData(); int getRawDataSize(); String getString(); int getType(); @Override int hashCode(); boolean isEmpty(); void setBinaryValue(final byte[] data); void setBooleanValue(final boolean value); void setDWordValue(final long value); void setGUIDValue(final GUID value); void setQWordValue(final long value); void setString(final String value); void setStringValue(final String value); void setWordValue(final int value); @Override String toString(); static final long DWORD_MAXVALUE; static final int MAX_LANG_INDEX; static final int MAX_STREAM_NUMBER; final static int TYPE_BINARY; final static int TYPE_BOOLEAN; final static int TYPE_DWORD; final static int TYPE_GUID; final static int TYPE_QWORD; final static int TYPE_STRING; final static int TYPE_WORD; }