Number160 extends Number implements Comparable<Number160> { public String toString(final boolean removeLeadingZero) { boolean removeZero = removeLeadingZero; final StringBuilder sb = new StringBuilder("0x"); for (int i = 0; i < INT_ARRAY_SIZE; i++) { toHex(val[i], removeZero, sb); if (removeZero && val[i] != 0) { removeZero = false; } } return sb.toString(); } Number160();  Number160(final int... val);  Number160(final String val);  Number160(final int val);  Number160(final long val);  Number160(final byte[] val);  Number160(final byte[] val, final int offset, final int length);  Number160(final Random random);  Number160(final long timestamp, Number160 number96); long timestamp(); Number160 number96(); Number160 xor(final Number160 key); int[] toIntArray(); int toByteArray(final byte[] me, final int offset); byte[] toByteArray(); String toString(final boolean removeLeadingZero); boolean isZero(); int bitLength(); @Override String toString(); @Override double doubleValue(); @Override float floatValue(); @Override int intValue(); @Override long longValue(); @Override int compareTo(final Number160 o); @Override boolean equals(final Object obj); @Override int hashCode(); static Number160 createHash(final int integerValue); static Number160 createHash(final long longValue); static Number160 createHash(final String string); static final int BITS; static final int INT_ARRAY_SIZE; static final int BYTE_ARRAY_SIZE; static final int CHARS_PER_INT; static final Number160 ZERO; static final Number160 ONE; static final Number160 MAX_VALUE; }
@Test public void testFromIntArray() { int[] tmp = new int[] { 1, 2, 3, 4, 5 }; Number160 ki2 = new Number160(tmp); Assert.assertEquals("0x0000000100000002000000030000000400000005", ki2.toString(false)); tmp = new int[] { -1, -1, -1, -1, -1 }; ki2 = new Number160(tmp); Assert.assertEquals("0xffffffffffffffffffffffffffffffffffffffff", ki2.toString(false)); ki2 = new Number160(new int[] { 1, 2 }); Assert.assertEquals("0x100000002", ki2.toString()); ki2 = new Number160(new int[] { 1 }); Assert.assertEquals("0x1", ki2.toString()); ki2 = new Number160(new int[] { 1, 1, 1, 1, 1 }); Assert.assertEquals("0x0000000100000001000000010000000100000001", ki2.toString(false)); }
@Test public void testFromString() { Number160 ki2 = new Number160("0x9"); Assert.assertEquals("0x9", ki2.toString(true)); ki2 = new Number160("0x22"); Assert.assertEquals("0x22", ki2.toString(true)); ki2 = new Number160("0x0000000000000002000000030000000400000005"); Assert.assertEquals("0x2000000030000000400000005", ki2.toString(true)); Assert.assertEquals("0x0000000000000002000000030000000400000005", ki2.toString(false)); ki2 = new Number160("0x0400000005"); Assert.assertEquals("0x400000005", ki2.toString(true)); ki2 = new Number160("0x0000000000000002000000000000000000000000"); Assert.assertEquals("0x2000000000000000000000000", ki2.toString(true)); Assert.assertEquals("0x0000000000000002000000000000000000000000", ki2.toString(false)); ki2 = new Number160("0x1000000000000000000000000000000000000000"); Assert.assertEquals("0x1000000000000000000000000000000000000000", ki2.toString(true)); ki2 = new Number160("0x100000000000000000000"); Assert.assertEquals("0x100000000000000000000", ki2.toString(true)); }
@Test public void testFromInt() { Number160 ki2 = new Number160(0x2c); Assert.assertEquals("0x2c", ki2.toString()); }
@Test public void testPerformance2() { ConcurrentSkipListSet<BigInteger> test1 = new ConcurrentSkipListSet<BigInteger>(); ConcurrentSkipListSet<Number160> test2 = new ConcurrentSkipListSet<Number160>(); int runs = 10000; BigInteger bi1[] = new BigInteger[runs]; for (int i = 0; i < runs; i++) { bi1[i] = new BigInteger(160, rnd); if (bi1[i].toString(16).length() != 40) i--; } Number160 ki1[] = new Number160[runs]; for (int i = 0; i < runs; i++) ki1[i] = new Number160("0x" + bi1[i].toString(16)); long start = System.currentTimeMillis(); for (int j = 0; j < 500; j++) { test1.clear(); for (int i = 0; i < runs; i++) test1.add(bi1[i]); } System.err.println("BigInteger time " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (int j = 0; j < 500; j++) { test2.clear(); for (int i = 0; i < runs; i++) test2.add(ki1[i]); } System.err.println("Key time " + (System.currentTimeMillis() - start)); Assert.assertEquals("0x" + test1.first().toString(16), test2.first().toString()); }
@Test public void testLong() { Number160 n1 = new Number160(1); Number160 n2 = new Number160(1L); Assert.assertEquals(n1, n2); n2 = new Number160(Long.MAX_VALUE); Assert.assertEquals("0x7FFFFFFFFFFFFFFF".toLowerCase(), n2.toString()); }