Beispiel #1
0
 /** @tests java.util.TreeSet#tailSet(java.lang.Object) */
 public void test_tailSetLjava_lang_Object() {
   // Test for method java.util.SortedSet
   // java.util.TreeSet.tailSet(java.lang.Object)
   Set s = ts.tailSet(new Integer(900));
   assertEquals("Returned set of incorrect size", 100, s.size());
   for (int i = 900; i < objArray.length; i++)
     assertTrue("Returned incorrect set", s.contains(objArray[i]));
 }
Beispiel #2
0
    @Override
    public int nextTab(int position) {
      int tabStop = Integer.MAX_VALUE;

      // Search for the first tab stop after the given position...
      SortedSet<Integer> tailSet = myTabStops.tailSet(position + 1);
      if (!tailSet.isEmpty()) {
        tabStop = tailSet.first();
      }

      // Don't go beyond the end of the line...
      return Math.min(tabStop, (myWidth - 1));
    }
Beispiel #3
0
  public static void main(String[] args) {
    System.setProperty("fr.umlv.jbucks.factory", BuckFactoryImpl.class.getName());

    BuckFactory factory = BuckFactory.getFactory();
    Book book = factory.createBook("test");
    System.out.println(book.getName());

    book.setUserData("hello-UID", "12345");
    System.out.println("hello-UID " + book.getUserDataValue("hello-UID"));

    EventManager manager = factory.getEventManager();

    manager.addListener(
        Book.class,
        "accounts",
        PropertyEvent.TYPE_PROPERTY_ADDED | PropertyEvent.TYPE_PROPERTY_REMOVED,
        new PropertyListener() {
          public void propertyChanged(PropertyEvent event) {
            System.out.println(event);
          }
        });

    Account account = factory.createAccount(book, "remi");
    factory.createAccount(book, "gilles");

    List list = book.getAccounts();

    System.out.println(list);

    SortedSet transactions = account.getTransactions();

    manager.addListener(
        Account.class,
        "transactions",
        PropertyEvent.TYPE_PROPERTY_ADDED | PropertyEvent.TYPE_PROPERTY_REMOVED,
        new PropertyListener() {
          public void propertyChanged(PropertyEvent event) {
            System.out.println("transaction " + event);
          }
        });

    Transaction transaction =
        factory.createTransaction(new Date().getTime(), Collections.EMPTY_LIST);
    transactions.add(transaction);

    SortedSet tailSet = transactions.tailSet(transaction);

    System.out.println(tailSet);

    tailSet.add(factory.createTransaction(transaction.getDate() + 1, Collections.EMPTY_LIST));
  }
 /**
  * Returns a new {@link GapAwareTrackingToken} instance based on this token but which has advanced
  * to given {@code index}. Gaps that have fallen behind the index by more than the {@code
  * maxGapOffset} will not be included in the new token.
  *
  * <p>Note that the given {@code index} should be one of the current token's gaps or be higher
  * than the current token's index.
  *
  * @param index the global sequence number of the next event
  * @param maxGapOffset the maximum distance between a gap and the token's index
  * @return the new token that has advanced from the current token
  */
 public GapAwareTrackingToken advanceTo(long index, int maxGapOffset) {
   long newIndex;
   SortedSet<Long> gaps = new TreeSet<>(this.gaps);
   if (gaps.remove(index)) {
     newIndex = this.index;
   } else if (index > this.index) {
     newIndex = index;
     LongStream.range(this.index + 1L, index).forEach(gaps::add);
   } else {
     throw new IllegalArgumentException(
         String.format(
             "The given index [%d] should be larger than the token index [%d] or be one of the token's gaps [%s]",
             index, this.index, gaps));
   }
   gaps = gaps.tailSet(newIndex - maxGapOffset);
   return new GapAwareTrackingToken(newIndex, gaps);
 }
  private BdynRangeSet addToRange(long start, long t0, long t1, BdynRangeSet rslt) {
    OutputEntry timee = new OutputEntry(start);
    SortedSet<OutputEntry> ss = output_set.tailSet(timee);
    for (OutputEntry e1 : ss) {
      if (e1.getStartTime() > t1) break;
      if (e1.getEndTime(t1) >= t0) {
        ThreadData td = e1.getThread();
        if (rslt == null) rslt = new BdynRangeSet();
        Set<BdynEntry> r1 = rslt.get(td);
        if (r1 == null) {
          r1 = new HashSet<BdynEntry>();
          rslt.put(td, r1);
        }
        r1.add(e1);
      }
    }

    return rslt;
  }
Beispiel #6
0
 public static void main(String[] args) {
   SortedSet<String> sortedSet = new TreeSet<String>();
   Collections.addAll(sortedSet, "one two three four five six seven eight".split(" "));
   print(sortedSet);
   String low = sortedSet.first();
   String high = sortedSet.last();
   print(low);
   print(high);
   Iterator<String> it = sortedSet.iterator();
   for (int i = 0; i <= 6; i++) {
     if (i == 3) low = it.next();
     if (i == 6) high = it.next();
     else it.next();
   }
   print(low);
   print(high);
   print(sortedSet.subSet(low, high));
   print(sortedSet.headSet(high));
   print(sortedSet.tailSet(low));
 }