Java, "Heterogeneous Container".
, , , Heterogenic Container - , .
, .
public class MyListTreeSet<E> extends AbstractList<E>
{
private Class<E> type;
private TreeSet<E> set;
public MyListTreeSet( Comparator<? super E> comp, Class<E> type )
{
this.type = type;
set = new TreeSet<>( comp );
}
, contains(), , .
@Override
public boolean contains( Object o )
{
if( !type.isInstance( o ) ) return false;
E e = type.cast( o );
return set.contains( e );
}
, .
EDIT:
, , (). , , , . TreeCollection - , , TreeCollection.
TreeCollection<Integer> c = new NewTreeCollection<>(
new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1.compareTo(o2);
}
}, Integer.class );
NewTreeCollection , I, , TreeCollection TreeSet, .
public class NewTreeCollection<E> extends TreeCollection<E>
{
private Class<E> type;
private TreeSet<E> set;
public NewTreeCollection( Comparator<? super E> comp, Class<E> type )
{
this.type = type;
set = new TreeSet<>( comp );
}
@Override
public boolean contains( Object o )
{
if( !type.isInstance( o ) ) return false;
E e = type.cast( o );
return set.contains( e );
}
}