Tabnine Logo
SortedSet
Code IndexAdd Tabnine to your IDE (free)

How to use
SortedSet
in
java.util

Best Java code snippets using java.util.SortedSet (Showing top 20 results out of 20,466)

origin: google/guava

private static <E extends Comparable<? super E>> SortedSet<E> nullCheckedTreeSet(E[] elements) {
 SortedSet<E> set = newTreeSet();
 for (E element : elements) {
  // Explicit null check because TreeSet wrongly accepts add(null) when empty.
  set.add(checkNotNull(element));
 }
 return set;
}
origin: spring-projects/spring-framework

  /**
   * Find the requested number of available ports for this {@code SocketType},
   * each randomly selected from the range [{@code minPort}, {@code maxPort}].
   * @param numRequested the number of available ports to find
   * @param minPort the minimum port number
   * @param maxPort the maximum port number
   * @return a sorted set of available port numbers for this socket type
   * @throws IllegalStateException if the requested number of available ports could not be found
   */
  SortedSet<Integer> findAvailablePorts(int numRequested, int minPort, int maxPort) {
    Assert.isTrue(minPort > 0, "'minPort' must be greater than 0");
    Assert.isTrue(maxPort > minPort, "'maxPort' must be greater than 'minPort'");
    Assert.isTrue(maxPort <= PORT_RANGE_MAX, "'maxPort' must be less than or equal to " + PORT_RANGE_MAX);
    Assert.isTrue(numRequested > 0, "'numRequested' must be greater than 0");
    Assert.isTrue((maxPort - minPort) >= numRequested,
        "'numRequested' must not be greater than 'maxPort' - 'minPort'");
    SortedSet<Integer> availablePorts = new TreeSet<>();
    int attemptCount = 0;
    while ((++attemptCount <= numRequested + 100) && availablePorts.size() < numRequested) {
      availablePorts.add(findAvailablePort(minPort, maxPort));
    }
    if (availablePorts.size() != numRequested) {
      throw new IllegalStateException(String.format(
          "Could not find %d available %s ports in the range [%d, %d]",
          numRequested, name(), minPort, maxPort));
    }
    return availablePorts;
  }
}
origin: google/guava

 @Override
 protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  if (set.isEmpty()) {
   /*
    * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be
    * greater than tooHigh.
    */
   return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1);
  }
  int tooHigh = set.last() + 1;
  int tooLow = set.first() - 1;
  set.add(tooHigh);
  set.add(tooLow);
  return checkedCreate(set).subSet(tooLow + 1, tooHigh);
 }
}
origin: google/guava

 @Override
 public E last() {
  SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
  while (true) {
   E element = sortedUnfiltered.last();
   if (predicate.apply(element)) {
    return element;
   }
   sortedUnfiltered = sortedUnfiltered.headSet(element);
  }
 }
}
origin: google/guava

 @Override
 protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  int tooHigh = set.isEmpty() ? 0 : set.last() + 1;
  set.add(tooHigh);
  return checkedCreate(set).headSet(tooHigh);
 }
}
origin: google/guava

 @Override
 protected SortedSet<Integer> create(Integer[] elements) {
  SortedSet<Integer> set = nullCheckedTreeSet(elements);
  int tooLow = set.isEmpty() ? 0 : set.first() - 1;
  set.add(tooLow);
  return checkedCreate(set).tailSet(tooLow + 1);
 }
}
origin: google/guava

void ensureNotDirectlyModifiable(SortedSet<Integer> unmod) {
 try {
  unmod.add(4);
  fail("UnsupportedOperationException expected");
 } catch (UnsupportedOperationException expected) {
 }
 try {
  unmod.remove(4);
  fail("UnsupportedOperationException expected");
 } catch (UnsupportedOperationException expected) {
 }
 try {
  unmod.addAll(Collections.singleton(4));
  fail("UnsupportedOperationException expected");
 } catch (UnsupportedOperationException expected) {
 }
 try {
  Iterator<Integer> iterator = unmod.iterator();
  iterator.next();
  iterator.remove();
  fail("UnsupportedOperationException expected");
 } catch (UnsupportedOperationException expected) {
 }
}
origin: google/guava

public void testSortedKeySet() {
 TreeMultimap<String, Integer> multimap = createPopulate();
 SortedSet<String> keySet = multimap.keySet();
 assertEquals(null, keySet.first());
 assertEquals("google", keySet.last());
 assertEquals(StringLength.COMPARATOR, keySet.comparator());
 assertEquals(Sets.newHashSet(null, "tree"), keySet.headSet("yahoo"));
 assertEquals(Sets.newHashSet("google"), keySet.tailSet("yahoo"));
 assertEquals(Sets.newHashSet("tree"), keySet.subSet("ask", "yahoo"));
}
origin: google/guava

 @GwtIncompatible // SerializableTester
 public void testSeveral_serialization() {
  SortedSet<String> set = new SafeTreeSet<>();
  set.add("a");
  set.add("b");
  set.add("c");
  SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
  assertEquals(set.comparator(), copy.comparator());
 }
}
origin: apache/incubator-druid

@Override
public DimFilter optimize()
{
 InDimFilter inFilter = optimizeLookup();
 if (inFilter.values.size() == 1) {
  return new SelectorDimFilter(inFilter.dimension, inFilter.values.first(), inFilter.getExtractionFn());
 }
 return inFilter;
}
origin: apache/hbase

/**
 * Adds the given servers to the group.
 */
public void addAllServers(Collection<Address> hostPort){
 servers.addAll(hostPort);
}
origin: apache/storm

@Override
public KinesisMessageId getNextFailedMessageToRetry() {
  KinesisMessageId result = null;
  // return the first message to be retried from the set. It will return the message with the earliest retry time <= current time
  if (!retryMessageSet.isEmpty() ) {
    result = retryMessageSet.first();
    if (!(retryTimes.get(result) <= System.nanoTime())) {
      result = null;
    }
  }
  LOG.debug("Returning {} to spout for retrying.", result);
  return result;
}
origin: jenkinsci/jenkins

public synchronized int size() {
  return permissions.size();
}
origin: google/guava

public void testAsMapSortedReadsThrough() {
 SortedSet<String> strings = new NonNavigableSortedSet();
 Collections.addAll(strings, "one", "two", "three");
 SortedMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION);
 assertNull(map.comparator());
 assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5), map);
 assertNull(map.get("four"));
 strings.add("four");
 assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5, "four", 4), map);
 assertEquals(Integer.valueOf(4), map.get("four"));
 SortedMap<String, Integer> headMap = map.headMap("two");
 assertEquals(ImmutableSortedMap.of("four", 4, "one", 3, "three", 5), headMap);
 strings.add("five");
 strings.remove("one");
 assertEquals(ImmutableSortedMap.of("five", 4, "four", 4, "three", 5), headMap);
 assertThat(map.entrySet())
   .containsExactly(
     mapEntry("five", 4), mapEntry("four", 4), mapEntry("three", 5), mapEntry("two", 3))
   .inOrder();
}
origin: google/j2objc

@Override
public K firstKey() {
 // correctly throws NoSuchElementException when filtered map is empty.
 return keySet().iterator().next();
}
origin: google/guava

@Override
public E first() {
 synchronized (mutex) {
  return delegate().first();
 }
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void setCollectionPropertyWithIntegerValue() {
  IndexedTestBean target = new IndexedTestBean();
  AbstractPropertyAccessor accessor = createAccessor(target);
  Collection<Integer> coll = new HashSet<>();
  coll.add(0);
  accessor.setPropertyValue("collection", new Integer(0));
  List<Integer> set = new LinkedList<>();
  set.add(1);
  accessor.setPropertyValue("set", new Integer(1));
  List<Integer> sortedSet = new ArrayList<>();
  sortedSet.add(2);
  accessor.setPropertyValue("sortedSet", new Integer(2));
  Set<Integer> list = new HashSet<>();
  list.add(3);
  accessor.setPropertyValue("list", new Integer(3));
  assertEquals(1, target.getCollection().size());
  assertTrue(target.getCollection().containsAll(coll));
  assertEquals(1, target.getSet().size());
  assertTrue(target.getSet().containsAll(set));
  assertEquals(1, target.getSortedSet().size());
  assertTrue(target.getSortedSet().containsAll(sortedSet));
  assertEquals(1, target.getList().size());
  assertTrue(target.getList().containsAll(list));
}
origin: google/guava

@Override
public E last() {
 synchronized (mutex) {
  return delegate().last();
 }
}
origin: google/guava

public void testNullAcceptingComparator() throws Exception {
 Comparator<String> comparator = Ordering.<String>natural().nullsFirst();
 TreeMultiset<String> ms = TreeMultiset.create(comparator);
 ms.add("b");
 ms.add(null);
 ms.add("a");
 ms.add("b");
 ms.add(null, 2);
 assertThat(ms).containsExactly(null, null, null, "a", "b", "b").inOrder();
 assertEquals(3, ms.count(null));
 SortedSet<String> elementSet = ms.elementSet();
 assertEquals(null, elementSet.first());
 assertEquals("b", elementSet.last());
 assertEquals(comparator, elementSet.comparator());
}
origin: spring-projects/spring-framework

@Test
public void setCollectionPropertyWithStringValueAndCustomEditor() {
  IndexedTestBean target = new IndexedTestBean();
  AbstractPropertyAccessor accessor = createAccessor(target);
  accessor.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
  accessor.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));
  accessor.setPropertyValue("set", "set1 ");
  accessor.setPropertyValue("sortedSet", "sortedSet1");
  accessor.setPropertyValue("list", "list1 ");
  assertEquals(1, target.getSet().size());
  assertTrue(target.getSet().contains("set1"));
  assertEquals(1, target.getSortedSet().size());
  assertTrue(target.getSortedSet().contains("sortedSet1"));
  assertEquals(1, target.getList().size());
  assertTrue(target.getList().contains("list1"));
  accessor.setPropertyValue("list", Collections.singletonList("list1 "));
  assertTrue(target.getList().contains("list1"));
}
java.utilSortedSet

Javadoc

SortedSet is a Set which iterates over its elements in a sorted order. The order is determined either by the elements natural ordering, or by a Comparator which is passed into a concrete implementation at construction time. All elements in this set must be mutually comparable. The ordering in this set must be consistent with equals of its elements.

Most used methods

  • add
  • size
  • isEmpty
  • first
    Returns the first (lowest) element currently in this set.
  • addAll
  • iterator
  • last
    Returns the last (highest) element currently in this set.
  • remove
  • contains
  • clear
  • tailSet
    Returns a view of the portion of this set whose elements are greater than or equal to fromElement. T
  • comparator
    Returns the comparator used to order the elements in this set, or null if this set uses the Comparab
  • tailSet,
  • comparator,
  • headSet,
  • toArray,
  • subSet,
  • stream,
  • removeAll,
  • forEach,
  • containsAll,
  • retainAll

Popular in Java

  • Finding current android device location
  • getSystemService (Context)
  • getResourceAsStream (ClassLoader)
  • getContentResolver (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now