本文整理了Java中java.util.TreeSet.comparator()
方法的一些代码示例,展示了TreeSet.comparator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeSet.comparator()
方法的具体详情如下:
包路径:java.util.TreeSet
类名称:TreeSet
方法名:comparator
[英]Returns the comparator used to compare elements in this TreeSet.
[中]返回用于比较此树集中元素的比较器。
代码示例来源:origin: goldmansachs/gs-collections
public Comparator<? super T> comparator()
{
return this.treeSet.comparator();
}
代码示例来源:origin: eclipse/eclipse-collections
@Override
public Comparator<? super T> comparator()
{
return this.treeSet.comparator();
}
代码示例来源:origin: eclipse/eclipse-collections
@Override
public Comparator<? super T> comparator()
{
return this.treeSet.comparator();
}
代码示例来源:origin: goldmansachs/gs-collections
public TreeSortedSet<T> newEmpty()
{
return TreeSortedSet.newSet(this.treeSet.comparator());
}
代码示例来源:origin: eclipse/eclipse-collections
@Override
public TreeSortedSet<T> newEmpty()
{
return TreeSortedSet.newSet(this.treeSet.comparator());
}
代码示例来源:origin: eclipse/eclipse-collections
@Override
public TreeSortedSet<T> newEmpty()
{
return TreeSortedSet.newSet(this.treeSet.comparator());
}
代码示例来源:origin: apache/ignite
/**
* 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());
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* @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;
}
}
}
}
代码示例来源:origin: apache/ignite
/**
* 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;
}
代码示例来源:origin: apache/ignite
/** {@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);
}
代码示例来源:origin: apache/geode
writeObject(set.comparator(), out);
for (Object e : set) {
writeObject(e, out);
代码示例来源:origin: apache/geode
/**
* 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());
}
代码示例来源:origin: apache/ignite
/**
* 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();
}
代码示例来源:origin: apache/ignite
assert resSet.comparator() instanceof TestKeyComparator;
else
assertNull(resSet.comparator());
代码示例来源:origin: com.google.gwt/gwt-servlet
public static void serialize(SerializationStreamWriter streamWriter,
TreeSet instance) throws SerializationException {
streamWriter.writeObject(instance.comparator());
Collection_CustomFieldSerializerBase.serialize(streamWriter, instance);
}
代码示例来源:origin: jpox/jpox
/**
* Accessor for the comparator.
* @return The comparator
*/
public Comparator comparator()
{
return delegate.comparator();
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
public void reindex() {
TreeSet<Statement> treeSet = new TreeSet<Statement>(tree.comparator());
treeSet.addAll(tree);
tree = treeSet;
}
代码示例来源:origin: com.esotericsoftware/kryo
public void write (Kryo kryo, Output output, Collection collection) {
TreeSet treeSet = (TreeSet)collection;
kryo.writeClassAndObject(output, treeSet.comparator());
super.write(kryo, output, collection);
}
代码示例来源:origin: com.esotericsoftware.kryo/kryo
public void write (Kryo kryo, Output output, Collection collection) {
TreeSet treeSet = (TreeSet)collection;
kryo.writeClassAndObject(output, treeSet.comparator());
super.write(kryo, output, collection);
}
代码示例来源:origin: net.wetheinter/gwt-user
public static void serialize(SerializationStreamWriter streamWriter,
TreeSet instance) throws SerializationException {
streamWriter.writeObject(instance.comparator());
Collection_CustomFieldSerializerBase.serialize(streamWriter, instance);
}
内容来源于网络,如有侵权,请联系作者删除!