src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
---|---|
ByteUtils { public static byte[] floatToBytesBE(float f, byte[] bytes, int off) { return intToBytesBE(Float.floatToIntBits(f), bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testFloatToBytesBE() { assertArrayEquals(FLOAT_PI_BE , ByteUtils.floatToBytesBE((float) Math.PI, new byte[4], 0)); } |
ByteUtils { public static byte[] floatToBytesLE(float f, byte[] bytes, int off) { return intToBytesLE(Float.floatToIntBits(f), bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testFloatToBytesLE() { assertArrayEquals(FLOAT_PI_LE , ByteUtils.floatToBytesLE((float) Math.PI, new byte[4], 0)); } |
ByteUtils { public static byte[] doubleToBytesBE(double d, byte[] bytes, int off) { return longToBytesBE(Double.doubleToLongBits(d), bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testDoubleToBytesBE() { assertArrayEquals(DOUBLE_PI_BE , ByteUtils.doubleToBytesBE(Math.PI, new byte[8], 0)); } |
ByteUtils { public static byte[] doubleToBytesLE(double d, byte[] bytes, int off) { return longToBytesLE(Double.doubleToLongBits(d), bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testDoubleToBytesLE() { assertArrayEquals(DOUBLE_PI_LE , ByteUtils.doubleToBytesLE(Math.PI, new byte[8], 0)); } |
ByteUtils { public static byte[][] swapShorts(byte bs[][]) { int carry = 0; for (int i = 0; i < bs.length; i++) { byte[] b = bs[i]; if (carry != 0) swapLastFirst(bs[i-1], b); int len = b.length - carry; swapShorts(b, carry, len & ~1); carry = len & 1; } return bs; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testSwapShorts() { assertArrayEquals(TAG_PIXEL_DATA_LE , ByteUtils.swapShorts(TAG_PIXEL_DATA_BE.clone(), 0, TAG_PIXEL_DATA_BE.length)); } |
ByteUtils { public static byte[] swapInts(byte b[], int off, int len) { checkLength(len, 4); for (int i = off, n = off + len; i < n; i += 4) { swap(b, i, i+3); swap(b, i+1, i+2); } return b; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testSwapInts() { assertArrayEquals(FLOAT_PI_LE , ByteUtils.swapInts(FLOAT_PI_BE.clone(), 0, FLOAT_PI_BE.length)); } |
ByteUtils { public static byte[] swapLongs(byte b[], int off, int len) { checkLength(len, 8); for (int i = off, n = off + len; i < n; i += 8) { swap(b, i, i+7); swap(b, i+1, i+6); swap(b, i+2, i+5); swap(b, i+3, i+4); } return b; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testSwapLongs() { assertArrayEquals(DOUBLE_PI_LE , ByteUtils.swapLongs(DOUBLE_PI_BE.clone(), 0, DOUBLE_PI_BE.length)); } |
DicomInputStream extends FilterInputStream implements DicomInputHandler, BulkDataCreator { public Attributes readDataset(int len, int stopTag) throws IOException { handler.startDataset(this); readFileMetaInformation(); Attributes attrs = new Attributes(bigEndian, 64); readAttributes(attrs, len, stopTag); attrs.trimToSize(); handler.endDataset(this); return attrs; } DicomInputStream(InputStream in, String tsuid); DicomInputStream(InputStream in); DicomInputStream(File file); final String getTransferSyntax(); final int getAllocateLimit(); final void setAllocateLimit(int allocateLimit); final String getURI(); final void setURI(String uri); final IncludeBulkData getIncludeBulkData(); final void setIncludeBulkData(IncludeBulkData includeBulkData); final BulkDataDescriptor getBulkDataDescriptor(); final void setBulkDataDescriptor(BulkDataDescriptor bulkDataDescriptor); final String getBulkDataFilePrefix(); final void setBulkDataFilePrefix(String blkFilePrefix); final String getBulkDataFileSuffix(); final void setBulkDataFileSuffix(String blkFileSuffix); final File getBulkDataDirectory(); final void setBulkDataDirectory(File blkDirectory); final boolean isConcatenateBulkDataFiles(); final void setConcatenateBulkDataFiles(boolean catBlkFiles); final List<File> getBulkDataFiles(); final void setDicomInputHandler(DicomInputHandler handler); void setBulkDataCreator(BulkDataCreator bulkDataCreator); final void setFileMetaInformationGroupLength(byte[] val); final byte[] getPreamble(); Attributes getFileMetaInformation(); final int level(); final int tag(); final VR vr(); final int length(); final long getPosition(); void setPosition(long pos); long getTagPosition(); final boolean bigEndian(); final boolean explicitVR(); boolean isExcludeBulkData(); boolean isIncludeBulkDataURI(); static String toAttributePath(List<ItemPointer> itemPointers, int tag); String getAttributePath(); @Override void close(); @Override synchronized void mark(int readlimit); @Override synchronized void reset(); @Override final int read(); @Override final int read(byte[] b, int off, int len); @Override final int read(byte[] b); @Override final long skip(long n); void skipFully(long n); void readFully(byte b[]); void readFully(byte b[], int off, int len); void readFully(short[] s, int off, int len); void readHeader(); boolean readItemHeader(); Attributes readCommand(); Attributes readDataset(int len, int stopTag); Attributes readFileMetaInformation(); void readAttributes(Attributes attrs, int len, int stopTag); @Override void readValue(DicomInputStream dis, Attributes attrs); @Override BulkData createBulkData(DicomInputStream dis); @Override void readValue(DicomInputStream dis, Sequence seq); @Override void readValue(DicomInputStream dis, Fragments frags); @Override void startDataset(DicomInputStream dis); @Override void endDataset(DicomInputStream dis); Attributes readItem(); byte[] readValue(); } | @Test(expected = EOFException.class) public void testNoOutOfMemoryErrorOnInvalidLength() throws IOException { byte[] b = { 8, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 'e', 'v', 'i', 'l', 'l', 'e', 'n', 'g', 'h' }; try ( DicomInputStream in = new DicomInputStream(new ByteArrayInputStream(b))) { in.readDataset(-1, -1); } } |
DicomOutputStream extends FilterOutputStream { public void writeCommand(Attributes cmd) throws IOException { if (explicitVR || bigEndian) throw new IllegalStateException("explicitVR=" + explicitVR + ", bigEndian=" + bigEndian); cmd.writeGroupTo(this, Tag.CommandGroupLength); } DicomOutputStream(OutputStream out, String tsuid); DicomOutputStream(File file); final void setPreamble(byte[] preamble); final boolean isExplicitVR(); final boolean isBigEndian(); final DicomEncodingOptions getEncodingOptions(); final void setEncodingOptions(DicomEncodingOptions encOpts); @Override void write(byte[] b, int off, int len); void writeCommand(Attributes cmd); void writeFileMetaInformation(Attributes fmi); void writeDataset(Attributes fmi, Attributes dataset); void switchTransferSyntax(String tsuid); void writeHeader(int tag, VR vr, int len); void writeAttribute(int tag, VR vr, Object value,
SpecificCharacterSet cs); void writeAttribute(int tag, VR vr, byte[] val); void writeAttribute(int tag, VR vr, Value val); void writeGroupLength(int tag, int len); void finish(); void close(); } | @Test public void testWriteCommand() throws IOException { DicomOutputStream out = new DicomOutputStream( new FileOutputStream(file), UID.ImplicitVRLittleEndian); try { out.writeCommand(cechorq()); } finally { out.close(); } assertEquals(4, readAttributes().size()); } |
AttributeSelector implements Serializable { public boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag) { int level; if (tag != this.tag || !Objects.equals(privateCreator, this.privateCreator) || (itemPointers.size() != (level = level()))) { return false; } for (int i = 0; i < level; i++) { ItemPointer itemPointer = itemPointers.get(i); ItemPointer other = itemPointer(i); if (!(itemPointer.itemIndex < 0 || other.itemIndex < 0 ? itemPointer.equalsIgnoreItemIndex(other) : itemPointer.equals(other))) { return false; } } return true; } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); } | @Test public void testMatches() { ItemPointer ip = new ItemPointer(Tag.RequestAttributesSequence); AttributeSelector selector = new AttributeSelector(Tag.StudyInstanceUID, null, ip); assertTrue(selector.matches(Collections.singletonList(ip), null, Tag.StudyInstanceUID)); } |
DicomOutputStream extends FilterOutputStream { public void writeDataset(Attributes fmi, Attributes dataset) throws IOException { if (fmi != null) { writeFileMetaInformation(fmi); switchTransferSyntax(fmi.getString(Tag.TransferSyntaxUID, null)); } if (dataset.bigEndian() != bigEndian || encOpts.groupLength || !encOpts.undefSequenceLength || !encOpts.undefItemLength) dataset = new Attributes(dataset, bigEndian); if (encOpts.groupLength) dataset.calcLength(encOpts, explicitVR); dataset.writeTo(this); } DicomOutputStream(OutputStream out, String tsuid); DicomOutputStream(File file); final void setPreamble(byte[] preamble); final boolean isExplicitVR(); final boolean isBigEndian(); final DicomEncodingOptions getEncodingOptions(); final void setEncodingOptions(DicomEncodingOptions encOpts); @Override void write(byte[] b, int off, int len); void writeCommand(Attributes cmd); void writeFileMetaInformation(Attributes fmi); void writeDataset(Attributes fmi, Attributes dataset); void switchTransferSyntax(String tsuid); void writeHeader(int tag, VR vr, int len); void writeAttribute(int tag, VR vr, Object value,
SpecificCharacterSet cs); void writeAttribute(int tag, VR vr, byte[] val); void writeAttribute(int tag, VR vr, Value val); void writeGroupLength(int tag, int len); void finish(); void close(); } | @Test public void testWriteDataset() throws IOException { DicomOutputStream out = new DicomOutputStream(file); }
@Test public void testWriteDeflatedEvenLength() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try (DicomOutputStream dos = new DicomOutputStream( out, UID.DeflatedExplicitVRLittleEndian)) { Attributes attrs = new Attributes(); attrs.setString(Tag.SOPClassUID, VR.UI, UID.CTImageStorage); dos.writeDataset(null, attrs); } assertEquals("odd number of bytes", 0, out.size() & 1); } |
DicomOutputStream extends FilterOutputStream { public final void setEncodingOptions(DicomEncodingOptions encOpts) { if (encOpts == null) throw new NullPointerException(); this.encOpts = encOpts; } DicomOutputStream(OutputStream out, String tsuid); DicomOutputStream(File file); final void setPreamble(byte[] preamble); final boolean isExplicitVR(); final boolean isBigEndian(); final DicomEncodingOptions getEncodingOptions(); final void setEncodingOptions(DicomEncodingOptions encOpts); @Override void write(byte[] b, int off, int len); void writeCommand(Attributes cmd); void writeFileMetaInformation(Attributes fmi); void writeDataset(Attributes fmi, Attributes dataset); void switchTransferSyntax(String tsuid); void writeHeader(int tag, VR vr, int len); void writeAttribute(int tag, VR vr, Object value,
SpecificCharacterSet cs); void writeAttribute(int tag, VR vr, byte[] val); void writeAttribute(int tag, VR vr, Value val); void writeGroupLength(int tag, int len); void finish(); void close(); } | @Test public void testWriteDatasetWithGroupLength() throws IOException { DicomOutputStream out = new DicomOutputStream(file); out.setEncodingOptions( new DicomEncodingOptions(true, true, false, true, false)); testWriteDataset(out, UID.ExplicitVRLittleEndian); }
@Test public void testWriteDatasetWithoutUndefLength() throws IOException { DicomOutputStream out = new DicomOutputStream(file); out.setEncodingOptions( new DicomEncodingOptions(false, false, false, false, false)); testWriteDataset(out, UID.ExplicitVRLittleEndian); }
@Test public void testWriteDatasetWithUndefEmptyLength() throws IOException { DicomOutputStream out = new DicomOutputStream(file); out.setEncodingOptions( new DicomEncodingOptions(false, true, true, true, true)); testWriteDataset(out, UID.ExplicitVRLittleEndian); } |
DicomOutputStream extends FilterOutputStream { public void close() throws IOException { try { finish(); } catch (IOException ignored) { } super.close(); } DicomOutputStream(OutputStream out, String tsuid); DicomOutputStream(File file); final void setPreamble(byte[] preamble); final boolean isExplicitVR(); final boolean isBigEndian(); final DicomEncodingOptions getEncodingOptions(); final void setEncodingOptions(DicomEncodingOptions encOpts); @Override void write(byte[] b, int off, int len); void writeCommand(Attributes cmd); void writeFileMetaInformation(Attributes fmi); void writeDataset(Attributes fmi, Attributes dataset); void switchTransferSyntax(String tsuid); void writeHeader(int tag, VR vr, int len); void writeAttribute(int tag, VR vr, Object value,
SpecificCharacterSet cs); void writeAttribute(int tag, VR vr, byte[] val); void writeAttribute(int tag, VR vr, Value val); void writeGroupLength(int tag, int len); void finish(); void close(); } | @Test public void testSerializeDataset() throws Exception { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(file)); try { out.writeObject(dataset()); out.writeUTF("END"); } finally { out.close(); } deserializeAttributes(); } |
DicomOutputStream extends FilterOutputStream { public void writeFileMetaInformation(Attributes fmi) throws IOException { if (!explicitVR || bigEndian || countingOutputStream != null) throw new IllegalStateException("explicitVR=" + explicitVR + ", bigEndian=" + bigEndian + ", deflated=" + (countingOutputStream != null)); write(preamble); write(DICM); fmi.writeGroupTo(this, Tag.FileMetaInformationGroupLength); } DicomOutputStream(OutputStream out, String tsuid); DicomOutputStream(File file); final void setPreamble(byte[] preamble); final boolean isExplicitVR(); final boolean isBigEndian(); final DicomEncodingOptions getEncodingOptions(); final void setEncodingOptions(DicomEncodingOptions encOpts); @Override void write(byte[] b, int off, int len); void writeCommand(Attributes cmd); void writeFileMetaInformation(Attributes fmi); void writeDataset(Attributes fmi, Attributes dataset); void switchTransferSyntax(String tsuid); void writeHeader(int tag, VR vr, int len); void writeAttribute(int tag, VR vr, Object value,
SpecificCharacterSet cs); void writeAttribute(int tag, VR vr, byte[] val); void writeAttribute(int tag, VR vr, Value val); void writeGroupLength(int tag, int len); void finish(); void close(); } | @Test(expected = IllegalStateException.class) public void testWriteFMIDeflated() throws IOException { try (DicomOutputStream out = new DicomOutputStream( new ByteArrayOutputStream(), UID.DeflatedExplicitVRLittleEndian)) { out.writeFileMetaInformation( Attributes.createFileMetaInformation(UIDUtils.createUID(), UID.CTImageStorage, UID.DeflatedExplicitVRLittleEndian)); } } |
RecordFactory { public RecordType getRecordType(String cuid) { if (cuid == null) throw new NullPointerException(); lazyLoadDefaultConfiguration(); RecordType recordType = recordTypes.get(cuid); return recordType != null ? recordType : RecordType.PRIVATE; } void loadDefaultConfiguration(); void loadConfiguration(String uri); RecordType getRecordType(String cuid); RecordType setRecordType(String cuid, RecordType type); void setRecordKeys(RecordType type, int[] keys); int[] getRecordKeys(RecordType type); String getPrivateRecordUID(String cuid); String setPrivateRecordUID(String cuid, String uid); int[] setPrivateRecordKeys(String uid, int[] keys); Attributes createRecord(Attributes dataset, Attributes fmi,
String[] fileIDs); Attributes createRecord(RecordType type, String privRecUID,
Attributes dataset, Attributes fmi, String[] fileIDs); } | @Test public void testGetRecordType() { RecordFactory f = new RecordFactory(); assertEquals(RecordType.IMAGE, f.getRecordType(UID.SecondaryCaptureImageStorage)); } |
FindSCU { static void mergeKeys(Attributes attrs, Attributes keys) { try { attrs.accept(new MergeNested(keys), false); } catch (Exception e) { throw new RuntimeException(e); } attrs.addAll(keys); } FindSCU(); final void setPriority(int priority); final void setInformationModel(InformationModel model, String[] tss,
EnumSet<QueryOption> queryOptions); void addLevel(String s); final void setCancelAfter(int cancelAfter); final void setOutputDirectory(File outDir); final void setOutputFileFormat(String outFileFormat); final void setXSLT(File xsltFile); final void setXML(boolean xml); final void setXMLIndent(boolean indent); final void setXMLIncludeKeyword(boolean includeKeyword); final void setXMLIncludeNamespaceDeclaration(
boolean includeNamespaceDeclaration); final void setConcatenateOutputFiles(boolean catOut); final void setInputFilter(int[] inFilter); ApplicationEntity getApplicationEntity(); Connection getRemoteConnection(); AAssociateRQ getAAssociateRQ(); Association getAssociation(); Device getDevice(); Attributes getKeys(); @SuppressWarnings("unchecked") static void main(String[] args); void open(); void close(); void query(File f); void query(); void query( DimseRSPHandler rspHandler); } | @Test public void mergeNestedKeys() throws Exception { Attributes attrs = withSSA(returnKeys()); FindSCU.mergeKeys(attrs, withSSA(matchingKeys())); assertEquals(mergedKeys(), attrs.getNestedDataset(Tag.ScheduledStepAttributesSequence)); } |
Device implements Serializable { public void reconfigure(Device from) throws IOException, GeneralSecurityException { setDeviceAttributes(from); reconfigureConnections(from); reconfigureApplicationEntities(from); reconfigureWebApplications(from); reconfigureKeycloakClients(from); reconfigureDeviceExtensions(from); } Device(); Device(String name); final String getDeviceName(); final void setDeviceName(String name); final String getDescription(); final void setDescription(String description); String getDeviceUID(); void setDeviceUID(String deviceUID); final String getManufacturer(); final void setManufacturer(String manufacturer); final String getManufacturerModelName(); final void setManufacturerModelName(String manufacturerModelName); final String[] getSoftwareVersions(); final void setSoftwareVersions(String... softwareVersions); final String getStationName(); final void setStationName(String stationName); final String getDeviceSerialNumber(); final void setDeviceSerialNumber(String deviceSerialNumber); final String[] getPrimaryDeviceTypes(); void setPrimaryDeviceTypes(String... primaryDeviceTypes); final String[] getInstitutionNames(); void setInstitutionNames(String... names); final Code[] getInstitutionCodes(); void setInstitutionCodes(Code... codes); final String[] getInstitutionAddresses(); void setInstitutionAddresses(String... addresses); final String[] getInstitutionalDepartmentNames(); void setInstitutionalDepartmentNames(String... names); final Issuer getIssuerOfPatientID(); final void setIssuerOfPatientID(Issuer issuerOfPatientID); final Issuer getIssuerOfAccessionNumber(); final void setIssuerOfAccessionNumber(Issuer issuerOfAccessionNumber); final Issuer getOrderPlacerIdentifier(); final void setOrderPlacerIdentifier(Issuer orderPlacerIdentifier); final Issuer getOrderFillerIdentifier(); final void setOrderFillerIdentifier(Issuer orderFillerIdentifier); final Issuer getIssuerOfAdmissionID(); final void setIssuerOfAdmissionID(Issuer issuerOfAdmissionID); final Issuer getIssuerOfServiceEpisodeID(); final void setIssuerOfServiceEpisodeID(Issuer issuerOfServiceEpisodeID); final Issuer getIssuerOfContainerIdentifier(); final void setIssuerOfContainerIdentifier(Issuer issuerOfContainerIdentifier); final Issuer getIssuerOfSpecimenIdentifier(); final void setIssuerOfSpecimenIdentifier(Issuer issuerOfSpecimenIdentifier); X509Certificate[] getAuthorizedNodeCertificates(String ref); void setAuthorizedNodeCertificates(String ref, X509Certificate... certs); X509Certificate[] removeAuthorizedNodeCertificates(String ref); void removeAllAuthorizedNodeCertificates(); X509Certificate[] getAllAuthorizedNodeCertificates(); String[] getAuthorizedNodeCertificateRefs(); final String getTrustStoreURL(); final void setTrustStoreURL(String trustStoreURL); final String getTrustStoreType(); final void setTrustStoreType(String trustStoreType); final String getTrustStorePin(); final void setTrustStorePin(String trustStorePin); final String getTrustStorePinProperty(); final void setTrustStorePinProperty(String trustStorePinProperty); X509Certificate[] getThisNodeCertificates(String ref); void setThisNodeCertificates(String ref, X509Certificate... certs); X509Certificate[] removeThisNodeCertificates(String ref); final String getKeyStoreURL(); final void setKeyStoreURL(String keyStoreURL); final String getKeyStoreType(); final void setKeyStoreType(String keyStoreType); final String getKeyStorePin(); final void setKeyStorePin(String keyStorePin); final String getKeyStorePinProperty(); final void setKeyStorePinProperty(String keyStorePinProperty); final String getKeyStoreKeyPin(); final void setKeyStoreKeyPin(String keyStorePin); final String getKeyStoreKeyPinProperty(); final void setKeyStoreKeyPinProperty(String keyStoreKeyPinProperty); void removeAllThisNodeCertificates(); X509Certificate[] getAllThisNodeCertificates(); String[] getThisNodeCertificateRefs(); final String[] getRelatedDeviceRefs(); void setRelatedDeviceRefs(String... refs); final byte[][] getVendorData(); void setVendorData(byte[]... vendorData); final boolean isInstalled(); final void setInstalled(boolean installed); boolean isRoleSelectionNegotiationLenient(); void setRoleSelectionNegotiationLenient(boolean roleSelectionNegotiationLenient); void setTimeZoneOfDevice(TimeZone timeZoneOfDevice); TimeZone getTimeZoneOfDevice(); final void setDimseRQHandler(DimseRQHandler dimseRQHandler); final DimseRQHandler getDimseRQHandler(); final AssociationHandler getAssociationHandler(); void setAssociationHandler(AssociationHandler associationHandler); ConnectionMonitor getConnectionMonitor(); void setConnectionMonitor(ConnectionMonitor connectionMonitor); AssociationMonitor getAssociationMonitor(); void setAssociationMonitor(AssociationMonitor associationMonitor); void bindConnections(); void rebindConnections(); void unbindConnections(); final Executor getExecutor(); final void setExecutor(Executor executor); final ScheduledExecutorService getScheduledExecutor(); final void setScheduledExecutor(ScheduledExecutorService executor); void addConnection(Connection conn); boolean removeConnection(Connection conn); List<Connection> listConnections(); Connection connectionWithEqualsRDN(Connection other); void addApplicationEntity(ApplicationEntity ae); ApplicationEntity removeApplicationEntity(ApplicationEntity ae); ApplicationEntity removeApplicationEntity(String aet); Collection<String> getWebApplicationNames(); Collection<WebApplication> getWebApplications(); Collection<WebApplication> getWebApplicationsWithServiceClass(WebApplication.ServiceClass serviceClass); WebApplication getWebApplication(String name); void addWebApplication(WebApplication webapp); WebApplication removeWebApplication(WebApplication webapp); WebApplication removeWebApplication(String name); Collection<String> getKeycloakClientIDs(); Collection<KeycloakClient> getKeycloakClients(); KeycloakClient getKeycloakClient(String clientID); void addKeycloakClient(KeycloakClient client); KeycloakClient removeKeycloakClient(KeycloakClient client); KeycloakClient removeKeycloakClient(String name); void addDeviceExtension(DeviceExtension ext); boolean removeDeviceExtension(DeviceExtension ext); final int getLimitOpenAssociations(); final void setLimitOpenAssociations(int limit); int getLimitAssociationsInitiatedBy(String callingAET); void setLimitAssociationsInitiatedBy(String callingAET, int limit); String[] getLimitAssociationsInitiatedBy(); void setLimitAssociationsInitiatedBy(String[] values); Association [] listOpenAssociations(); int getNumberOfOpenAssociations(); int getNumberOfAssociationsInitiatedBy(String callingAET); void waitForNoOpenConnections(); boolean isLimitOfAssociationsExceeded(AAssociateRQ rq); ApplicationEntity getApplicationEntity(String aet); ApplicationEntity getApplicationEntity(String aet, boolean matchOtherAETs); Collection<String> getApplicationAETitles(); Collection<ApplicationEntity> getApplicationEntities(); final void setKeyManager(KeyManager km); final KeyManager getKeyManager(); final void setTrustManager(TrustManager tm); final TrustManager getTrustManager(); SSLContext sslContext(); KeyManager[] keyManagers(); TrustManager[] trustManagers(); void execute(Runnable command); ScheduledFuture<?> schedule(Runnable command, long delay,
TimeUnit unit); ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
long initialDelay, long period, TimeUnit unit); ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
long initialDelay, long delay, TimeUnit unit); @Override String toString(); StringBuilder promptTo(StringBuilder sb, String indent); void reconfigure(Device from); void reconfigureConnections(List<Connection> conns,
List<Connection> src); Collection<DeviceExtension> listDeviceExtensions(); @SuppressWarnings("unchecked") T getDeviceExtension(Class<T> clazz); T getDeviceExtensionNotNull(Class<T> clazz); } | @Test public void testReconfigure() throws Exception { Device d1 = createDevice("test", "AET1"); Device d2 = createDevice("test", "AET2"); d1.reconfigure(d2); ApplicationEntity ae = d1.getApplicationEntity("AET2"); assertNotNull(ae); List<Connection> conns = ae.getConnections(); assertEquals(1, conns.size()); } |
SpecificCharacterSet { public byte[] encode(String val, String delimiters) { return codecs[0].encode(val); } protected SpecificCharacterSet(Codec[] codecs, String... codes); static SpecificCharacterSet getDefaultCharacterSet(); static void setDefaultCharacterSet(String code); static void setCharsetNameMapping(String code, String charsetName); static void resetCharsetNameMappings(); static String checkSpecificCharacterSet(String code); static String checkCharsetName(String charsetName); static SpecificCharacterSet valueOf(String... codes); static boolean trimISO2022(String[] codes); String[] toCodes(); byte[] encode(String val, String delimiters); String decode(byte[] val); boolean isUTF8(); boolean isASCII(); boolean containsASCII(); boolean contains(SpecificCharacterSet other); String toText(String s); @Override boolean equals(Object other); @Override int hashCode(); static final SpecificCharacterSet ASCII; } | @Test public void testEncodeGermanPersonName() { assertArrayEquals(GERMAN_PERSON_NAME_BYTE, iso8859_1().encode(GERMAN_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeFrenchPersonName() { assertArrayEquals(FRENCH_PERSON_NAME_BYTE, iso8859_1().encode(FRENCH_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeRussianPersonName() { assertArrayEquals(RUSSIAN_PERSON_NAME_BYTE, iso8859_5().encode(RUSSIAN_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeArabicPersonName() { assertArrayEquals(ARABIC_PERSON_NAME_BYTE, iso8859_6().encode(ARABIC_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeGreekPersonName() { assertArrayEquals(GREEK_PERSON_NAME_BYTE, iso8859_7().encode(GREEK_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeHebrewPersonName() { assertArrayEquals(HEBREW_PERSON_NAME_BYTE, iso8859_8().encode(HEBREW_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeJapanesePersonNameASCII() { assertArrayEquals(JAPANESE_PERSON_NAME_ASCII_BYTES, jisX0208().encode(JAPANESE_PERSON_NAME_ASCII, PN_DELIMS)); }
@Test public void testEncodeJapanesePersonNameJISX0201() { assertArrayEquals(JAPANESE_PERSON_NAME_JISX0201_BYTES, jisX0201().encode(JAPANESE_PERSON_NAME_JISX0201, PN_DELIMS)); }
@Test public void testEncodeKoreanPersonName() { assertArrayEquals(KOREAN_PERSON_NAME_BYTES, ksx1001().encode(KOREAN_PERSON_NAME, PN_DELIMS)); }
@Test public void testEncodeKoreanLongText() { assertArrayEquals(KOREAN_LONG_TEXT_BYTES, ksx1001().encode(KOREAN_LONG_TEXT, LT_DELIMS)); }
@Test public void testEncodeChinesePersonNameGB2312() { assertArrayEquals(CHINESE_PERSON_NAME_GB2312_BYTES, gb2312().encode(CHINESE_PERSON_NAME_GB2312, PN_DELIMS)); }
@Test public void testEncodeChineseLongTextGB2312() { assertArrayEquals(CHINESE_LONG_TEXT_GB2312_BYTES, gb2312().encode(CHINESE_LONG_TEXT_GB2312, LT_DELIMS)); }
@Test public void testEncodeChinesePersonNameUTF8() { assertArrayEquals(CHINESE_PERSON_NAME_UTF8_BYTES, utf8().encode(CHINESE_PERSON_NAME_UTF8, PN_DELIMS)); }
@Test public void testEncodeChinesePersonNameGB18030() { assertArrayEquals(CHINESE_PERSON_NAME_GB18030_BYTES, gb18030().encode(CHINESE_PERSON_NAME_GB18030, PN_DELIMS)); }
@Test public void testEncodeChinesePersonNameGBK() { assertArrayEquals(CHINESE_PERSON_NAME_GB18030_BYTES, gbk().encode(CHINESE_PERSON_NAME_GB18030, PN_DELIMS)); } |
SpecificCharacterSet { public String decode(byte[] val) { return codecs[0].decode(val, 0, val.length); } protected SpecificCharacterSet(Codec[] codecs, String... codes); static SpecificCharacterSet getDefaultCharacterSet(); static void setDefaultCharacterSet(String code); static void setCharsetNameMapping(String code, String charsetName); static void resetCharsetNameMappings(); static String checkSpecificCharacterSet(String code); static String checkCharsetName(String charsetName); static SpecificCharacterSet valueOf(String... codes); static boolean trimISO2022(String[] codes); String[] toCodes(); byte[] encode(String val, String delimiters); String decode(byte[] val); boolean isUTF8(); boolean isASCII(); boolean containsASCII(); boolean contains(SpecificCharacterSet other); String toText(String s); @Override boolean equals(Object other); @Override int hashCode(); static final SpecificCharacterSet ASCII; } | @Test public void testDecodeGermanPersonName() { assertEquals(GERMAN_PERSON_NAME, iso8859_1().decode(GERMAN_PERSON_NAME_BYTE)); }
@Test public void testDecodeFrenchPersonName() { assertEquals(FRENCH_PERSON_NAME, iso8859_1().decode(FRENCH_PERSON_NAME_BYTE)); }
@Test public void testDecodeRussianPersonName() { assertEquals(RUSSIAN_PERSON_NAME, iso8859_5().decode(RUSSIAN_PERSON_NAME_BYTE)); }
@Test public void testDecodeArabicPersonName() { assertEquals(ARABIC_PERSON_NAME, iso8859_6().decode(ARABIC_PERSON_NAME_BYTE)); }
@Test public void testDecodeGreekPersonName() { assertEquals(GREEK_PERSON_NAME, iso8859_7().decode(GREEK_PERSON_NAME_BYTE)); }
@Test public void testDecodeHebrewPersonName() { assertEquals(HEBREW_PERSON_NAME, iso8859_8().decode(HEBREW_PERSON_NAME_BYTE)); }
@Test public void testDecodeJapanesePersonNameASCII() { assertEquals(JAPANESE_PERSON_NAME_ASCII, jisX0208().decode(JAPANESE_PERSON_NAME_ASCII_BYTES)); }
@Test public void testDecodeJapanesePersonNameJISX0201() { assertEquals(JAPANESE_PERSON_NAME_JISX0201, jisX0201().decode(JAPANESE_PERSON_NAME_JISX0201_BYTES)); }
@Test public void testDecodeKoreanPersonName() { assertEquals(KOREAN_PERSON_NAME, ksx1001().decode(KOREAN_PERSON_NAME_BYTES)); }
@Test public void testDecodeKoreanLongText() { assertEquals(KOREAN_LONG_TEXT, ksx1001().decode(KOREAN_LONG_TEXT_BYTES)); }
@Test public void testDecodeChinesePersonNameGB2312() { assertEquals(CHINESE_PERSON_NAME_GB2312, gb2312().decode(CHINESE_PERSON_NAME_GB2312_BYTES)); }
@Test public void testDecodeChineseLongTextGB2312() { assertEquals(CHINESE_LONG_TEXT_GB2312, gb2312().decode(CHINESE_LONG_TEXT_GB2312_BYTES)); }
@Test public void testDecodeChinesePersonNameUTF8() { assertEquals(CHINESE_PERSON_NAME_UTF8, utf8().decode(CHINESE_PERSON_NAME_UTF8_BYTES)); }
@Test public void testDecodeChinesePersonNameGB18030() { assertEquals(CHINESE_PERSON_NAME_GB18030, gb18030().decode(CHINESE_PERSON_NAME_GB18030_BYTES)); }
@Test public void testDecodeChinesePersonNameGBK() { assertEquals(CHINESE_PERSON_NAME_GB18030, gbk().decode(CHINESE_PERSON_NAME_GB18030_BYTES)); }
@Test public void testDecodeJISX0201EdgeCases() { byte[][] edgeCases = new byte[][] { {}, { 0x33, 0x43 }, { 0x33, 0x1b }, { 0x1b, 0x24, 0x28 }, { 0x1b, 0x24, 0x28, 0x55 }, { 0x1b, 0x24, 0x28, 0x44 }, { 0x1b, 0x24, 0x28, 0x44, 0x55 }, { 0x1b, 0x24, 0x29 }, { 0x1b, 0x24, 0x29, 0x41 }, { 0x1b, 0x24, 0x29, 0x41, 0x55 }, { 0x1b, 0x24, 0x29, 0x43 }, { 0x1b, 0x24, 0x29, 0x43, 0x55 }, { 0x1b, 0x24, 0x29, 0x55 }, { 0x1b, 0x24, 0x42 }, { 0x1b, 0x24, 0x42, 0x31 }, { 0x1b, 0x33 }, { 0x1b, 0x33, 0x43 } }; final String[] expectedStrings = new String[] { "", "3C", "3\u001b", "\u001b$(", "\u001b$(U", "", "\ufffd", "\u001b$)", "", "U", "", "U", "\u001b$)U", "", "\ufffd", "\u001b3", "\u001b3C" }; assertEquals( "There must be the same number of expected results and edge cases.", edgeCases.length, expectedStrings.length ); for ( int i = 0; i < edgeCases.length; ++i ) { assertEquals( "Unexpected value for the sequence with the index " + i, expectedStrings[ i ], jisX0201().decode( edgeCases[ i ] ) ); } } |
JSONWriter implements DicomInputHandler { public void write(Attributes attrs) { final SpecificCharacterSet cs = attrs.getSpecificCharacterSet(); gen.writeStartObject(); try { attrs.accept(new Attributes.Visitor(){ @Override public boolean visit(Attributes attrs, int tag, VR vr, Object value) throws Exception { writeAttribute(tag, vr, value, cs, attrs); return true; }}, false); } catch (Exception e) { throw new RuntimeException(e); } gen.writeEnd(); } JSONWriter(JsonGenerator gen); String getReplaceBulkDataURI(); void setReplaceBulkDataURI(String replaceBulkDataURI); void write(Attributes attrs); @Override void readValue(DicomInputStream dis, Attributes attrs); @Override void readValue(DicomInputStream dis, Sequence seq); @Override void readValue(DicomInputStream dis, Fragments frags); @Override void startDataset(DicomInputStream dis); @Override void endDataset(DicomInputStream dis); } | @Test public void test() { Attributes dataset = new Attributes(); dataset.setString(Tag.SpecificCharacterSet, VR.CS, null, "ISO 2022 IR 87"); dataset.setString(Tag.ImageType, VR.CS, "DERIVED", "PRIMARY"); Attributes item = new Attributes(2); dataset.newSequence(Tag.SourceImageSequence, 1).add(item); item.setString(Tag.ReferencedSOPClassUID, VR.UI, UID.CTImageStorage); item.setString(Tag.ReferencedSOPInstanceUID, VR.UI, "1.2.3.4"); dataset.setString(Tag.PatientName, VR.PN, "af^ag=if^ig=pf^pg"); dataset.setBytes("PRIVATE", 0x00090002, VR.OB, BYTE01); dataset.setDouble(Tag.FrameTime, VR.DS, 33.0); dataset.setInt(Tag.SamplesPerPixel, VR.US, 1); dataset.setInt(Tag.NumberOfFrames, VR.IS, 1); dataset.setInt(Tag.FrameIncrementPointer, VR.AT, Tag.FrameTime); dataset.setValue(Tag.OverlayData, VR.OW, new BulkData(null, "file:/OverlayData", false)); Fragments frags = dataset.newFragments(Tag.PixelData, VR.OB, 2); frags.add(null); frags.add(new BulkData(null, "file:/PixelData", false)); StringWriter writer = new StringWriter(); JsonGenerator gen = Json.createGenerator(writer); new JSONWriter(gen).write(dataset); gen.flush(); assertEquals(RESULT, writer.toString()); }
@Test public void testInfinityAndNaN() { Attributes dataset = new Attributes(); dataset.setDouble(Tag.SelectorFDValue, VR.FD, Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY); dataset.setFloat(Tag.SelectorFLValue, VR.FL, Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY); StringWriter writer = new StringWriter(); JsonGenerator gen = Json.createGenerator(writer); new JSONWriter(gen).write(dataset); gen.flush(); assertEquals(INFINITY_AND_NAN, writer.toString()); } |
LdapHL7Configuration extends LdapDicomConfigurationExtension implements HL7Configuration { @Override public HL7Application findHL7Application(String name) throws ConfigurationException { Device device = config.findDevice( "(&(objectclass=hl7Application)(hl7ApplicationName=" + name + "))", name); HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); return hl7Ext.getHL7Application(name); } void addHL7ConfigurationExtension(LdapHL7ConfigurationExtension ext); boolean removeHL7ConfigurationExtension(
LdapHL7ConfigurationExtension ext); @Override boolean registerHL7Application(String name); @Override void unregisterHL7Application(String name); @Override String[] listRegisteredHL7ApplicationNames(); @Override HL7Application findHL7Application(String name); @Override synchronized HL7ApplicationInfo[] listHL7AppInfos(HL7ApplicationInfo keys); } | @Test public void testPersist() throws Exception { try { config.removeDevice("Test-Device-1", null); } catch (ConfigurationNotFoundException e) {} Device device = createDevice("Test-Device-1", "TEST1^DCM4CHE"); config.persist(device, null); HL7Application app = hl7Ext.findHL7Application("TEST1^DCM4CHE"); assertEquals(2575, app.getConnections().get(0).getPort()); assertEquals("TEST2^DCM4CHE", app.getAcceptedSendingApplications()[0]); assertEquals(7, app.getAcceptedMessageTypes().length); config.removeDevice("Test-Device-1", null); } |
IDWithIssuer { public static Set<IDWithIssuer> pidsOf(Attributes attrs) { IDWithIssuer pid = IDWithIssuer.pidOf(attrs); Sequence opidseq = attrs.getSequence(Tag.OtherPatientIDsSequence); if (opidseq == null) if (pid == null) return Collections.emptySet(); else return Collections.singleton(pid); Set<IDWithIssuer> pids = new HashSet<IDWithIssuer>((1 + opidseq.size()) << 1); if (pid != null) pids.add(pid); for (Attributes item : opidseq) addTo(IDWithIssuer.pidOf(item), pids); return pids; } IDWithIssuer(String id, Issuer issuer); IDWithIssuer(String id, String issuer); IDWithIssuer(String cx); IDWithIssuer withoutIssuer(); final String getID(); String getTypeOfPatientID(); void setTypeOfPatientID(String typeOfPatientID); final String getIdentifierTypeCode(); final void setIdentifierTypeCode(String identifierTypeCode); final Issuer getIssuer(); final void setIssuer(Issuer issuer); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); boolean matches(IDWithIssuer other); Attributes exportPatientIDWithIssuer(Attributes attrs); static IDWithIssuer valueOf(Attributes attrs, int idTag,
int issuerSeqTag); static IDWithIssuer pidOf(Attributes attrs); static Set<IDWithIssuer> pidsOf(Attributes attrs); static final IDWithIssuer[] EMPTY; } | @Test public void pidsOfTest_faking_duplicate_by_using_same_PID_but_different_issuer() { Attributes rootWithMainId = createIdWithNS(NS); rootWithMainId.newSequence(OtherPatientIDsSequence, 0); Sequence other = rootWithMainId.getSequence(OtherPatientIDsSequence); Attributes otherPatientId = otherPatientIds("other_ns"); other.add(otherPatientId); Set<IDWithIssuer> all = IDWithIssuer.pidsOf(rootWithMainId); assertEquals("Same pid but for different issuer should not be removed!", all.size(), 2); }
@Test public void no_main_id_returns_all() { Attributes rootWithMainId = createIdWithNS(NS); rootWithMainId.newSequence(OtherPatientIDsSequence, 0); Sequence other = rootWithMainId.getSequence(OtherPatientIDsSequence); Attributes otherPatientId = otherPatientIds("other_ns"); other.add(otherPatientId); Set<IDWithIssuer> all = IDWithIssuer.pidsOf(rootWithMainId); assertEquals("Same pid but for different issuer should not be removed!", all.size(), 2); } |
IOD extends ArrayList<IOD.DataElement> { public static IOD load(String uri) throws IOException { if (uri.startsWith("resource:")) { try { uri = ResourceLocator.getResource(uri.substring(9), IOD.class); } catch (NullPointerException npe) { throw new FileNotFoundException(uri); } } else if (uri.indexOf(':') < 2) { uri = new File(uri).toURI().toString(); } IOD iod = new IOD(); iod.parse(uri); iod.trimToSize(); return iod; } void setType(DataElementType type); DataElementType getType(); void setCondition(Condition condition); Condition getCondition(); int getLineNumber(); void setLineNumber(int lineNumber); void parse(String uri); static IOD load(String uri); static IOD valueOf(Code code); } | @Test public void testValidateDICOMDIR() throws Exception { IOD iod = IOD.load("resource:dicomdir-iod.xml"); Attributes attrs = readDataset("DICOMDIR"); ValidationResult result = attrs.validate(iod); assertTrue(result.isValid()); }
@Test public void testValidateCode() throws Exception { IOD iod = IOD.load("resource:code-iod.xml"); Attributes attrs = new Attributes(2); attrs.newSequence(Tag.ConceptNameCodeSequence, 1).add( new Code("CV-9991", "99DCM4CHE", null, "CM-9991").toItem()); Attributes contentNode = new Attributes(2); contentNode.newSequence(Tag.ConceptNameCodeSequence, 1).add( new Code("CV-9992", "99DCM4CHE", null, "CM-9992").toItem()); contentNode.newSequence(Tag.ConceptCodeSequence, 1).add( new Code("CV-9993", "99DCM4CHE", null, "CM-9993").toItem()); attrs.newSequence(Tag.ContentSequence, 1).add(contentNode); ValidationResult result = attrs.validate(iod); assertTrue(result.isValid()); } |
PersonName { public String get(Component c) { return get(Group.Alphabetic, c); } PersonName(); PersonName(String s); PersonName(String s, boolean lenient); String toString(); String toString(Group g, boolean trim); String get(Component c); String get(Group g, Component c); void set(Component c, String s); void set(Group g, Component c, String s); boolean isEmpty(); boolean contains(Group g); boolean contains(Group g, Component c); boolean contains(Component c); @Override int hashCode(); @Override boolean equals(Object obj); } | @Test public void testValueOf() { PersonName pn = new PersonName( "Adams^John Robert Quincy^^Rev.^B.A. M.Div."); assertEquals("Adams", pn.get(PersonName.Component.FamilyName)); assertEquals("John Robert Quincy", pn.get(PersonName.Component.GivenName)); assertEquals("Rev.", pn.get(PersonName.Component.NamePrefix)); assertEquals("B.A. M.Div.", pn.get(PersonName.Component.NameSuffix)); }
@Test public void testValueOf2() { PersonName pn = new PersonName("Hong^Gildong=洪^吉洞=홍^길동"); assertEquals("Hong", pn.get(PersonName.Group.Alphabetic, PersonName.Component.FamilyName)); assertEquals("Gildong", pn.get(PersonName.Group.Alphabetic, PersonName.Component.GivenName)); assertEquals("洪", pn.get(PersonName.Group.Ideographic, PersonName.Component.FamilyName)); assertEquals("吉洞", pn.get(PersonName.Group.Ideographic, PersonName.Component.GivenName)); assertEquals("홍", pn.get(PersonName.Group.Phonetic, PersonName.Component.FamilyName)); assertEquals("길동", pn.get(PersonName.Group.Phonetic, PersonName.Component.GivenName)); } |
PersonName { public String toString() { int totLen = 0; Group lastGroup = Group.Alphabetic; for (Group g : Group.values()) { Component lastCompOfGroup = Component.FamilyName; for (Component c : Component.values()) { String s = get(g, c); if (s != null) { totLen += s.length(); lastGroup = g; lastCompOfGroup = c; } } totLen += lastCompOfGroup.ordinal(); } totLen += lastGroup.ordinal(); char[] ch = new char[totLen]; int wpos = 0; for (Group g : Group.values()) { Component lastCompOfGroup = Component.FamilyName; for (Component c : Component.values()) { String s = get(g, c); if (s != null) { int d = c.ordinal() - lastCompOfGroup.ordinal(); while (d-- > 0) ch[wpos++] = '^'; d = s.length(); s.getChars(0, d, ch, wpos); wpos += d; lastCompOfGroup = c; } } if (g == lastGroup) break; ch[wpos++] = '='; } return new String(ch); } PersonName(); PersonName(String s); PersonName(String s, boolean lenient); String toString(); String toString(Group g, boolean trim); String get(Component c); String get(Group g, Component c); void set(Component c, String s); void set(Group g, Component c, String s); boolean isEmpty(); boolean contains(Group g); boolean contains(Group g, Component c); boolean contains(Component c); @Override int hashCode(); @Override boolean equals(Object obj); } | @Test public void testToString() { PersonName pn = new PersonName(); pn.set(PersonName.Component.FamilyName, "Morrison-Jones"); pn.set(PersonName.Component.GivenName, "Susan"); pn.set(PersonName.Component.NameSuffix, "Ph.D., Chief Executive Officer"); assertEquals("Morrison-Jones^Susan^^^Ph.D., Chief Executive Officer", pn.toString()); } |
ValueSelector implements Serializable { @Override public String toString() { if (str == null) str = attributeSelector.toStringBuilder() .append("/Value[@number=\"") .append(valueIndex + 1) .append("\"]") .toString(); return str; } ValueSelector(int tag, String privateCreator, int index, ItemPointer... itemPointers); ValueSelector(AttributeSelector attributeSelector, int index); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); int valueIndex(); String selectStringValue(Attributes attrs, String defVal); @Override String toString(); static ValueSelector valueOf(String s); @Override int hashCode(); @Override boolean equals(Object obj); } | @Test public void testToString() { ItemPointer ip = new ItemPointer(Tag.RequestAttributesSequence, 0); ValueSelector vs = new ValueSelector(Tag.StudyInstanceUID, null, 0, ip); assertEquals(XPATH, vs.toString()); } |
LdapDicomConfiguration implements DicomConfiguration { @Override public synchronized boolean registerAETitle(String aet) throws ConfigurationException { ensureConfigurationExists(); try { registerAET(aet); return true; } catch (AETitleAlreadyExistsException e) { return false; } } LdapDicomConfiguration(); @SuppressWarnings("unchecked") LdapDicomConfiguration(Hashtable<?,?> env); final boolean isExtended(); final void setExtended(boolean extended); final void setConfigurationCN(String configurationCN); final String getConfigurationCN(); final void setConfigurationRoot(String configurationRoot); final String getConfigurationRoot(); void setPkiUser(String pkiUser); String getPkiUser(); void setUserCertificate(String userCertificate); String getUserCertificate(); void addDicomConfigurationExtension(LdapDicomConfigurationExtension ext); boolean removeDicomConfigurationExtension(
LdapDicomConfigurationExtension ext); @SuppressWarnings("unchecked") @Override T getDicomConfigurationExtension(Class<T> clazz); @Override synchronized void close(); @Override synchronized boolean configurationExists(); boolean exists(String dn); @Override synchronized boolean purgeConfiguration(); @Override synchronized boolean registerAETitle(String aet); @Override synchronized boolean registerWebAppName(String webAppName); @Override synchronized void unregisterAETitle(String aet); @Override synchronized void unregisterWebAppName(String webAppName); @Override synchronized ApplicationEntity findApplicationEntity(String aet); @Override synchronized WebApplication findWebApplication(String name); synchronized Device findDevice(String filter, String childName); Connection findConnection(String connDN, Map<String, Connection> cache); @Override synchronized Device findDevice(String name); @Override synchronized DeviceInfo[] listDeviceInfos(DeviceInfo keys); @Override synchronized String[] listDeviceNames(); @Override synchronized String[] listRegisteredAETitles(); @Override synchronized String[] listRegisteredWebAppNames(); synchronized String[] list(String dn, String filter, String attrID); @Override synchronized ConfigurationChanges persist(Device device, EnumSet<Option> options); @Override ConfigurationChanges merge(Device device, EnumSet<Option> options); @Override synchronized ConfigurationChanges removeDevice(String name, EnumSet<Option> options); synchronized void createSubcontext(String name, Attributes attrs); synchronized void destroySubcontext(String dn); synchronized void destroySubcontextWithChilds(String name); String getConfigurationDN(); void ensureConfigurationExists(); @Override synchronized void persistCertificates(String dn, X509Certificate... certs); @Override synchronized void removeCertificates(String dn); @Override synchronized X509Certificate[] findCertificates(String dn); @Override byte[][] loadDeviceVendorData(String deviceName); @Override ConfigurationChanges updateDeviceVendorData(String deviceName, byte[]... vendorData); Device loadDevice(String deviceDN); Attributes getAttributes(String name); Attributes getAttributes(String name, String[] attrIDs); NamingEnumeration<SearchResult> search(String dn, String filter); NamingEnumeration<SearchResult> search(String dn, String filter,
String... attrs); void modifyAttributes(String dn, List<ModificationItem> mods); void replaceAttributes(String dn, Attributes attrs); @Override String deviceRef(String name); void store(ConfigurationChanges diffs, Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void load(Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void merge(ConfigurationChanges diffs,
Map<String,BasicBulkDataDescriptor> prevs,
Map<String,BasicBulkDataDescriptor> descriptors,
String parentDN); void store(AttributeCoercions coercions, String parentDN); void load(AttributeCoercions acs, String dn); void merge(ConfigurationChanges diffs, AttributeCoercions prevs, AttributeCoercions acs,
String parentDN); @Override void sync(); @Override synchronized ApplicationEntityInfo[] listAETInfos(ApplicationEntityInfo keys); @Override synchronized WebApplicationInfo[] listWebApplicationInfos(WebApplicationInfo keys); NamingEnumeration<SearchResult> search(String deviceName, String[] attrsArray, String filter); } | @Test public void testRegisterAETitle() throws Exception { config.unregisterAETitle("TEST-AET1"); assertTrue(config.registerAETitle("TEST-AET1")); assertFalse(config.registerAETitle("TEST-AET1")); assertTrue( Arrays.asList(config.listRegisteredAETitles()) .contains("TEST-AET1")); config.unregisterAETitle("TEST-AET1"); assertFalse( Arrays.asList(config.listRegisteredAETitles()) .contains("TEST-AET1")); } |
ValueSelector implements Serializable { public static ValueSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new ValueSelector(AttributeSelector.valueOf(s), AttributeSelector.selectNumber(s, fromIndex) - 1); } catch (Exception e) { throw new IllegalArgumentException(s); } } ValueSelector(int tag, String privateCreator, int index, ItemPointer... itemPointers); ValueSelector(AttributeSelector attributeSelector, int index); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); int valueIndex(); String selectStringValue(Attributes attrs, String defVal); @Override String toString(); static ValueSelector valueOf(String s); @Override int hashCode(); @Override boolean equals(Object obj); } | @Test public void testValueOf() { ValueSelector vs = ValueSelector.valueOf(XPATH); assertEquals(Tag.StudyInstanceUID, vs.tag()); assertNull(vs.privateCreator()); assertEquals(0, vs.valueIndex()); assertEquals(1, vs.level()); ItemPointer ip = vs.itemPointer(0); assertEquals(Tag.RequestAttributesSequence, ip.sequenceTag); assertNull(ip.privateCreator); assertEquals(0, ip.itemIndex); } |
ElementDictionary { public static VR vrOf(int tag, String privateCreator) { return getElementDictionary(privateCreator).vrOf(tag); } protected ElementDictionary(String privateCreator, Class<?> tagClass); static ElementDictionary getStandardElementDictionary(); static ElementDictionary getElementDictionary(String privateCreator); static void reload(); static VR vrOf(int tag, String privateCreator); static String keywordOf(int tag, String privateCreator); static int tagForKeyword(String keyword, String privateCreatorID); final String getPrivateCreator(); abstract VR vrOf(int tag); abstract String keywordOf(int tag); int tmTagOf(int daTag); int daTagOf(int tmTag); int tagForKeyword(String keyword); } | @Test public void testVrOf() { for (int i = 0; i < TAGS.length; i++) assertEquals(VRS[i], ElementDictionary.vrOf(TAGS[i], null)); }
@Test public void testPrivateVrOf() { for (int i = 0; i < SIEMENS_CSA_HEADER_TAGS.length; i++) assertEquals(SIEMENS_CSA_HEADER_VRS[i], ElementDictionary.vrOf(SIEMENS_CSA_HEADER_TAGS[i], SIEMENS_CSA_HEADER)); for (int i = 0; i < SIEMENS_CSA_NON_IMAGE_TAGS.length; i++) assertEquals(SIEMENS_CSA_NON_IMAGE_VRS[i], ElementDictionary.vrOf(SIEMENS_CSA_NON_IMAGE_TAGS[i], SIEMENS_CSA_NON_IMAGE)); } |
ElementDictionary { public static String keywordOf(int tag, String privateCreator) { return getElementDictionary(privateCreator).keywordOf(tag); } protected ElementDictionary(String privateCreator, Class<?> tagClass); static ElementDictionary getStandardElementDictionary(); static ElementDictionary getElementDictionary(String privateCreator); static void reload(); static VR vrOf(int tag, String privateCreator); static String keywordOf(int tag, String privateCreator); static int tagForKeyword(String keyword, String privateCreatorID); final String getPrivateCreator(); abstract VR vrOf(int tag); abstract String keywordOf(int tag); int tmTagOf(int daTag); int daTagOf(int tmTag); int tagForKeyword(String keyword); } | @Test public void testKeywordOf() { for (int i = 0; i < TAGS.length; i++) assertEquals(KEYWORDS[i], ElementDictionary.keywordOf(TAGS[i], null)); }
@Test public void testPrivateKeywordOf() { for (int i = 0; i < SIEMENS_CSA_HEADER_TAGS.length; i++) assertEquals(SIEMENS_CSA_HEADER_KEYWORDS[i], ElementDictionary.keywordOf( SIEMENS_CSA_HEADER_TAGS[i], SIEMENS_CSA_HEADER)); for (int i = 0; i < SIEMENS_CSA_NON_IMAGE_TAGS.length; i++) assertEquals(SIEMENS_CSA_NON_IMAGE_KEYWORDS[i], ElementDictionary.keywordOf( SIEMENS_CSA_NON_IMAGE_TAGS[i], SIEMENS_CSA_NON_IMAGE)); } |
ElementDictionary { public static int tagForKeyword(String keyword, String privateCreatorID) { return getElementDictionary(privateCreatorID).tagForKeyword(keyword); } protected ElementDictionary(String privateCreator, Class<?> tagClass); static ElementDictionary getStandardElementDictionary(); static ElementDictionary getElementDictionary(String privateCreator); static void reload(); static VR vrOf(int tag, String privateCreator); static String keywordOf(int tag, String privateCreator); static int tagForKeyword(String keyword, String privateCreatorID); final String getPrivateCreator(); abstract VR vrOf(int tag); abstract String keywordOf(int tag); int tmTagOf(int daTag); int daTagOf(int tmTag); int tagForKeyword(String keyword); } | @Test public void tagForKeyword() { for (int i = 0; i < KEYWORDS.length-1; i++) assertEquals(TAGS[i], ElementDictionary.tagForKeyword(KEYWORDS[i], null)); }
@Test public void tagPrivateForKeyword() { for (int i = 0; i < SIEMENS_CSA_HEADER_KEYWORDS.length; i++) assertEquals(SIEMENS_CSA_HEADER_TAGS[i], ElementDictionary.tagForKeyword( SIEMENS_CSA_HEADER_KEYWORDS[i], SIEMENS_CSA_HEADER)); for (int i = 0; i < SIEMENS_CSA_NON_IMAGE_KEYWORDS.length; i++) assertEquals(SIEMENS_CSA_NON_IMAGE_TAGS[i], ElementDictionary.tagForKeyword( SIEMENS_CSA_NON_IMAGE_KEYWORDS[i], SIEMENS_CSA_NON_IMAGE)); } |
StringUtils { public static boolean matches(String s, String key, boolean matchNullOrEmpty, boolean ignoreCase) { if (key == null || key.isEmpty()) return true; if (s == null || s.isEmpty()) return matchNullOrEmpty; return containsWildCard(key) ? compilePattern(key, ignoreCase).matcher(s).matches() : ignoreCase ? key.equalsIgnoreCase(s) : key.equals(s); } static StringBuilder appendLine(StringBuilder sb, Object... ss); static String concat(String[] ss, char delim); static String concat(Collection<String> ss, char delim); static Object splitAndTrim(String s, char delim); static String[] split(String s, char delim); static String cut(String s, int index, char delim); static String trimTrailing(String s); static int parseIS(String s); static double parseDS(String s); static String formatDS(float f); static String formatDS(double d); static boolean matches(String s, String key,
boolean matchNullOrEmpty, boolean ignoreCase); static Pattern compilePattern(String key, boolean ignoreCase); static boolean containsWildCard(String s); static String[] maskNull(String[] ss); static T maskNull(T o, T mask); static T nullify(T o, T val); static String maskEmpty(String s, String mask); static String truncate(String s, int maxlen); static boolean equals(T o1, T o2); static String replaceSystemProperties(String s); @Deprecated static String resourceURL(String name); static boolean isUpperCase(String s); static boolean isIPAddr(String s); static boolean contains(T[] a, T o); static T[] requireNotEmpty(T[] a, String message); static String requireNotEmpty(String s, String message); static String[] requireContainsNoEmpty(String[] ss, String message); static String LINE_SEPARATOR; static String[] EMPTY_STRING; } | @Test public void testMatches() { assertTrue(StringUtils.matches("aBcD", "aBcD", false, false)); assertFalse(StringUtils.matches("aBcD", "abCd", false, false)); assertTrue(StringUtils.matches("aBcD", "abCd", false, true)); assertFalse(StringUtils.matches("aBcD", "ab*", false, false)); assertTrue(StringUtils.matches("aBcD", "ab*", false, true)); assertTrue(StringUtils.matches("aBcD", "a?c?", false, false)); assertTrue(StringUtils.matches("aBcD", "a*D*", false, false)); assertFalse(StringUtils.matches("aBcD", "a*d?", false, true)); } |
AttributesFormat extends Format { @Override public StringBuffer format(Object obj, StringBuffer result, FieldPosition pos) { return format.format(toArgs((Attributes) obj), result, pos); } AttributesFormat(String pattern); static AttributesFormat valueOf(String s); @Override StringBuffer format(Object obj, StringBuffer result, FieldPosition pos); @Override Object parseObject(String source, ParsePosition pos); @Override String toString(); } | @Test public void testFormat() { Attributes attrs = new Attributes(); attrs.setString(Tag.ImageType, VR.CS, "ORIGINAL", "PRIMARY", "AXIAL"); attrs.setString(Tag.StudyDate, VR.DA, "20111012"); attrs.setString(Tag.StudyTime, VR.TM, "0930"); attrs.setString(Tag.StudyInstanceUID, VR.UI, "1.2.3"); attrs.setString(Tag.SeriesInstanceUID, VR.UI, "1.2.3.4"); attrs.setString(Tag.SOPInstanceUID, VR.UI, "1.2.3.4.5"); assertEquals("2011/10/12/09/02C82A3A/71668980/PRIMARY/1.2.3.4.5.dcm", new AttributesFormat(TEST_PATTERN).format(attrs)); }
@Test public void testFormatMD5() { Attributes attrs = new Attributes(); attrs.setString(Tag.StudyDate, VR.DA, "20111012"); attrs.setString(Tag.StudyTime, VR.TM, "0930"); attrs.setString(Tag.StudyInstanceUID, VR.UI, "1.2.3"); attrs.setString(Tag.SeriesInstanceUID, VR.UI, "1.2.3.4"); attrs.setString(Tag.SOPInstanceUID, VR.UI, "1.2.3.4.5"); assertEquals("2011/10/12/09/02C82A3A/71668980/08vpsu2l2shpb0kc3orpgfnhv0.dcm", new AttributesFormat(TEST_PATTERN_MD5).format(attrs)); }
@Test public void testFormatRND() { assertTrue(ASSERT_PATTERN_RND.matcher( new AttributesFormat(TEST_PATTERN_RND).format(new Attributes())).matches()); }
@Test public void testOffset() { Attributes attrs = new Attributes(); attrs.setString(Tag.SeriesNumber, VR.IS, "1"); attrs.setString(Tag.InstanceNumber, VR.IS, "2"); assertEquals("101/1", new AttributesFormat(TEST_PATTERN_OFFSET).format(attrs)); } |
LdapDicomConfiguration implements DicomConfiguration { @Override public synchronized ConfigurationChanges persist(Device device, EnumSet<Option> options) throws ConfigurationException { ensureConfigurationExists(); String deviceName = device.getDeviceName(); String deviceDN = deviceRef(deviceName); boolean rollback = false; ArrayList<String> destroyDNs = new ArrayList<>(); try { if (options != null && options.contains(Option.REGISTER)) register(device, destroyDNs); ConfigurationChanges diffs = configurationChangesOf(options); ConfigurationChanges.ModifiedObject ldapObj = ConfigurationChanges.addModifiedObject(diffs, deviceDN, ConfigurationChanges.ChangeType.C); createSubcontext(deviceDN, storeTo(ConfigurationChanges.nullifyIfNotVerbose(diffs, ldapObj), device, new BasicAttributes(true))); rollback = true; storeChilds(ConfigurationChanges.nullifyIfNotVerbose(diffs, diffs), deviceDN, device); if (options == null || !options.contains(Option.PRESERVE_CERTIFICATE)) updateCertificates(device); rollback = false; destroyDNs.clear(); return diffs; } catch (NameAlreadyBoundException e) { throw new ConfigurationAlreadyExistsException(deviceName); } catch (NamingException e) { throw new ConfigurationException(e); } catch (CertificateException e) { throw new ConfigurationException(e); } finally { if (rollback) { try { destroySubcontextWithChilds(deviceDN); } catch (NamingException e) { LOG.warn("Rollback failed:", e); } } unregister(destroyDNs); } } LdapDicomConfiguration(); @SuppressWarnings("unchecked") LdapDicomConfiguration(Hashtable<?,?> env); final boolean isExtended(); final void setExtended(boolean extended); final void setConfigurationCN(String configurationCN); final String getConfigurationCN(); final void setConfigurationRoot(String configurationRoot); final String getConfigurationRoot(); void setPkiUser(String pkiUser); String getPkiUser(); void setUserCertificate(String userCertificate); String getUserCertificate(); void addDicomConfigurationExtension(LdapDicomConfigurationExtension ext); boolean removeDicomConfigurationExtension(
LdapDicomConfigurationExtension ext); @SuppressWarnings("unchecked") @Override T getDicomConfigurationExtension(Class<T> clazz); @Override synchronized void close(); @Override synchronized boolean configurationExists(); boolean exists(String dn); @Override synchronized boolean purgeConfiguration(); @Override synchronized boolean registerAETitle(String aet); @Override synchronized boolean registerWebAppName(String webAppName); @Override synchronized void unregisterAETitle(String aet); @Override synchronized void unregisterWebAppName(String webAppName); @Override synchronized ApplicationEntity findApplicationEntity(String aet); @Override synchronized WebApplication findWebApplication(String name); synchronized Device findDevice(String filter, String childName); Connection findConnection(String connDN, Map<String, Connection> cache); @Override synchronized Device findDevice(String name); @Override synchronized DeviceInfo[] listDeviceInfos(DeviceInfo keys); @Override synchronized String[] listDeviceNames(); @Override synchronized String[] listRegisteredAETitles(); @Override synchronized String[] listRegisteredWebAppNames(); synchronized String[] list(String dn, String filter, String attrID); @Override synchronized ConfigurationChanges persist(Device device, EnumSet<Option> options); @Override ConfigurationChanges merge(Device device, EnumSet<Option> options); @Override synchronized ConfigurationChanges removeDevice(String name, EnumSet<Option> options); synchronized void createSubcontext(String name, Attributes attrs); synchronized void destroySubcontext(String dn); synchronized void destroySubcontextWithChilds(String name); String getConfigurationDN(); void ensureConfigurationExists(); @Override synchronized void persistCertificates(String dn, X509Certificate... certs); @Override synchronized void removeCertificates(String dn); @Override synchronized X509Certificate[] findCertificates(String dn); @Override byte[][] loadDeviceVendorData(String deviceName); @Override ConfigurationChanges updateDeviceVendorData(String deviceName, byte[]... vendorData); Device loadDevice(String deviceDN); Attributes getAttributes(String name); Attributes getAttributes(String name, String[] attrIDs); NamingEnumeration<SearchResult> search(String dn, String filter); NamingEnumeration<SearchResult> search(String dn, String filter,
String... attrs); void modifyAttributes(String dn, List<ModificationItem> mods); void replaceAttributes(String dn, Attributes attrs); @Override String deviceRef(String name); void store(ConfigurationChanges diffs, Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void load(Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void merge(ConfigurationChanges diffs,
Map<String,BasicBulkDataDescriptor> prevs,
Map<String,BasicBulkDataDescriptor> descriptors,
String parentDN); void store(AttributeCoercions coercions, String parentDN); void load(AttributeCoercions acs, String dn); void merge(ConfigurationChanges diffs, AttributeCoercions prevs, AttributeCoercions acs,
String parentDN); @Override void sync(); @Override synchronized ApplicationEntityInfo[] listAETInfos(ApplicationEntityInfo keys); @Override synchronized WebApplicationInfo[] listWebApplicationInfos(WebApplicationInfo keys); NamingEnumeration<SearchResult> search(String deviceName, String[] attrsArray, String filter); } | @Test public void testPersist() throws Exception { try { config.removeDevice("Test-Device-1", null); } catch (ConfigurationNotFoundException e) {} Device device = createDevice("Test-Device-1", "TEST-AET1"); config.persist(device, null); ApplicationEntity ae = config.findApplicationEntity("TEST-AET1"); assertFalse(ae.isAssociationInitiator()); assertTrue(ae.isAssociationAcceptor()); assertTrue(ae.getConnections().get(0).isServer()); TransferCapability echoSCP = ae.getTransferCapabilityFor( UID.Verification, TransferCapability.Role.SCP); assertNotNull(echoSCP); assertArrayEquals(new String[] { UID.ImplicitVRLittleEndian }, echoSCP.getTransferSyntaxes()); TransferCapability ctSCP = ae.getTransferCapabilityFor( UID.CTImageStorage, TransferCapability.Role.SCP); assertNotNull(ctSCP); assertArrayEquals(new String[] { UID.ImplicitVRLittleEndian, UID.ExplicitVRLittleEndian }, sort(ctSCP.getTransferSyntaxes())); assertNull(ctSCP.getStorageOptions()); TransferCapability findSCP = ae.getTransferCapabilityFor( UID.StudyRootQueryRetrieveInformationModelFind, TransferCapability.Role.SCP); assertNotNull(findSCP); assertArrayEquals(new String[] { UID.ImplicitVRLittleEndian }, findSCP.getTransferSyntaxes()); assertEquals(EnumSet.of(QueryOption.RELATIONAL), findSCP.getQueryOptions()); assertEquals(1, config.listDeviceInfos(deviceInfo("Test-Device-1")).length); try { config.persist(createDevice("Test-Device-1", "TEST-AET1"), null); fail("ConfigurationAlreadyExistsException expected"); } catch (ConfigurationAlreadyExistsException e) {} config.removeDevice("Test-Device-1", null); } |
DateUtils { public static String formatDA(TimeZone tz, Date date) { return formatDA(tz, date, new StringBuilder(8)).toString(); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date,
StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date,
StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static final Date[] EMPTY_DATES; } | @Test public void testFormatDA() { assertEquals("19700101", DateUtils.formatDA(tz, new Date(0))); } |
DateUtils { public static String formatTM(TimeZone tz, Date date) { return formatTM(tz, date, new DatePrecision()); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date,
StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date,
StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static final Date[] EMPTY_DATES; } | @Test public void testFormatTM() { assertEquals("020000.000", DateUtils.formatTM(tz, new Date(0))); } |
DateUtils { public static String formatDT(TimeZone tz, Date date) { return formatDT(tz, date, new DatePrecision()); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date,
StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date,
StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static final Date[] EMPTY_DATES; } | @Test public void testFormatDT() { assertEquals("19700101020000.000", DateUtils.formatDT(tz, new Date(0))); }
@Test public void testFormatDTwithTZ() { assertEquals("19700101020000.000+0200", DateUtils.formatDT(tz, new Date(0), new DatePrecision(Calendar.MILLISECOND, true))); } |
DateUtils { public static Date parseDA(TimeZone tz, String s) { return parseDA(tz, s, false); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date,
StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date,
StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static final Date[] EMPTY_DATES; } | @Test public void testParseDA() { assertEquals(-2 * HOUR, DateUtils.parseDA(tz, "19700101").getTime()); }
@Test public void testParseDAacrnema() { assertEquals(-2 * HOUR, DateUtils.parseDA(tz, "1970.01.01").getTime()); }
@Test public void testParseDAceil() { assertEquals(DAY - 2 * HOUR - 1, DateUtils.parseDA(tz, "19700101", true).getTime()); } |
DateUtils { public static Date parseTM(TimeZone tz, String s, DatePrecision precision) { return parseTM(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date,
StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date,
StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static final Date[] EMPTY_DATES; } | @Test public void testParseTM() { DatePrecision precision = new DatePrecision(); assertEquals(0, DateUtils.parseTM(tz, "020000.000", precision).getTime()); assertEquals(Calendar.MILLISECOND, precision.lastField); }
@Test public void testParseTMacrnema() { DatePrecision precision = new DatePrecision(); assertEquals(0, DateUtils.parseTM(tz, "02:00:00", precision).getTime()); assertEquals(Calendar.SECOND, precision.lastField); }
@Test public void testParseTMceil() { DatePrecision precision = new DatePrecision(); assertEquals(MINUTE - 1, DateUtils.parseTM(tz, "0200", true, precision).getTime()); assertEquals(Calendar.MINUTE, precision.lastField); } |
LdapDicomConfiguration implements DicomConfiguration { @Override public ConfigurationChanges merge(Device device, EnumSet<Option> options) throws ConfigurationException { ConfigurationChanges diffs = configurationChangesOf(options); merge(device, options, diffs); return diffs; } LdapDicomConfiguration(); @SuppressWarnings("unchecked") LdapDicomConfiguration(Hashtable<?,?> env); final boolean isExtended(); final void setExtended(boolean extended); final void setConfigurationCN(String configurationCN); final String getConfigurationCN(); final void setConfigurationRoot(String configurationRoot); final String getConfigurationRoot(); void setPkiUser(String pkiUser); String getPkiUser(); void setUserCertificate(String userCertificate); String getUserCertificate(); void addDicomConfigurationExtension(LdapDicomConfigurationExtension ext); boolean removeDicomConfigurationExtension(
LdapDicomConfigurationExtension ext); @SuppressWarnings("unchecked") @Override T getDicomConfigurationExtension(Class<T> clazz); @Override synchronized void close(); @Override synchronized boolean configurationExists(); boolean exists(String dn); @Override synchronized boolean purgeConfiguration(); @Override synchronized boolean registerAETitle(String aet); @Override synchronized boolean registerWebAppName(String webAppName); @Override synchronized void unregisterAETitle(String aet); @Override synchronized void unregisterWebAppName(String webAppName); @Override synchronized ApplicationEntity findApplicationEntity(String aet); @Override synchronized WebApplication findWebApplication(String name); synchronized Device findDevice(String filter, String childName); Connection findConnection(String connDN, Map<String, Connection> cache); @Override synchronized Device findDevice(String name); @Override synchronized DeviceInfo[] listDeviceInfos(DeviceInfo keys); @Override synchronized String[] listDeviceNames(); @Override synchronized String[] listRegisteredAETitles(); @Override synchronized String[] listRegisteredWebAppNames(); synchronized String[] list(String dn, String filter, String attrID); @Override synchronized ConfigurationChanges persist(Device device, EnumSet<Option> options); @Override ConfigurationChanges merge(Device device, EnumSet<Option> options); @Override synchronized ConfigurationChanges removeDevice(String name, EnumSet<Option> options); synchronized void createSubcontext(String name, Attributes attrs); synchronized void destroySubcontext(String dn); synchronized void destroySubcontextWithChilds(String name); String getConfigurationDN(); void ensureConfigurationExists(); @Override synchronized void persistCertificates(String dn, X509Certificate... certs); @Override synchronized void removeCertificates(String dn); @Override synchronized X509Certificate[] findCertificates(String dn); @Override byte[][] loadDeviceVendorData(String deviceName); @Override ConfigurationChanges updateDeviceVendorData(String deviceName, byte[]... vendorData); Device loadDevice(String deviceDN); Attributes getAttributes(String name); Attributes getAttributes(String name, String[] attrIDs); NamingEnumeration<SearchResult> search(String dn, String filter); NamingEnumeration<SearchResult> search(String dn, String filter,
String... attrs); void modifyAttributes(String dn, List<ModificationItem> mods); void replaceAttributes(String dn, Attributes attrs); @Override String deviceRef(String name); void store(ConfigurationChanges diffs, Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void load(Map<String, BasicBulkDataDescriptor> descriptors, String parentDN); void merge(ConfigurationChanges diffs,
Map<String,BasicBulkDataDescriptor> prevs,
Map<String,BasicBulkDataDescriptor> descriptors,
String parentDN); void store(AttributeCoercions coercions, String parentDN); void load(AttributeCoercions acs, String dn); void merge(ConfigurationChanges diffs, AttributeCoercions prevs, AttributeCoercions acs,
String parentDN); @Override void sync(); @Override synchronized ApplicationEntityInfo[] listAETInfos(ApplicationEntityInfo keys); @Override synchronized WebApplicationInfo[] listWebApplicationInfos(WebApplicationInfo keys); NamingEnumeration<SearchResult> search(String deviceName, String[] attrsArray, String filter); } | @Test public void testMerge() throws Exception { try { config.removeDevice("Test-Device-1", null); } catch (ConfigurationNotFoundException e) {} Device device = createDevice("Test-Device-1", "TEST-AET1"); config.persist(device, null); modifyDevice(device); config.merge(device, null); ApplicationEntity ae2 = config.findApplicationEntity("TEST-AET2"); ApplicationEntity ae = ae2.getDevice().getApplicationEntity("TEST-AET1"); assertTrue(ae.isAssociationInitiator()); assertFalse(ae.isAssociationAcceptor()); assertFalse(ae.getConnections().get(0).isServer()); TransferCapability echoSCP = ae.getTransferCapabilityFor( UID.Verification, TransferCapability.Role.SCP); assertNull(echoSCP); TransferCapability echoSCU = ae.getTransferCapabilityFor( UID.Verification, TransferCapability.Role.SCU); assertNotNull(echoSCU); TransferCapability ctSCP = ae.getTransferCapabilityFor( UID.CTImageStorage, TransferCapability.Role.SCP); assertEquals(STORAGE_OPTIONS, ctSCP.getStorageOptions()); TransferCapability findSCP = ae.getTransferCapabilityFor( UID.StudyRootQueryRetrieveInformationModelFind, TransferCapability.Role.SCP); assertEquals(EnumSet.of(QueryOption.RELATIONAL, QueryOption.DATETIME), findSCP.getQueryOptions()); config.removeDevice("Test-Device-1", null); } |
DateUtils { public static Date parseDT(TimeZone tz, String s, DatePrecision precision) { return parseDT(tz, s, false, precision); } static String formatDA(TimeZone tz, Date date); static StringBuilder formatDA(TimeZone tz, Date date,
StringBuilder toAppendTo); static String formatTM(TimeZone tz, Date date); static String formatTM(TimeZone tz, Date date, DatePrecision precision); static String formatDT(TimeZone tz, Date date); static String formatDT(TimeZone tz, Date date, DatePrecision precision); static StringBuilder formatDT(TimeZone tz, Date date,
StringBuilder toAppendTo, DatePrecision precision); static String formatTimezoneOffsetFromUTC(TimeZone tz); static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date); static Date parseDA(TimeZone tz, String s); static Date parseDA(TimeZone tz, String s, boolean ceil); static Date parseTM(TimeZone tz, String s, DatePrecision precision); static Date parseTM(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static Date parseDT(TimeZone tz, String s, DatePrecision precision); static TimeZone timeZone(String s); static Date parseDT(TimeZone tz, String s, boolean ceil,
DatePrecision precision); static final Date[] EMPTY_DATES; } | @Test public void testParseDT() { DatePrecision precision = new DatePrecision(); assertEquals(0, DateUtils.parseDT(tz, "19700101020000.000", precision).getTime()); assertEquals(Calendar.MILLISECOND, precision.lastField); assertFalse(precision.includeTimezone); }
@Test public void testParseWithTZ() { DatePrecision precision = new DatePrecision(); assertEquals(2 * HOUR, DateUtils.parseDT(tz, "19700101020000.000+0000", precision).getTime()); assertEquals(Calendar.MILLISECOND, precision.lastField); assertTrue(precision.includeTimezone); }
@Test public void testParseDTceil() { DatePrecision precision = new DatePrecision(); assertEquals(YEAR - 2 * HOUR - 1, DateUtils.parseDT(tz, "1970", true, precision).getTime()); assertEquals(Calendar.YEAR, precision.lastField); assertFalse(precision.includeTimezone); } |
IntHashMap implements Cloneable, java.io.Serializable { public int size() { return size; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testSize() { assertEquals(15, map.size()); removeOdd(); assertEquals(7, map.size()); } |
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V get(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return (V) values[i]; i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testGet() { removeOdd(); testGet(map); } |
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V put(int key, V value) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] > FREE) { if (keys[i] == key) { V oldValue = (V) values[i]; values[i] = value; return oldValue; } i = (i + 1) & mask; } byte oldState = states[i]; states[i] = FULL; keys[i] = key; values[i] = value; ++size; if (oldState == FREE && --free < 0) resize(Math.max(capacity(size), keys.length)); return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testPut() { removeOdd(); for (int i = 0; i < 45; i++) map.put(i, Integer.valueOf(i)); assertEquals(45, map.size()); for (int i = 0; i < 45; i++) assertEquals(Integer.valueOf(i), map.get(i)); } |
IntHashMap implements Cloneable, java.io.Serializable { public boolean containsKey(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) return states[i] > FREE; i = (i + 1) & mask; } return false; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testContainsKey() { removeOdd(); for (int i = 1; i < 45; i++) assertEquals((i & 1) == 0 && (i % 3) == 1, map.containsKey(i)); } |
IntHashMap implements Cloneable, java.io.Serializable { public void rehash() { resize(keys.length); } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testRehash() { removeOdd(); map.trimToSize(); testGet(map); } |
JsonConfiguration { public void writeTo(DeviceInfo deviceInfo, JsonGenerator gen) { JsonWriter writer = new JsonWriter(gen); gen.writeStartObject(); gen.write("dicomDeviceName", deviceInfo.getDeviceName()); writer.writeNotNullOrDef("dicomDescription", deviceInfo.getDescription(), null); writer.writeNotNullOrDef("dicomManufacturer", deviceInfo.getManufacturer(), null); writer.writeNotNullOrDef("dicomManufacturerModelName", deviceInfo.getManufacturerModelName(), null); writer.writeNotEmpty("dicomSoftwareVersion", deviceInfo.getSoftwareVersions()); writer.writeNotNullOrDef("dicomStationName", deviceInfo.getStationName(), null); writer.writeNotEmpty("dicomInstitutionName", deviceInfo.getInstitutionNames()); writer.writeNotEmpty("dicomInstitutionDepartmentName", deviceInfo.getInstitutionalDepartmentNames()); writer.writeNotEmpty("dicomPrimaryDeviceType", deviceInfo.getPrimaryDeviceTypes()); gen.write("dicomInstalled", deviceInfo.getInstalled()); gen.write("hasArcDevExt", deviceInfo.getArcDevExt()); gen.writeEnd(); } void addJsonConfigurationExtension(JsonConfigurationExtension ext); boolean removeJsonConfigurationExtension(JsonConfigurationExtension ext); T getJsonConfigurationExtension(Class<T> clazz); void writeTo(DeviceInfo deviceInfo, JsonGenerator gen); void writeTo(ApplicationEntityInfo aetInfo, JsonGenerator gen); void writeTo(WebApplicationInfo webappInfo, JsonGenerator gen); void writeTo(WebApplicationInfo webappInfo, JsonGenerator gen, String keycloakClientID); void writeTo(HL7ApplicationInfo hl7AppInfo, JsonGenerator gen); void writeTo(Device device, JsonGenerator gen, boolean extended); Device loadDeviceFrom(JsonParser parser, ConfigurationDelegate config); void writeBulkdataDescriptors(Map<String, BasicBulkDataDescriptor> descriptors, JsonWriter writer); void loadBulkdataDescriptors(Map<String, BasicBulkDataDescriptor> descriptors, JsonReader reader); } | @Test public void testWriteTo() throws Exception { StringWriter writer = new StringWriter(); try ( JsonGenerator gen = Json.createGenerator(writer)) { JsonConfiguration config = new JsonConfiguration(); config.addJsonConfigurationExtension(new JsonAuditLoggerConfiguration()); config.addJsonConfigurationExtension(new JsonAuditRecordRepositoryConfiguration()); config.addJsonConfigurationExtension(new JsonImageReaderConfiguration()); config.addJsonConfigurationExtension(new JsonImageWriterConfiguration()); config.addJsonConfigurationExtension(new JsonHL7Configuration()); config.writeTo(createDevice("Test-Device-1", "TEST-AET1"), gen, true); } Path path = Paths.get("src/test/data/device.json"); try (BufferedReader reader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { assertEquals(reader.readLine(), writer.toString()); } } |
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public V remove(int key) { byte[] states = this.states; int[] keys = this.keys; int mask = keys.length - 1; int i = key & mask; while (states[i] != FREE) { if (keys[i] == key) { if (states[i] < FREE) return null; states[i] = REMOVED; V oldValue = (V) values[i]; values[i] = null; size--; return oldValue; } i = (i + 1) & mask; } return null; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testRemove() { for (int i = 1; i < 45; i += 2) if ((i % 3) == 1) assertEquals(Integer.valueOf(i), map.remove(i)); else assertNull(map.remove(i)); } |
IntHashMap implements Cloneable, java.io.Serializable { public void clear() { Arrays.fill(values, null); Arrays.fill(states, FREE); size = 0; free = keys.length >>> 1; } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @Test public void testClear() { assertFalse(map.isEmpty()); map.clear(); assertTrue(map.isEmpty()); } |
IntHashMap implements Cloneable, java.io.Serializable { @SuppressWarnings("unchecked") public Object clone() { try { IntHashMap<V> m = (IntHashMap<V>) super.clone(); m.states = states.clone(); m.keys = keys.clone(); m.values = values.clone(); return m; } catch (CloneNotSupportedException e) { throw new InternalError(); } } IntHashMap(); IntHashMap(int expectedMaxSize); int size(); boolean isEmpty(); @SuppressWarnings("unchecked") V get(int key); boolean containsKey(int key); @SuppressWarnings("unchecked") V put(int key, V value); void trimToSize(); void rehash(); @SuppressWarnings("unchecked") V remove(int key); void clear(); @SuppressWarnings("unchecked") Object clone(); @SuppressWarnings("unchecked") boolean accept(Visitor<V> visitor); } | @SuppressWarnings("unchecked") @Test public void testClone() { removeOdd(); IntHashMap<Integer> clone = (IntHashMap<Integer>) map.clone(); map.clear(); testGet(clone); } |
ByteUtils { public static int bytesToUShortBE(byte[] bytes, int off) { return ((bytes[off] & 255) << 8) + (bytes[off + 1] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToUShortBE() { assertEquals(-12345 & 0xffff, ByteUtils.bytesToUShortBE(SHORT_12345_BE, 0)); } |
ByteUtils { public static int bytesToUShortLE(byte[] bytes, int off) { return ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToUShortLE() { assertEquals(-12345 & 0xffff, ByteUtils.bytesToUShortLE(SHORT_12345_LE, 0)); } |
ByteUtils { public static int bytesToShortBE(byte[] bytes, int off) { return (bytes[off] << 8) + (bytes[off + 1] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToShortBE() { assertEquals(-12345, ByteUtils.bytesToShortBE(SHORT_12345_BE, 0)); } |
ByteUtils { public static int bytesToShortLE(byte[] bytes, int off) { return (bytes[off + 1] << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToShortLE() { assertEquals(-12345, ByteUtils.bytesToShortLE(SHORT_12345_LE, 0)); } |
ByteUtils { public static int bytesToIntBE(byte[] bytes, int off) { return (bytes[off] << 24) + ((bytes[off + 1] & 255) << 16) + ((bytes[off + 2] & 255) << 8) + (bytes[off + 3] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToIntBE() { assertEquals(-12345, ByteUtils.bytesToIntBE(INT_12345_BE, 0)); } |
ByteUtils { public static int bytesToIntLE(byte[] bytes, int off) { return (bytes[off + 3] << 24) + ((bytes[off + 2] & 255) << 16) + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToIntLE() { assertEquals(-12345, ByteUtils.bytesToIntLE(INT_12345_LE, 0)); } |
ByteUtils { public static int bytesToTagBE(byte[] bytes, int off) { return bytesToIntBE(bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToTagBE() { assertEquals(Tag.PixelData, ByteUtils.bytesToTagBE(TAG_PIXEL_DATA_BE, 0)); } |
AttributeSelector implements Serializable { @Override public String toString() { if (str == null) str = toStringBuilder().toString(); return str; } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); } | @Test public void testToString() { ItemPointer ip = new ItemPointer(Tag.RequestAttributesSequence); AttributeSelector selector = new AttributeSelector(Tag.StudyInstanceUID, null, ip); assertEquals(XPATH, selector.toString()); } |
ByteUtils { public static int bytesToTagLE(byte[] bytes, int off) { return (bytes[off + 1] << 24) + ((bytes[off] & 255) << 16) + ((bytes[off + 3] & 255) << 8) + (bytes[off + 2] & 255); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToTagLE() { assertEquals(Tag.PixelData, ByteUtils.bytesToTagLE(TAG_PIXEL_DATA_LE, 0)); } |
ByteUtils { public static float bytesToFloatBE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntBE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToFloatBE() { assertEquals((float) Math.PI, ByteUtils.bytesToFloatBE(FLOAT_PI_BE, 0), 0); } |
ByteUtils { public static float bytesToFloatLE(byte[] bytes, int off) { return Float.intBitsToFloat(bytesToIntLE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToFloatLE() { assertEquals((float) Math.PI, ByteUtils.bytesToFloatLE(FLOAT_PI_LE, 0), 0); } |
ByteUtils { public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToDoubleBE() { assertEquals(Math.PI, ByteUtils.bytesToDoubleBE(DOUBLE_PI_BE, 0), 0); } |
ByteUtils { public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testBytesToDoubleLE() { assertEquals(Math.PI, ByteUtils.bytesToDoubleLE(DOUBLE_PI_LE, 0), 0); } |
ByteUtils { public static byte[] shortToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 8); bytes[off + 1] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testShortToBytesBE() { assertArrayEquals(SHORT_12345_BE, ByteUtils.shortToBytesBE(-12345, new byte[2] , 0)); } |
ByteUtils { public static byte[] shortToBytesLE(int i, byte[] bytes, int off) { bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testShortToBytesLE() { assertArrayEquals(SHORT_12345_LE, ByteUtils.shortToBytesLE(-12345, new byte[2] , 0)); } |
ByteUtils { public static byte[] intToBytesBE(int i, byte[] bytes, int off) { bytes[off] = (byte) (i >> 24); bytes[off + 1] = (byte) (i >> 16); bytes[off + 2] = (byte) (i >> 8); bytes[off + 3] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testIntToBytesBE() { assertArrayEquals(INT_12345_BE, ByteUtils.intToBytesBE(-12345, new byte[4] , 0)); } |
ByteUtils { public static byte[] intToBytesLE(int i, byte[] bytes, int off) { bytes[off + 3] = (byte) (i >> 24); bytes[off + 2] = (byte) (i >> 16); bytes[off + 1] = (byte) (i >> 8); bytes[off] = (byte) i; return bytes; } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testIntToBytesLE() { assertArrayEquals(INT_12345_LE, ByteUtils.intToBytesLE(-12345, new byte[4] , 0)); } |
ByteUtils { public static byte[] tagToBytesBE(int i, byte[] bytes, int off) { return intToBytesBE(i, bytes, off); } static int bytesToVR(byte[] bytes, int off); static int bytesToUShort(byte[] bytes, int off, boolean bigEndian); static int bytesToUShortBE(byte[] bytes, int off); static int bytesToUShortLE(byte[] bytes, int off); static int bytesToShort(byte[] bytes, int off, boolean bigEndian); static int bytesToShortBE(byte[] bytes, int off); static int bytesToShortLE(byte[] bytes, int off); static void bytesToShorts(byte[] b, short[] s, int off, int len, boolean bigEndian); static void bytesToShortsLE(byte[] b, short[] s, int off, int len); static void bytesToShortsBE(byte[] b, short[] s, int off, int len); static int bytesToInt(byte[] bytes, int off, boolean bigEndian); static int bytesToIntBE(byte[] bytes, int off); static int bytesToIntLE(byte[] bytes, int off); static int bytesToTag(byte[] bytes, int off, boolean bigEndian); static int bytesToTagBE(byte[] bytes, int off); static int bytesToTagLE(byte[] bytes, int off); static float bytesToFloat(byte[] bytes, int off, boolean bigEndian); static float bytesToFloatBE(byte[] bytes, int off); static float bytesToFloatLE(byte[] bytes, int off); static long bytesToLong(byte[] bytes, int off, boolean bigEndian); static long bytesToLongBE(byte[] bytes, int off); static long bytesToLongLE(byte[] bytes, int off); static double bytesToDouble(byte[] bytes, int off, boolean bigEndian); static double bytesToDoubleBE(byte[] bytes, int off); static double bytesToDoubleLE(byte[] bytes, int off); static byte[] shortToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] shortToBytesBE(int i, byte[] bytes, int off); static byte[] shortToBytesLE(int i, byte[] bytes, int off); static byte[] intToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] intToBytesBE(int i, byte[] bytes, int off); static byte[] intToBytesLE(int i, byte[] bytes, int off); static byte[] tagToBytes(int i, byte[] bytes, int off,
boolean bigEndian); static byte[] tagToBytesBE(int i, byte[] bytes, int off); static byte[] tagToBytesLE(int i, byte[] bytes, int off); static byte[] floatToBytes(float f, byte[] bytes, int off,
boolean bigEndian); static byte[] floatToBytesBE(float f, byte[] bytes, int off); static byte[] floatToBytesLE(float f, byte[] bytes, int off); static byte[] doubleToBytes(double d, byte[] bytes, int off,
boolean bigEndian); static byte[] doubleToBytesBE(double d, byte[] bytes, int off); static byte[] doubleToBytesLE(double d, byte[] bytes, int off); static byte[] longToBytes(long l, byte[] bytes, int off,
boolean bigEndian); static byte[] longToBytesBE(long l, byte[] bytes, int off); static byte[] longToBytesLE(long l, byte[] bytes, int off); static byte[][] swapShorts(byte bs[][]); static byte[] swapShorts(byte b[], int off, int len); static byte[] swapInts(byte b[], int off, int len); static byte[] swapLongs(byte b[], int off, int len); static byte[] intsToBytesLE(int... values); static final byte[] EMPTY_BYTES; static final int[] EMPTY_INTS; static final float[] EMPTY_FLOATS; static final double[] EMPTY_DOUBLES; } | @Test public void testTagToBytesBE() { assertArrayEquals(TAG_PIXEL_DATA_BE, ByteUtils.tagToBytesBE(Tag.PixelData, new byte[4] , 0)); } |
AttributeSelector implements Serializable { public static AttributeSelector valueOf(String s) { int fromIndex = s.lastIndexOf("DicomAttribute"); try { return new AttributeSelector( selectTag(s, fromIndex), selectPrivateCreator(s, fromIndex), itemPointersOf(s, fromIndex)); } catch (Exception e) { throw new IllegalArgumentException(s); } } AttributeSelector(int tag); AttributeSelector(int tag, String privateCreator); AttributeSelector(int tag, String privateCreator, ItemPointer... itemPointers); AttributeSelector(int tag, String privateCreator, List<ItemPointer> itemPointers); int tag(); String privateCreator(); int level(); ItemPointer itemPointer(int index); String selectStringValue(Attributes attrs, int valueIndex, String defVal); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static AttributeSelector valueOf(String s); boolean matches(List<ItemPointer> itemPointers, String privateCreator, int tag); } | @Test public void testValueOf() { AttributeSelector selector = AttributeSelector.valueOf(XPATH); assertEquals(Tag.StudyInstanceUID, selector.tag()); assertNull(selector.privateCreator()); assertEquals(1, selector.level()); ItemPointer ip = selector.itemPointer(0); assertEquals(Tag.RequestAttributesSequence, ip.sequenceTag); assertNull(ip.privateCreator); assertEquals(-1, ip.itemIndex); } |
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); } | @Test public void testStartUpProdServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext, never()).addServlet(eq("H2Console"), any(WebServlet.class)); }
@Test public void testStartUpDevServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext).addServlet(eq("H2Console"), any(WebServlet.class)); } |
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); mappings.add("json", "text/html;charset=utf-8"); container.setMimeMappings(mappings); if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) { ((UndertowEmbeddedServletContainerFactory) container) .addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)); } } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); } | @Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }
@Test public void testUndertowHttp2Enabled() { props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue(); } |
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = jHipsterProperties.getCors(); if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) { log.debug("Registering CORS filter"); source.registerCorsConfiguration("/api/**", config); source.registerCorsConfiguration("/v2/api-docs", config); } return new CorsFilter(source); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties, HazelcastInstance hazelcastInstance); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); } | @Test public void testCorsFilterOnApiPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( options("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")) .andExpect(header().string(HttpHeaders.VARY, "Origin")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800")); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com")); }
@Test public void testCorsFilterOnOtherPath() throws Exception { props.getCors().setAllowedOrigins(Collections.singletonList("*")); props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); props.getCors().setAllowedHeaders(Collections.singletonList("*")); props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/test/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
@Test public void testCorsFilterDeactivated() throws Exception { props.getCors().setAllowedOrigins(null); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); }
@Test public void testCorsFilterDeactivated2() throws Exception { props.getCors().setAllowedOrigins(new ArrayList<>()); MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) .addFilters(webConfigurer.corsFilter()) .build(); mockMvc.perform( get("/api/test-cors") .header(HttpHeaders.ORIGIN, "other.domain.com")) .andExpect(status().isOk()) .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); } |
WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer { @Override public void onStartup(ServletContext servletContext) throws ServletException { if (env.getActiveProfiles().length != 0) { log.info("Web application configuration, using profiles: {}", (Object[]) env.getActiveProfiles()); } EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); initMetrics(servletContext, disps); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) { initCachingHttpHeadersFilter(servletContext, disps); } if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { initH2Console(servletContext); } log.info("Web application fully configured"); } WebConfigurer(Environment env, JHipsterProperties jHipsterProperties); @Override void onStartup(ServletContext servletContext); @Override void customize(ConfigurableEmbeddedServletContainer container); @Bean CorsFilter corsFilter(); @Autowired(required = false) void setMetricRegistry(MetricRegistry metricRegistry); } | @Test public void testStartUpProdServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext).addFilter(eq("cachingHttpHeadersFilter"), any(CachingHttpHeadersFilter.class)); verify(servletContext, never()).addServlet(eq("H2Console"), any(WebServlet.class)); }
@Test public void testStartUpDevServletContext() throws ServletException { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT); webConfigurer.onStartup(servletContext); assertThat(servletContext.getAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE)).isEqualTo(metricRegistry); assertThat(servletContext.getAttribute(MetricsServlet.METRICS_REGISTRY)).isEqualTo(metricRegistry); verify(servletContext).addFilter(eq("webappMetricsFilter"), any(InstrumentedFilter.class)); verify(servletContext).addServlet(eq("metricsServlet"), any(MetricsServlet.class)); verify(servletContext, never()).addFilter(eq("cachingHttpHeadersFilter"), any(CachingHttpHeadersFilter.class)); verify(servletContext).addServlet(eq("H2Console"), any(WebServlet.class)); } |
Post extends AuditableEntity { @PrePersist public void slugify(){ this.slug = new Slugify().slugify(this.title); } @PrePersist void slugify(); } | @Test public void testSlug() { System.out.println("getSlug"); Post instance = new Post(); instance.setTitle("test post 1"); instance.slugify(); assertEquals("test-post-1", instance.getSlug()); } |
PostService { public Post createPost(PostForm form) { Post _post = Post.builder() .title(form.getTitle()) .content(form.getContent()) .build(); Post saved = this.postRepository.save(_post); return saved; } Post createPost(PostForm form); Post updatePost(String slug, PostForm form); void deletePost(String slug); } | @Test public void createPost() { final String TITLE = "test post title"; final String CONTENT = "test post content"; final PostForm input = PostForm.builder().title(TITLE).content(CONTENT).build(); Post expected = Post.builder().title(TITLE).content(CONTENT).build(); expected.setId(1L); given(posts.save(Post.builder().title(input.getTitle()).content(input.getContent()).build())) .willReturn(expected); Post returned = postService.createPost(input); assertTrue(returned == expected); verify(posts, times(1)).save(any(Post.class)); verifyNoMoreInteractions(posts); } |
UserServiceClient { public User findByUsername(String username) { try { ResponseEntity<User> response = this.restTemplate.getForEntity(userServiceUrl + "/users/{username}", User.class, username); return response.getBody(); } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { return null; } } return null; } UserServiceClient(RestTemplateBuilder builder, ObjectMapper objectMapper); void handleSignup(SignupForm form); User findByUsername(String username); } | @Test public void testFindbyUsername() { this.server.expect(requestTo(userServiceUrl + "/users/user")) .andRespond(withSuccess(new ClassPathResource("/find-user-by-username.json"), MediaType.APPLICATION_JSON_UTF8)); User user = this.client.findByUsername("user"); assertNotNull(user); assertEquals("user", user.getUsername()); this.server.verify(); }
@Test public void testFindbyUsername_notFound() { this.server.expect(requestTo(userServiceUrl + "/users/user1")) .andRespond(withStatus(NOT_FOUND)); User user = this.client.findByUsername("user1"); assertNull(user); this.server.verify(); } |
GraphExporter { public BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state) { BufferedImage graphImage; int stateImageWidth = (int) (STATE_AREA_WIDTH * scale); BufferedImage stateImage = null; if (selectedBlock != null && state != null) { mxCell currentCell = selectedBlock.getMxCell(); String originalStrokeColor = (String) graph.getCellStyle(currentCell).get(mxConstants.STYLE_STROKECOLOR); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, Styles.SELECTION_BORDER_COLOR, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.SELECTION_STROKE_WIDTH), new Object[]{selectedBlock.getMxCell()}); graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); graph.setCellStyles(mxConstants.STYLE_STROKECOLOR, originalStrokeColor == null ? mxConstants.NONE : originalStrokeColor, new Object[]{currentCell}); graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, String.valueOf(Styles.DEFAULT_STROKE_WIDTH), new Object[]{currentCell}); LatticeElement inState = state.getInState(); LatticeElement outState = state.getOutState(); String in = inState == null ? "<not set>" : inState.getStringRepresentation(); String out = outState == null ? "<not set>" : outState.getStringRepresentation(); int blockNumber = selectedBlock.getBlockNumber(); int lineNumber = selectedBlock.getLineNumber(); stateImage = new BufferedImage(stateImageWidth, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gO = stateImage.createGraphics(); gO.setFont(new Font(Font.MONOSPACED, Font.BOLD, (int) (FONT_SIZE * scale))); gO.setColor(Colors.DARK_TEXT.getColor()); String[] inStrings = in.split("\n"); String[] outStrings = out.split("\n"); int lineHeight = (int) (LINE_HEIGHT * scale); int height = lineHeight; String selectionString = "Selected Position: (" + blockNumber; selectionString += lineNumber == -1 ? ")" : ", " + lineNumber + ")"; gO.drawString(selectionString, 0, height); height += 2 * lineHeight; gO.drawString("In State:", 0, height); for (String s : inStrings) { height += lineHeight; gO.drawString(s, 0, height); } height += 3 * lineHeight; gO.drawString("Out State:", 0, height); for (String s : outStrings) { height += lineHeight; gO.drawString(s, 0, height); } } else { graphImage = mxCellRenderer.createBufferedImage(graph, null, scale, null, true, null); } BufferedImage result = new BufferedImage(graphImage.getWidth() + stateImageWidth + 2 * PADDING, graphImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics resultGraphics = result.getGraphics(); resultGraphics.drawImage(graphImage, PADDING, 0, null); if (stateImage != null) { resultGraphics.drawImage(stateImage, graphImage.getWidth() + 2 * PADDING, 0, null); } resultGraphics.dispose(); return result; } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); } | @Test public void shouldCreateSmallExportImage() throws IOException { BufferedImage exportedImage = graphExporter.exportCurrentGraph(graph, 1.0, null, null); BufferedImage referenceImage = ImageIO.read(getClass().getResourceAsStream("/export-small.png")); Assert.assertEquals("", TestUtils.bufferedImagesEqual(exportedImage, referenceImage, 10, 100, 10)); }
@Test public void shouldCreateMediumExportImage() throws IOException { BufferedImage exportedImage = graphExporter.exportCurrentGraph(graph, 2.0, null, null); BufferedImage referenceImage = ImageIO.read(getClass().getResourceAsStream("/export-medium.png")); Assert.assertEquals("", TestUtils.bufferedImagesEqual(exportedImage, referenceImage, 10, 300, 10)); }
@Test public void shouldCreateLargeExportImage() throws IOException { BufferedImage exportedImage = graphExporter.exportCurrentGraph(graph, 3.0, null, null); BufferedImage referenceImage = ImageIO.read(getClass().getResourceAsStream("/export-large.png")); Assert.assertEquals("", TestUtils.bufferedImagesEqual(exportedImage, referenceImage, 10, 800, 10)); } |
GraphExporter { public void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback) { dfa = dfa.clone(); VisualGraphPanel panel = new VisualGraphPanel(); panel.setJumpToAction(true); GraphUIController controller = new GraphUIController(panel); controller.start(dfa); int totalSteps = includeLineSteps ? dfa.getTotalElementarySteps() : dfa.getTotalBlockSteps(); callback.setMaxStep(totalSteps + 1); for (int step = 0; step < totalSteps; step++) { if (includeLineSteps) { dfa.setCurrentElementaryStep(step); } else { dfa.setCurrentBlockStep(step); } controller.refresh(); UIAbstractBlock selectedBlock = panel.getSelectedBlock(); BlockState<? extends LatticeElement> state = selectedBlock == null ? null : dfa.getCurrentAnalysisState().getBlockState(selectedBlock.getDFABlock()); callback.onImageExported(exportCurrentGraph(panel.getMxGraph(), scale, selectedBlock, state)); callback.setExportStep(step); } callback.done(); } BufferedImage exportCurrentGraph(mxGraph graph, double scale, UIAbstractBlock selectedBlock, BlockState<? extends LatticeElement> state); void batchExportAsync(DFAExecution<? extends LatticeElement> dfa, double scale, boolean includeLineSteps, GraphExportCallback callback); } | @Test public void shouldPerformBatchExport() throws InterruptedException { String code = "public class shouldPerformBatchExportClass { int test(int a) { " + " if (a < 10) { " + " a = 20; " + " } " + " return a*2; " + " } }"; CodeProcessor codeProcessor = new CodeProcessor(code); GraphBuilder builder = new GraphBuilder(codeProcessor.getPath(), codeProcessor.getClassName()); SimpleBlockGraph blockGraph = builder.buildGraph("int test(int)"); WorklistManager manager = WorklistManager.getInstance(); final DFAExecution<DummyElement> dfa = new DFAExecution<DummyElement>(new DummyFactory(), manager.getWorklist(manager.getWorklistNames().get(0), blockGraph), blockGraph, new DFAPrecalcController()); dfa.setCurrentBlockStep(0); final TestGraphExportCallback testCallback = new TestGraphExportCallback(); new Thread(new Runnable() { @Override public void run() { graphExporter.batchExportAsync(dfa, 1.0, true, testCallback); } }).start(); synchronized (lock) { lock.wait(); } ArrayList<BufferedImage> imageList = testCallback.images; assertEquals(dfa.getTotalElementarySteps() + 1, testCallback.maxStep); assertEquals(dfa.getTotalElementarySteps(), imageList.size()); assertTrue(TestUtils.deltaEqual(603, imageList.get(0).getWidth(), 60)); assertTrue(TestUtils.deltaEqual(299, imageList.get(0).getHeight(), 60)); for (int i = 0; i < dfa.getTotalElementarySteps(); i++) { assertEquals(i, (int) testCallback.steps.get(i)); } final TestGraphExportCallback blockTestCallback = new TestGraphExportCallback(); new Thread(new Runnable() { @Override public void run() { graphExporter.batchExportAsync(dfa, 3.0, false, blockTestCallback); } }).start(); synchronized (lock) { lock.wait(); } ArrayList<BufferedImage> blockImageList = blockTestCallback.images; assertEquals(dfa.getTotalBlockSteps() + 1, blockTestCallback.maxStep); assertEquals(dfa.getTotalBlockSteps(), blockImageList.size()); assertTrue(TestUtils.deltaEqual(1729, blockImageList.get(0).getWidth(), 180)); assertTrue(TestUtils.deltaEqual(895, blockImageList.get(0).getHeight(), 180)); for (int i = 0; i < dfa.getTotalBlockSteps(); i++) { assertEquals(i, (int) blockTestCallback.steps.get(i)); } }
@Test public void graphBatchExportThreadShouldWork() throws InterruptedException { new GraphBatchExportThread(mockExporter, dfa, 3.0, false, null).run(); verify(mockExporter, times(1)).batchExportAsync(dfa, 3.0, false, null); } |
GraphUIController { public void refresh() { if (dfa == null) { throw new IllegalStateException("Graph has not been built using start() yet."); } panel.renderGraph(dfa); if (!panel.isJumpToActionEnabled()) { updateStatePanel(); } } GraphUIController(VisualGraphPanel panel); void start(final DFAExecution<? extends LatticeElement> dfa); void setStatePanel(StatePanelOpen statePanel); void refresh(); void stop(); } | @Test(expected = IllegalStateException.class) public void refreshShouldNotBePossibleBeforeStart() { controller.refresh(); } |
GraphUIController { public void start(final DFAExecution<? extends LatticeElement> dfa) { if (this.dfa != null) { throw new IllegalStateException("Visual graph was already built."); } this.dfa = dfa; ControlFlowGraph dfaGraph = dfa.getCFG(); List<BasicBlock> dfaBasicBlocks = dfaGraph.getBasicBlocks(); Map<BasicBlock, UIBasicBlock> mappedBasicBlocks = new HashMap<>(); final List<UIAbstractBlock> uiBlocks = new ArrayList<>(); final Map<mxCell, UIAbstractBlock> mxCellMap = new HashMap<>(); for (int i = 0; i < dfaBasicBlocks.size(); i++) { BasicBlock dfaBasicBlock = dfaBasicBlocks.get(i); UIBasicBlock basicBlock = new UIBasicBlock(graph, dfaBasicBlock, dfa); uiBlocks.add(basicBlock); basicBlock.setBlockNumber(i); List<ElementaryBlock> elementaryBlocks = dfaBasicBlock.getElementaryBlocks(); if (elementaryBlocks.size() != 0) { List<UILineBlock> lineBlocks = new ArrayList<>(); ElementaryBlock firstElementaryBlock = elementaryBlocks.get(0); UILineBlock firstLineBlock = new UILineBlock(firstElementaryBlock, panel.getGraphComponent(), graph, basicBlock); lineBlocks.add(firstLineBlock); uiBlocks.add(firstLineBlock); firstLineBlock.setBlockNumber(0); basicBlock.insertLineBlock(lineBlocks.get(0)); mappedAbstractBlocks.put(firstElementaryBlock, firstLineBlock); for (int n = 1; n < elementaryBlocks.size(); n++) { ElementaryBlock currentElementaryBlock = elementaryBlocks.get(n); UILineBlock newLineBlock = new UILineBlock(currentElementaryBlock, panel.getGraphComponent(), graph, basicBlock, lineBlocks.get(n - 1)); lineBlocks.add(newLineBlock); uiBlocks.add(newLineBlock); newLineBlock.setBlockNumber(n); basicBlock.insertLineBlock(lineBlocks.get(n)); mappedAbstractBlocks.put(currentElementaryBlock, newLineBlock); } } mappedAbstractBlocks.put(dfaBasicBlock, basicBlock); mappedBasicBlocks.put(dfaBasicBlock, basicBlock); panel.insertBasicBlock(basicBlock); } panel.setBlockMap(mappedAbstractBlocks); for (BasicBlock dfaBasicBlock : dfaBasicBlocks) { UIBasicBlock currentBlock = mappedBasicBlocks.get(dfaBasicBlock); List<UIBasicBlock> successors = new ArrayList<>(); for (BasicBlock dfaSuccessor : dfaGraph.getSuccessors(dfaBasicBlock)) { successors.add(mappedBasicBlocks.get(dfaSuccessor)); } for (UIBasicBlock successor : successors) { panel.insertEdge(new UIEdge(graph, currentBlock, successor)); } } panel.renderGraph(dfa); for (UIAbstractBlock block : uiBlocks) { mxCellMap.put(block.getMxCell(), block); } graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxEventSource.mxIEventListener() { @Override public void invoke(Object o, mxEventObject mxEventObject) { @SuppressWarnings("unchecked") ArrayList<mxCell> selectedCells = (ArrayList<mxCell>) mxEventObject.getProperty("removed"); if (selectedCells != null && selectedCells.size() > 0) { mxCell selectedCell = selectedCells.get(0); panel.setSelectedBlock(mxCellMap.get(selectedCell)); } else { panel.setSelectedBlock(null); } updateStatePanel(); } }); } GraphUIController(VisualGraphPanel panel); void start(final DFAExecution<? extends LatticeElement> dfa); void setStatePanel(StatePanelOpen statePanel); void refresh(); void stop(); } | @Test(expected = IllegalStateException.class) public void startShouldNotBePossibleTwice() { CodeProcessor codeProcessor = new CodeProcessor("void emptyInside() {}"); GraphBuilder builder = new GraphBuilder(codeProcessor.getPath(), codeProcessor.getClassName()); SimpleBlockGraph blockGraph = builder.buildGraph("void emptyInside()"); DFAExecution<DummyElement> dfa = new DFAExecution<>(new DummyFactory(), new NaiveWorklist(), blockGraph, new DFAPrecalcController()); controller.start(dfa); controller.start(dfa); } |
Tracing extends org.apache.cassandra.tracing.Tracing { Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) { ByteBuffer b3 = payload != null ? payload.get("b3") : null; if (b3 == null) return tracer.nextSpan(); TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3)); if (extracted == null) return tracer.nextSpan(); return tracer.nextSpan(extracted); } Tracing(brave.Tracing tracing); Tracing(); @Override final TraceState begin(
String request, InetAddress client, Map<String, String> parameters); @Override final void trace(ByteBuffer sessionId, String message, int ttl); } | @Test public void spanFromPayload_startsTraceOnNullPayload() { assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), null)) .isNotNull(); }
@Test public void spanFromPayload_startsTraceOnAbsentB3SingleEntry() { assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), Collections.emptyMap())) .isNotNull(); }
@Test public void spanFromPayload_resumesTraceOnB3SingleEntry() { assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), Collections.singletonMap("b3", ByteBuffer.wrap(new byte[] {'0'})))) .extracting(b -> b.isNoop()) .isEqualTo(Boolean.TRUE); } |
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new DirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); } | @Test public void testConnect() throws Exception { directedGraph.connect("F", "G", 1d); assertEquals("F", directedGraph.incomingEdgesOf("G").iterator().next().getVertex1()); } |
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean add(V v){ if(!connected.containsKey(v)){ connected.put(v, new LinkedHashSet<GraphEdge<V, E>>()); return true; } return false; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); } | @Test public void testEdgesWithDisconnectedVertices() throws Exception { graph.add("X"); graph.add("Y"); testGraphEdges(); }
@Test public void testAdd() throws Exception { graph.add("X"); Set vertices = Sets.newHashSet(graph.vertices()); assertTrue(vertices.contains("X")); assertTrue(vertices.size()==size+1); } |
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public boolean remove(V v){ Set<GraphEdge<V, E>> edges = this.connected.get(v); if (edges == null) return false; for(Iterator<GraphEdge<V,E>> it = edges.iterator(); it.hasNext(); ){ GraphEdge<V,E> edge = it.next(); it.remove(); V v2 = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); for(Iterator<GraphEdge<V,E>> it2 = this.connected.get(v2).iterator(); it2.hasNext();){ GraphEdge<V,E> edge2 = it2.next(); if (edge2.getVertex1().equals(v) || edge2.getVertex2().equals(v)){ it2.remove(); } } } this.connected.remove(v); return true; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); } | @Test public void testRemove() throws Exception { graph.remove("v1"); assertFalse(Sets.newHashSet(graph.vertices()).contains("v1")); } |
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public GraphEdge<V,E> connect(V v1, V v2, E value){ if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); } | @Test public void testConnect() throws Exception { graph.add("X"); graph.add("Y"); graph.connect("X","Y",1.0d); assertTrue(Sets.newHashSet(graph.vertices()).contains("X")); assertTrue(Sets.newHashSet(graph.vertices()).contains("Y")); } |
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<V> vertices() { return connected.keySet(); } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); } | @Test public void testVertices() throws Exception { Set vertices = Sets.newHashSet(graph.vertices()); assertEquals(size, vertices.size()); } |
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { Set<GraphEdge<V, E>> set = connected.get(vertex); if (set == null) set = Collections.emptySet(); return set; } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); } | @Test public void testEdgesOf() throws Exception { Set edges = Sets.newHashSet(graph.edgesOf("v1")); assertEquals(size-1, edges.size()); } |
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex1().equals(vertex); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); } | @Test public void testOutgoingEdgesOf() throws Exception { for(int i=0; i<size; i++) { Set edges = Sets.newHashSet(graph.outgoingEdgesOf("v"+i)); assertEquals(size-(i+1), edges.size()); } } |
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex) { return F.filter(edgesOf(vertex), new Function<GraphEdge<V, E>, Boolean>() { @Override public Boolean apply(GraphEdge<V, E> edge) { return edge.getVertex2().equals(vertex); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); } | @Test public void testIncomingEdgesOf() throws Exception { for(int i=0; i<size; i++) { Set edges = Sets.newHashSet(graph.incomingEdgesOf("v"+i)); assertEquals(i, edges.size()); } } |
HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph<V, E> implements HipsterMutableGraph<V, E>, HipsterDirectedGraph<V, E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); } @Override GraphEdge<V, E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(final V vertex); @Override Iterable<GraphEdge<V, E>> edges(); static HashBasedHipsterDirectedGraph<V, E> create(); } | @Test public void testEdges() throws Exception { Set edges = Sets.newHashSet(graph.edges()); assertEquals(size*(size-1)/2, edges.size()); } |
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) { return graphTable.row(vertex).values(); } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); } | @Test public void testOutgoingEdgesOf() throws Exception { Set<DirectedEdge<String, Double>> expected = new HashSet<DirectedEdge<String, Double>>(); expected.add(new DirectedEdge<String, Double>("B", "C", 5d)); expected.add(new DirectedEdge<String, Double>("B", "D", 10d)); assertEquals(expected, Sets.newHashSet(directedGraph.outgoingEdgesOf("B"))); } |
HashTableHipsterDirectedGraph extends HashTableHipsterGraph<V,E> implements HipsterDirectedGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex) { return graphTable.column(vertex).values(); } @Override GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex); @Override Iterable<GraphEdge<V, E>> incomingEdgesOf(V vertex); static HashTableHipsterDirectedGraph<V, E> create(); } | @Test public void testIncomingEdgesOf() throws Exception { Set<DirectedEdge<String, Double>> expected = new HashSet<DirectedEdge<String, Double>>(); expected.add(new DirectedEdge<String, Double>("B", "C", 5d)); expected.add(new DirectedEdge<String, Double>("A", "C", 2d)); assertEquals(expected, Sets.newHashSet(directedGraph.incomingEdgesOf("C"))); } |
HashTableHipsterGraph implements HipsterGraph<V,E> { public void add(V v){ if (!graphTable.containsColumn(v) && !graphTable.containsRow(v)){ disconnected.add(v); } } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); } | @Test public void testAdd() throws Exception { graph.add("G"); assertTrue(Sets.newHashSet(graph.vertices()).contains("G")); } |
HashTableHipsterGraph implements HipsterGraph<V,E> { public void remove(V v){ for(GraphEdge<V,E> edge : edgesOf(v)){ V connectedVertex = edge.getVertex1().equals(v) ? edge.getVertex2() : edge.getVertex1(); if (!greaterThan(1, edgesOf(connectedVertex))){ disconnected.add(connectedVertex); } } if (graphTable.containsRow(v)){ graphTable.row(v).clear(); } if (graphTable.containsColumn(v)){ graphTable.column(v).clear(); } disconnected.remove(v); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); } | @Test public void testRemove() throws Exception { graph.remove("B"); assertFalse(Sets.newHashSet(graph.vertices()).contains("B")); } |
HashTableHipsterGraph implements HipsterGraph<V,E> { public GraphEdge<V,E> connect(V v1, V v2, E value){ Preconditions.checkArgument(v1 != null && v2 != null, "Vertices cannot be null"); GraphEdge<V,E> edge = new UndirectedEdge<V, E>(v1, v2, value); graphTable.put(v1, v2, edge); graphTable.put(v2, v1, edge); disconnected.remove(v1); disconnected.remove(v2); return edge; } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); } | @Test public void testConnect() throws Exception { graph.connect("X","Y",1.0d); assertTrue(Sets.newHashSet(graph.vertices()).contains("X")); assertTrue(Sets.newHashSet(graph.vertices()).contains("Y")); } |
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return graphTable.values(); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); } | @Test public void testEdges() throws Exception { Set<GraphEdge<String,Double>> expected = new HashSet<GraphEdge<String, Double>>(); expected.add(new UndirectedEdge<String, Double>("A","B",4d)); expected.add(new UndirectedEdge<String, Double>("A","C",2d)); expected.add(new UndirectedEdge<String, Double>("B","C",5d)); expected.add(new UndirectedEdge<String, Double>("B","D",10d)); expected.add(new UndirectedEdge<String, Double>("C","E",3d)); expected.add(new UndirectedEdge<String, Double>("D","F",11d)); expected.add(new UndirectedEdge<String, Double>("E","D",4d)); assertEquals(expected, Sets.newHashSet(graph.edges())); } |
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<V> vertices() { return Sets.union(Sets.union(graphTable.rowKeySet(), graphTable.columnKeySet()), disconnected); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); } | @Test public void testVertices() throws Exception { Set<String> expected = Sets.newHashSet("A","B","C","D","E","F"); assertEquals(expected, graph.vertices()); } |
HashTableHipsterGraph implements HipsterGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edgesOf(V vertex) { return Sets.union(Sets.newHashSet(graphTable.row(vertex).values()), Sets.newHashSet(graphTable.column(vertex).values())); } void add(V v); void remove(V v); void remove(V v, GraphEdge<V,E> edge); GraphEdge<V,E> connect(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); static HashTableHipsterGraph<V, E> create(); } | @Test public void testEdgesOf() throws Exception { Set<GraphEdge<String,Double>> expected = new HashSet<GraphEdge<String, Double>>(); expected.add(new UndirectedEdge<String, Double>("B","D",10d)); expected.add(new UndirectedEdge<String, Double>("A","B",4d)); expected.add(new UndirectedEdge<String, Double>("B","C",5d)); assertEquals(expected, graph.edgesOf("B")); } |
HashBasedHipsterGraph implements HipsterMutableGraph<V,E> { @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); } HashBasedHipsterGraph(); @Override boolean add(V v); @Override Set<V> add(V... vertices); @Override boolean remove(V v); @Override Set<V> remove(V... vertices); @Override GraphEdge<V,E> connect(V v1, V v2, E value); GraphEdge<V,E> buildEdge(V v1, V v2, E value); @Override Iterable<GraphEdge<V, E>> edges(); @Override Iterable<V> vertices(); @Override Iterable<GraphEdge<V, E>> edgesOf(V vertex); HashMap<V, Set<GraphEdge<V, E>>> getConnected(); void setConnected(HashMap<V, Set<GraphEdge<V, E>>> connected); static HashBasedHipsterGraph<V, E> create(); } | @Test public void testEdges() throws Exception { testGraphEdges(); } |
CallArgumentsToByteArray { public byte[] getGasPrice() { byte[] gasPrice = new byte[] {0}; if (args.gasPrice != null && args.gasPrice.length() != 0) { gasPrice = stringHexToByteArray(args.gasPrice); } return gasPrice; } CallArgumentsToByteArray(Web3.CallArguments args); byte[] getGasPrice(); byte[] getGasLimit(); byte[] getToAddress(); byte[] getValue(); byte[] getData(); RskAddress getFromAddress(); } | @Test public void getGasPriceWhenValueIsNull() throws Exception { Web3.CallArguments args = new Web3.CallArguments(); CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args); Assert.assertArrayEquals(new byte[] {0}, byteArrayArgs.getGasPrice()); }
@Test public void getGasPriceWhenValueIsEmpty() throws Exception { Web3.CallArguments args = new Web3.CallArguments(); args.gasPrice = ""; CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args); Assert.assertArrayEquals(new byte[] {0}, byteArrayArgs.getGasPrice()); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.