本文整理汇总了Java中java.util.NavigableSet.subSet方法的典型用法代码示例。如果您正苦于以下问题:Java NavigableSet.subSet方法的具体用法?Java NavigableSet.subSet怎么用?Java NavigableSet.subSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.NavigableSet
的用法示例。
在下文中一共展示了NavigableSet.subSet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subSet
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* Returns a view of the portion of {@code set} whose elements are contained by {@code range}.
*
* <p>This method delegates to the appropriate methods of {@link NavigableSet} (namely
* {@link NavigableSet#subSet(Object, boolean, Object, boolean) subSet()},
* {@link NavigableSet#tailSet(Object, boolean) tailSet()}, and
* {@link NavigableSet#headSet(Object, boolean) headSet()}) to actually construct the view.
* Consult these methods for a full description of the returned view's behavior.
*
* <p><b>Warning:</b> {@code Range}s always represent a range of values using the values' natural
* ordering. {@code NavigableSet} on the other hand can specify a custom ordering via a
* {@link Comparator}, which can violate the natural ordering. Using this method (or in general
* using {@code Range}) with unnaturally-ordered sets can lead to unexpected and undefined
* behavior.
*
* @since 20.0
*/
@Beta
@GwtIncompatible // NavigableSet
public static <K extends Comparable<? super K>> NavigableSet<K> subSet(
NavigableSet<K> set, Range<K> range) {
if (set.comparator() != null
&& set.comparator() != Ordering.natural()
&& range.hasLowerBound()
&& range.hasUpperBound()) {
checkArgument(
set.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0,
"set is using a custom comparator which is inconsistent with the natural ordering.");
}
if (range.hasLowerBound() && range.hasUpperBound()) {
return set.subSet(
range.lowerEndpoint(),
range.lowerBoundType() == BoundType.CLOSED,
range.upperEndpoint(),
range.upperBoundType() == BoundType.CLOSED);
} else if (range.hasLowerBound()) {
return set.tailSet(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
} else if (range.hasUpperBound()) {
return set.headSet(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
}
return checkNotNull(set);
}
示例2: createSubSet
import java.util.NavigableSet; //导入方法依赖的package包/类
@Override
NavigableSet<E> createSubSet(SortedSet<E> sortedSet, E firstExclusive, E lastExclusive) {
NavigableSet<E> set = (NavigableSet<E>) sortedSet;
if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
return set.headSet(lastInclusive, true);
} else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
return set.tailSet(firstExclusive, false);
} else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
return set.subSet(firstExclusive, false, lastExclusive, false);
} else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
return set.subSet(firstExclusive, false, lastInclusive, true);
} else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
return set.subSet(firstInclusive, true, lastInclusive, true);
} else {
return (NavigableSet<E>) super.createSubSet(set, firstExclusive, lastExclusive);
}
}
示例3: testSubSetRanges
import java.util.NavigableSet; //导入方法依赖的package包/类
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testSubSetRanges(String description, NavigableSet navigableSet) {
Object first = isDescending(navigableSet) ? BigInteger.TEN : BigInteger.ZERO;
Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;
NavigableSet subSet = navigableSet.subSet(first, true, last, true);
// same subset
subSet.subSet(first, true, last, true);
// slightly smaller
NavigableSet ns = subSet.subSet(first, false, last, false);
// slight exapansion
assertThrows(() -> {
ns.subSet(first, true, last, true);
},
IllegalArgumentException.class,
description + ": Expansion should not be allowed");
// much smaller
subSet.subSet(first, false, BigInteger.ONE, false);
}
示例4: testSubSetRanges
import java.util.NavigableSet; //导入方法依赖的package包/类
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testSubSetRanges(String description, NavigableSet navigableSet) {
Object first = isDescending(navigableSet) ? BigInteger.TEN : BigInteger.ZERO;
Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;
NavigableSet subSet = navigableSet.subSet(first, true, last, true);
// same subset
subSet.subSet(first, true, last, true);
// slightly smaller
NavigableSet ns = subSet.subSet(first, false, last, false);
// slight expansion
assertThrowsIAE(() -> {
ns.subSet(first, true, last, true);
},
description + ": Expansion should not be allowed");
// much smaller
subSet.subSet(first, false, BigInteger.ONE, false);
}
示例5: testSubSetContents2
import java.util.NavigableSet; //导入方法依赖的package包/类
public void testSubSetContents2() {
NavigableSet set = set5();
SortedSet sm = set.subSet(two, three);
assertEquals(1, sm.size());
assertEquals(two, sm.first());
assertEquals(two, sm.last());
assertFalse(sm.contains(one));
assertTrue(sm.contains(two));
assertFalse(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(two));
assertEquals(4, set.size());
assertEquals(0, sm.size());
assertTrue(sm.isEmpty());
assertFalse(sm.remove(three));
assertEquals(4, set.size());
}
示例6: testDescendingSubSetContents2
import java.util.NavigableSet; //导入方法依赖的package包/类
public void testDescendingSubSetContents2() {
NavigableSet set = dset5();
SortedSet sm = set.subSet(m2, m3);
assertEquals(1, sm.size());
assertEquals(m2, sm.first());
assertEquals(m2, sm.last());
assertFalse(sm.contains(m1));
assertTrue(sm.contains(m2));
assertFalse(sm.contains(m3));
assertFalse(sm.contains(m4));
assertFalse(sm.contains(m5));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(m2, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(m2));
assertEquals(4, set.size());
assertEquals(0, sm.size());
assertTrue(sm.isEmpty());
assertFalse(sm.remove(m3));
assertEquals(4, set.size());
}
示例7: testSubSetContents
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* subSet returns set with keys in requested range
*/
public void testSubSetContents() {
NavigableSet set = set5();
SortedSet sm = set.subSet(two, four);
assertEquals(two, sm.first());
assertEquals(three, sm.last());
assertEquals(2, sm.size());
assertFalse(sm.contains(one));
assertTrue(sm.contains(two));
assertTrue(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(two));
assertEquals(4, set.size());
assertEquals(1, sm.size());
assertEquals(three, sm.first());
assertEquals(three, sm.last());
assertTrue(sm.remove(three));
assertTrue(sm.isEmpty());
assertEquals(3, set.size());
}
示例8: testDescendingSubSetContents
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* subSet returns set with keys in requested range
*/
public void testDescendingSubSetContents() {
NavigableSet set = dset5();
SortedSet sm = set.subSet(m2, m4);
assertEquals(m2, sm.first());
assertEquals(m3, sm.last());
assertEquals(2, sm.size());
assertFalse(sm.contains(m1));
assertTrue(sm.contains(m2));
assertTrue(sm.contains(m3));
assertFalse(sm.contains(m4));
assertFalse(sm.contains(m5));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(m2, k);
k = (Integer)(i.next());
assertEquals(m3, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(m2));
assertEquals(4, set.size());
assertEquals(1, sm.size());
assertEquals(m3, sm.first());
assertEquals(m3, sm.last());
assertTrue(sm.remove(m3));
assertTrue(sm.isEmpty());
assertEquals(3, set.size());
}
示例9: testSubSet_E_E
import java.util.NavigableSet; //导入方法依赖的package包/类
public void testSubSet_E_E() {
NavigableSet<String> set = create();
SortedSet<String> subSet = set.subSet("a", "b");
assertTrue(subSet instanceof SynchronizedSortedSet);
assertSame(set, ((SynchronizedSortedSet<String>) subSet).mutex);
}
示例10: testSubSet_E_B_E_B
import java.util.NavigableSet; //导入方法依赖的package包/类
public void testSubSet_E_B_E_B() {
NavigableSet<String> set = create();
NavigableSet<String> subSet = set.subSet("a", false, "b", true);
assertTrue(subSet instanceof SynchronizedNavigableSet);
assertSame(set, ((SynchronizedNavigableSet<String>) subSet).mutex);
}
示例11: buildDtoChanges
import java.util.NavigableSet; //导入方法依赖的package包/类
public DtoChanges buildDtoChanges(
final TransactionId.W lowerTxid,
final boolean lowerInclusive,
final TransactionId.W upperTxid,
final boolean upperInclusive)
{
final Set<AbstractModel> newMvos = new HashSet<AbstractModel>();
final Set<AbstractModel> changedMvos = new HashSet<AbstractModel>();
for (AbstractModel obj : getAbstractModels()) {
final TransactionId.W initialTxid = obj.getInitialVersion();
if (lowerTxid.serial <= initialTxid.serial && initialTxid.serial <= upperTxid.serial) {
newMvos.add(obj);
}
NavigableSet<TransactionId.W> txids = new TreeSet<TransactionId.W>();
txids.addAll(getTransactionIds(obj));
for (String attrname : obj.getAttributeNames()) {
final Object value = obj.getValue(attrname);
if (value instanceof Attribute.SetAttr<?, ?>) {
final MvoSet<?> mvoset = ((Attribute.SetAttr<?, AbstractModel>) value).get(obj);
txids.addAll(getTransactionIds(mvoset));
}
if (value instanceof Attribute.ListAttr<?, ?>) {
final MvoList<?> mvolist = ((Attribute.ListAttr<?, AbstractModel>) value).get(obj);
txids.addAll(getTransactionIds(mvolist));
}
if (value instanceof Attribute.MapAttr<?, ?, ?>) {
final MvoMap<?, ?> mvomap = ((Attribute.MapAttr<?, ?, AbstractModel>) value).get(obj);
txids.addAll(getTransactionIds(mvomap));
}
}
txids = txids.subSet(lowerTxid, lowerInclusive, upperTxid, upperInclusive);
if (0 < txids.size()) {
changedMvos.add(obj);
}
}
changedMvos.removeAll(newMvos);
return new DtoChanges(
originator_, lowerTxid, upperTxid, TransactionContext.getTargetTime(),
buildDtos(newMvos), buildDtos(changedMvos));
}