示例#1
0
 /** Set contains all elements of successful addAll */
 public void testDescendingAddAll5() {
   Integer[] empty = new Integer[0];
   Integer[] ints = new Integer[SIZE];
   for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(SIZE - 1 - i);
   NavigableSet q = dset0();
   assertFalse(q.addAll(Arrays.asList(empty)));
   assertTrue(q.addAll(Arrays.asList(ints)));
   for (int i = 0; i < SIZE; ++i) assertEquals(new Integer(i), q.pollFirst());
 }
 @Override
 public <E extends A> NavigableSet<E> apply(final Collection<E> alternatives) {
   normalize();
   final NavigableSet<E> result = new ConcurrentSkipListSet<E>(this);
   result.addAll(alternatives);
   return result;
 }
示例#3
0
  private void mergeStatuses(NavigableSet<Status> originalStatuses, List<Status> newStatuses) {
    originalStatuses.addAll(newStatuses);

    while (originalStatuses.size() >= 40) {
      originalStatuses.pollFirst();
    }
  }
示例#4
0
 @Test
 public void testUnsignedTreeSetMRef() {
   NavigableSet<Integer> set = new TreeSet<>(Integer::compareUnsigned);
   set.addAll(Arrays.asList(-100, 0, 100));
   assertEquals(0, set.first().intValue());
   assertEquals(-100, set.last().intValue());
 }
示例#5
0
 /** addAll(null) throws NPE */
 public void testDescendingAddAll1() {
   NavigableSet q = dset0();
   try {
     q.addAll(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
示例#6
0
 void addAll(Collection<Link> nodes) {
   NavigableSet<Link> propset = leftNbrSet.clone();
   propset.addAll(nodes);
   while (capacity > 0 && propset.size() > capacity) {
     propset.remove(propset.last());
   }
   set(propset);
 }
示例#7
0
 /** addAll of a collection with null elements throws NPE */
 public void testDescendingAddAll2() {
   NavigableSet q = dset0();
   Integer[] ints = new Integer[SIZE];
   try {
     q.addAll(Arrays.asList(ints));
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
示例#8
0
 @Test
 public void testUnsignedTreeSetNotSerializable() {
   NavigableSet<Integer> set = new TreeSet<>((x, y) -> Integer.compareUnsigned(x, y));
   set.addAll(Arrays.asList(-100, 0, 100));
   assertEquals(0, set.first().intValue());
   assertEquals(-100, set.last().intValue());
   byte[] serializedSet = writeSetToBytes(set, false);
   assertEquals(null, serializedSet);
 }
示例#9
0
 /**
  * addAll of a collection with any null elements throws NPE after possibly adding some elements
  */
 public void testDescendingAddAll3() {
   NavigableSet q = dset0();
   Integer[] ints = new Integer[SIZE];
   for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i + SIZE);
   try {
     q.addAll(Arrays.asList(ints));
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
  private Collection<SamplingPoint> getNonOverlappingPoints(Collection<SamplingPoint> points) {
    final NavigableSet<SamplingPoint> unique = new TreeSet<>(orderedComparator);
    final NavigableSet<SamplingPoint> result = new TreeSet<>(orderedComparator);

    unique.addAll(points);
    for (final SamplingPoint point : unique) {
      if (overlapCalculator.areOverlapping(point, result)) {
        result.add(point);
      }
    }

    return result;
  }
示例#11
0
 @Test
 public void testUnsignedTreeSetSerializable() {
   NavigableSet<Integer> set =
       new TreeSet<>(
           (Comparator<Integer> & Serializable) ((x, y) -> Integer.compareUnsigned(x, y)));
   set.addAll(Arrays.asList(-100, 0, 100));
   assertEquals(0, set.first().intValue());
   assertEquals(-100, set.last().intValue());
   byte[] serializedSet = writeSetToBytes(set, true);
   NavigableSet<Integer> set1 = readSetFromBytes(serializedSet);
   assertEquals(0, set1.first().intValue());
   assertEquals(-100, set1.last().intValue());
   assertEquals(set, set1);
 }
示例#12
0
  public void setClusters(Set<SemiClusterDetails> clusters, int graphJobVertexMaxClusterCount) {
    int clusterCountToBeRemoved = 0;
    NavigableSet<SemiClusterDetails> setSort =
        new TreeSet<SemiClusterDetails>(
            new Comparator<SemiClusterDetails>() {

              @Override
              public int compare(SemiClusterDetails o1, SemiClusterDetails o2) {
                return (o1.getSemiClusterScore() == o2.getSemiClusterScore()
                    ? 0
                    : o1.getSemiClusterScore() < o2.getSemiClusterScore() ? -1 : 1);
              }
            });
    setSort.addAll(this.semiClusterContainThis);
    setSort.addAll(clusters);
    clusterCountToBeRemoved = setSort.size() - graphJobVertexMaxClusterCount;
    Iterator<SemiClusterDetails> itr = setSort.descendingIterator();
    while (clusterCountToBeRemoved > 0) {
      itr.next();
      itr.remove();
      clusterCountToBeRemoved--;
    }
    this.semiClusterContainThis = setSort;
  }
 @SuppressWarnings("EmptyCatchBlock")
 static void ensureNotDirectlyModifiable(NavigableSet<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 {
     unmod.pollFirst();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.pollLast();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.iterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.descendingIterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
 }
示例#14
0
文件: SetsTest.java 项目: cjosw/guava
 @GwtIncompatible("NavigableSet")
 void ensureNotDirectlyModifiable(NavigableSet<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 {
     unmod.pollFirst();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.pollLast();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.iterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.descendingIterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
 }
示例#15
0
文件: SetsTest.java 项目: cjosw/guava
  @GwtIncompatible("NavigableSet")
  public void testUnmodifiableNavigableSet() {
    TreeSet<Integer> mod = Sets.newTreeSet();
    mod.add(1);
    mod.add(2);
    mod.add(3);

    NavigableSet<Integer> unmod = unmodifiableNavigableSet(mod);

    /* Unmodifiable is a view. */
    mod.add(4);
    assertTrue(unmod.contains(4));
    assertTrue(unmod.descendingSet().contains(4));

    ensureNotDirectlyModifiable(unmod);
    ensureNotDirectlyModifiable(unmod.descendingSet());
    ensureNotDirectlyModifiable(unmod.headSet(2));
    ensureNotDirectlyModifiable(unmod.headSet(2, true));
    ensureNotDirectlyModifiable(unmod.tailSet(2));
    ensureNotDirectlyModifiable(unmod.tailSet(2, true));
    ensureNotDirectlyModifiable(unmod.subSet(1, 3));
    ensureNotDirectlyModifiable(unmod.subSet(1, true, 3, true));

    /* UnsupportedOperationException on indirect modifications. */
    NavigableSet<Integer> reverse = unmod.descendingSet();
    try {
      reverse.add(4);
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException expected) {
    }
    try {
      reverse.addAll(Collections.singleton(4));
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException expected) {
    }
    try {
      reverse.remove(4);
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException expected) {
    }
  }
示例#16
0
 public static void routing(Number160 key, Peer[] peers, int start) {
   System.out.println("routing: searching for key " + key);
   NavigableSet<PeerAddress> pa1 = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
   NavigableSet<PeerAddress> queried = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
   Number160 result = Number160.ZERO;
   Number160 resultPeer = new Number160("0xd75d1a3d57841fbc9e2a3d175d6a35dc2e15b9f");
   int round = 0;
   while (!resultPeer.equals(result)) {
     System.out.println("round " + round);
     round++;
     pa1.addAll(peers[start].getPeerBean().peerMap().getAll());
     queried.add(peers[start].getPeerAddress());
     System.out.println("closest so far: " + queried.first());
     PeerAddress next = pa1.pollFirst();
     while (queried.contains(next)) {
       next = pa1.pollFirst();
     }
     result = next.getPeerId();
     start = findNr(next.getPeerId().toString(), peers);
   }
 }
  @SuppressWarnings("EmptyCatchBlock")
  public void testUnmodifiability() {
    TreeSet<Integer> mod = Sets.newTreeSet();
    mod.add(1);
    mod.add(2);
    mod.add(3);

    NavigableSet<Integer> unmod = new UnmodifiableNavigableSet<Integer>(mod);

    mod.add(4);
    assertTrue(unmod.contains(4));
    assertTrue(unmod.descendingSet().contains(4));

    ensureNotDirectlyModifiable(unmod);
    ensureNotDirectlyModifiable(unmod.descendingSet());
    ensureNotDirectlyModifiable(unmod.headSet(2));
    ensureNotDirectlyModifiable(unmod.headSet(2, true));
    ensureNotDirectlyModifiable(unmod.tailSet(2));
    ensureNotDirectlyModifiable(unmod.tailSet(2, true));
    ensureNotDirectlyModifiable(unmod.subSet(1, 3));
    ensureNotDirectlyModifiable(unmod.subSet(1, true, 3, true));

    NavigableSet<Integer> reverse = unmod.descendingSet();
    try {
      reverse.add(4);
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException expected) {
    }
    try {
      reverse.addAll(Collections.singleton(4));
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException expected) {
    }
    try {
      reverse.remove(4);
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException expected) {
    }
  }
示例#18
0
  public TuningResDTO buildTuningRes(
      Date startDate,
      Date endDate,
      Stock stock,
      String analyseName,
      SortedMap<Date, double[]> calcOutput,
      EventInfo evtDef,
      Observer observer,
      Boolean isEventsPersisted)
      throws NotEnoughDataException {

    if (calcOutput == null) calcOutput = new TreeMap<Date, double[]>();
    if (!calcOutput.isEmpty() && calcOutput.firstKey().before(startDate))
      calcOutput = calcOutput.tailMap(startDate);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy MM dd");
    String noResMsg =
        "No estimate is available for "
            + stock.getName()
            + " between "
            + dateFormat.format(startDate)
            + " and "
            + dateFormat.format(endDate)
            + " with "
            + evtDef
            + ".\n";
    try {

      Date endCalcRes =
          (calcOutput.size() > 0 && calcOutput.lastKey().after(endDate))
              ? calcOutput.lastKey()
              : endDate;

      // Grab calculated events
      HashSet<EventInfo> eventDefinitions = new HashSet<EventInfo>();
      eventDefinitions.add(evtDef);
      SymbolEvents eventsCalculated =
          EventsResources.getInstance()
              .crudReadEventsForStock(
                  stock, startDate, endCalcRes, isEventsPersisted, eventDefinitions, analyseName);

      // Init event def list
      NavigableSet<EventValue> eventListForEvtDef =
          new TreeSet<EventValue>(
              new Comparator<EventValue>() {
                @Override
                public int compare(EventValue o1, EventValue o2) {
                  return o1.getDate().compareTo(o2.getDate());
                }
              });
      eventListForEvtDef.addAll(eventsCalculated.getDataResultMap().values());

      return buildTuningRes(
          stock,
          startDate,
          endDate,
          endCalcRes,
          analyseName,
          calcOutput,
          eventListForEvtDef,
          noResMsg,
          evtDef.info(),
          observer);

    } catch (NoQuotationsException e) {
      LOGGER.warn(noResMsg, e);
      throw new NotEnoughDataException(stock, noResMsg, e);
    } catch (NotEnoughDataException e) {
      LOGGER.warn(noResMsg, e);
      throw e;
    } catch (Exception e) {
      LOGGER.error(noResMsg, e);
      throw new NotEnoughDataException(stock, noResMsg, e);
    }
  }