public Comparator<? super T> comparator() { return this.treeSet.comparator(); }
@Override public Comparator<? super T> comparator() { return this.treeSet.comparator(); }
@Override public Comparator<? super T> comparator() { return this.treeSet.comparator(); }
public TreeSortedSet<T> newEmpty() { return TreeSortedSet.newSet(this.treeSet.comparator()); }
@Override public TreeSortedSet<T> newEmpty() { return TreeSortedSet.newSet(this.treeSet.comparator()); }
@Override public TreeSortedSet<T> newEmpty() { return TreeSortedSet.newSet(this.treeSet.comparator()); }
/** * Attempts to create a new set of the same type as {@code set} has. Otherwise returns new {@code HashSet} * instance. * * @param set Original set. * @return New set. */ public static <V> Set<V> newSet(Set<V> set) { if (set instanceof LinkedHashSet) return U.newLinkedHashSet(set.size()); else if (set instanceof TreeSet) return new TreeSet<>(((TreeSet<Object>)set).comparator()); else if (set instanceof ConcurrentSkipListSet) return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)set).comparator()); return U.newHashSet(set.size()); }
/** * @return true if element was successfully added, false otherwise * */ @Override public boolean add(E e) { if (remainingCapacity == 0 && size() == 0) { return false; } else if (remainingCapacity > 0) { // still has room, add element boolean added = super.add(e); if (added) { remainingCapacity--; } return added; } else { // compare new element with least element in queue int compared = super.comparator().compare(e, this.first()); if (compared == 1) { // new element is larger, replace old element pollFirst(); super.add(e); return true; } else { // new element is smaller, discard return false; } } } }
/** * Attempts to create a new collection of the same known type. Will return null if collection type is unknown. * * @param col Collection. * @return New empty collection. */ public static <V> Collection<V> newKnownCollection(Object col) { Class<?> cls = col == null ? null : col.getClass(); if (cls == HashSet.class) return U.newHashSet(((Collection)col).size()); else if (cls == LinkedHashSet.class) return U.newLinkedHashSet(((Collection)col).size()); else if (!wrapTrees() && cls == TreeSet.class) return new TreeSet<>(((TreeSet<Object>)col).comparator()); else if (cls == ConcurrentSkipListSet.class) return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)col).comparator()); else if (cls == ArrayList.class) return new ArrayList<>(((Collection)col).size()); else if (cls == LinkedList.class) return new LinkedList<>(); else if (cls == SINGLETON_LIST_CLS) return new MutableSingletonList<>(); return null; }
/** {@inheritDoc} */ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException { BinaryRawWriter rawWriter = writer.rawWriter(); rawWriter.writeObject(set.comparator()); int size = set.size(); rawWriter.writeInt(size); for (Object val : set) rawWriter.writeObject(val); }
writeObject(set.comparator(), out); for (Object e : set) { writeObject(e, out);
/** * Tests data serializing an {@link TreeSet} */ @Test public void testTreeSetWithComparator() throws Exception { Random random = getRandom(); int size = random.nextInt(50); TreeSet set = new TreeSet(new MyComparator(size)); for (int i = 0; i < size; i++) { set.add(new Long(random.nextLong())); } DataOutputStream out = getDataOutput(); DataSerializer.writeTreeSet(new TreeSet(new MyComparator(0)), out); DataSerializer.writeTreeSet(set, out); out.flush(); DataInput in = getDataInput(); TreeSet emptySet = DataSerializer.readTreeSet(in); assertEquals(new TreeSet(new MyComparator(0)), emptySet); assertEquals(new MyComparator(0), emptySet.comparator()); TreeSet set2 = DataSerializer.readTreeSet(in); assertEquals(set, set2); assertEquals(set.comparator(), set2.comparator()); }
/** * Check {@code TreeSet} data structure. * * @param useBinary Whether to go through binary mode. * @param useComparator Whether comparator should be used. * @throws Exception If failed. */ @SuppressWarnings("unchecked") private void checkTreeSetAsValue(boolean useBinary, boolean useComparator) throws Exception { // Populate set. TreeSet<TestKey> set; set = testSet(useComparator); // Put and get value from cache. cache().put(KEY, set); TreeSet<TestKey> resSet; if (useBinary) { BinaryObject resMapBinary = (BinaryObject)cache().withKeepBinary().get(KEY); resSet = resMapBinary.deserialize(); } else resSet = (TreeSet<TestKey>)cache().get(KEY); // Ensure content is correct. if (useComparator) assert resSet.comparator() instanceof TestKeyComparator; else assertNull(resSet.comparator()); assertEquals(set, resSet); cache().clear(); }
assert resSet.comparator() instanceof TestKeyComparator; else assertNull(resSet.comparator());
public static void serialize(SerializationStreamWriter streamWriter, TreeSet instance) throws SerializationException { streamWriter.writeObject(instance.comparator()); Collection_CustomFieldSerializerBase.serialize(streamWriter, instance); }
/** * Accessor for the comparator. * @return The comparator */ public Comparator comparator() { return delegate.comparator(); }
public void reindex() { TreeSet<Statement> treeSet = new TreeSet<Statement>(tree.comparator()); treeSet.addAll(tree); tree = treeSet; }
public void write (Kryo kryo, Output output, Collection collection) { TreeSet treeSet = (TreeSet)collection; kryo.writeClassAndObject(output, treeSet.comparator()); super.write(kryo, output, collection); }
public void write (Kryo kryo, Output output, Collection collection) { TreeSet treeSet = (TreeSet)collection; kryo.writeClassAndObject(output, treeSet.comparator()); super.write(kryo, output, collection); }
public static void serialize(SerializationStreamWriter streamWriter, TreeSet instance) throws SerializationException { streamWriter.writeObject(instance.comparator()); Collection_CustomFieldSerializerBase.serialize(streamWriter, instance); }