@Test public void testCompare() { TestConstant a = pool.valueOf("a_alpha"); TestConstant b = pool.valueOf("b_beta"); TestConstant c = pool.valueOf("c_gamma"); TestConstant d = pool.valueOf("d_delta"); TestConstant e = pool.valueOf("e_epsilon"); Set<TestConstant> set = new TreeSet<TestConstant>(); set.add(b); set.add(c); set.add(e); set.add(d); set.add(a); TestConstant[] array = set.toArray(new TestConstant[5]); assertThat(array.length, is(5)); Arrays.sort(array, new Comparator<TestConstant>() { @Override public int compare(TestConstant o1, TestConstant o2) { return o1.name().compareTo(o2.name()); } }); assertThat(array[0], is(sameInstance(a))); assertThat(array[1], is(sameInstance(b))); assertThat(array[2], is(sameInstance(c))); assertThat(array[3], is(sameInstance(d))); assertThat(array[4], is(sameInstance(e))); }
public T valueOf(Class<?> firstNameComponent, String secondNameComponent) { if (firstNameComponent == null) { throw new NullPointerException("firstNameComponent"); } if (secondNameComponent == null) { throw new NullPointerException("secondNameComponent"); } return valueOf(firstNameComponent.getName() + '#' + secondNameComponent); }
ConstantPool { public T valueOf(Class<?> firstNameComponent, String secondNameComponent) { if (firstNameComponent == null) { throw new NullPointerException("firstNameComponent"); } if (secondNameComponent == null) { throw new NullPointerException("secondNameComponent"); } return valueOf(firstNameComponent.getName() + '#' + secondNameComponent); } }
ConstantPool { public T valueOf(Class<?> firstNameComponent, String secondNameComponent) { if (firstNameComponent == null) { throw new NullPointerException("firstNameComponent"); } if (secondNameComponent == null) { throw new NullPointerException("secondNameComponent"); } return valueOf(firstNameComponent.getName() + '#' + secondNameComponent); }  }
ConstantPool { public T valueOf(Class<?> firstNameComponent, String secondNameComponent) { if (firstNameComponent == null) { throw new NullPointerException("firstNameComponent"); } if (secondNameComponent == null) { throw new NullPointerException("secondNameComponent"); } return valueOf(firstNameComponent.getName() + '#' + secondNameComponent); }  T valueOf(Class<?> firstNameComponent, String secondNameComponent); T valueOf(String name); boolean exists(String name); T newInstance(String name); @Deprecated final int nextId(); }
ConstantPool { public T valueOf(Class<?> firstNameComponent, String secondNameComponent) { if (firstNameComponent == null) { throw new NullPointerException("firstNameComponent"); } if (secondNameComponent == null) { throw new NullPointerException("secondNameComponent"); } return valueOf(firstNameComponent.getName() + '#' + secondNameComponent); }  T valueOf(Class<?> firstNameComponent, String secondNameComponent); T valueOf(String name); boolean exists(String name); T newInstance(String name); @Deprecated final int nextId();  }