Beispiel #1
0
 /** toArray(a) contains all elements in sorted order */
 public void testToArray2() {
   NavigableSet<Integer> q = populatedSet(SIZE);
   Integer[] ints = new Integer[SIZE];
   Integer[] array = q.toArray(ints);
   assertSame(ints, array);
   for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.pollFirst());
 }
Beispiel #2
0
  /** tailSet returns set with keys in requested range */
  public void testDescendingTailSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.tailSet(m2);
    assertFalse(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertTrue(sm.contains(m4));
    assertTrue(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    k = (Integer) (i.next());
    assertEquals(m4, k);
    k = (Integer) (i.next());
    assertEquals(m5, k);
    assertFalse(i.hasNext());

    SortedSet ssm = sm.tailSet(m4);
    assertEquals(m4, ssm.first());
    assertEquals(m5, ssm.last());
    assertTrue(ssm.remove(m4));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
  }
 @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());
 }
  public LeftEditorHighlighter(@NotNull EditorComponent editorComponent, boolean rightToLeft) {
    setBackground(EditorSettings.getInstance().getLeftHighlighterBackgroundColor());
    myEditorComponent = editorComponent;
    myRightToLeft = rightToLeft;
    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseExited(MouseEvent e) {
            mouseExitedFoldingArea(e);
            mouseExitedIconsArea(e);
          }

          @Override
          public void mouseEntered(MouseEvent e) {
            if (isInFoldingArea(e)) {
              mouseMovedInFoldingArea(e);
            } else if (isInTextArea(e)) {
              mouseMovedInTextArea(e);
            } else {
              mouseMovedInIconsArea(e);
            }
          }
        });
    addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(MouseEvent e) {
            if (isInFoldingArea(e)) {
              mouseExitedIconsArea(e);
              mouseMovedInFoldingArea(e);
            } else if (isInTextArea(e)) {
              mouseExitedFoldingArea(e);
              mouseExitedIconsArea(e);
              mouseMovedInTextArea(e);
            } else {
              mouseExitedFoldingArea(e);
              mouseMovedInIconsArea(e);
            }
          }
        });
    if (MPSToolTipManager.getInstance() != null) {
      MPSToolTipManager.getInstance().registerComponent(this);
    }
    editorComponent.addRebuildListener(
        new RebuildListener() {
          @Override
          public void editorRebuilt(EditorComponent editor) {
            assert SwingUtilities.isEventDispatchThread()
                : "LeftEditorHighlighter$RebuildListener should be called in eventDispatchThread";
            for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
              painter.editorRebuilt();
            }
          }
        });
    myBracketsPainter = new BracketsPainter(this, myRightToLeft);
    myFoldingButtonsPainter = new FoldingButtonsPainter(this);

    myFoldingAreaPainters.add(myBracketsPainter);
    myFoldingAreaPainters.add(myFoldingButtonsPainter);
  }
Beispiel #5
0
  /** tailSet returns set with keys in requested range */
  public void testTailSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.tailSet(two);
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertTrue(sm.contains(four));
    assertTrue(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());

    SortedSet ssm = sm.tailSet(four);
    assertEquals(four, ssm.first());
    assertEquals(five, ssm.last());
    assertTrue(ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
  }
 @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;
 }
Beispiel #7
0
  private NavigableSet<Integer> getVersionHistory() {
    final File upgradeDirName = new File(installRoot, "config/upgrade");
    final String pattern = "config.ldif.";
    final NavigableSet<Integer> versions = new TreeSet<Integer>();

    // Always include 0 in order to avoid checking for empty/null.
    versions.add(0);

    if (upgradeDirName.exists() && upgradeDirName.isDirectory()) {
      final String[] configFiles =
          upgradeDirName.list(
              new FilenameFilter() {
                public boolean accept(final File dir, final String name) {
                  return name.startsWith(pattern);
                }
              });

      for (final String configFile : configFiles) {
        if (configFile.length() > 0) {
          final String version = configFile.substring(pattern.length());

          try {
            versions.add(Integer.parseInt(version));
          } catch (final NumberFormatException nfe) {
            // TODO: log something?
          }
        }
      }
    }

    return versions;
  }
  public void testKeyPutRandomUniform() throws Exception {
    final NavigableSet<Integer> keys = new TreeSet<Integer>();

    long seed = System.currentTimeMillis();

    System.out.println("testKeyPutRandomUniform seed : " + seed);

    final MersenneTwisterFast random = new MersenneTwisterFast(seed);

    while (keys.size() < KEYS_COUNT) {
      int key = random.nextInt(Integer.MAX_VALUE);
      sbTree.put(key, createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));
      keys.add(key);

      doReset();
    }

    Assert.assertEquals(sbTree.firstKey(), keys.first());
    doReset();

    Assert.assertEquals(sbTree.lastKey(), keys.last());
    doReset();

    for (int key : keys) {
      Assert.assertEquals(
          sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));
      doReset();
    }
  }
Beispiel #9
0
 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());
 }
Beispiel #10
0
 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());
 }
Beispiel #11
0
 /** toArray(a) contains all elements */
 public void testDescendingToArray2() {
   NavigableSet q = populatedSet(SIZE);
   Integer[] ints = new Integer[SIZE];
   assertSame(ints, q.toArray(ints));
   Arrays.sort(ints);
   for (int i = 0; i < ints.length; i++) assertEquals(ints[i], q.pollFirst());
 }
Beispiel #12
0
 /** toString contains toStrings of elements */
 public void testDescendingToString() {
   NavigableSet q = populatedSet(SIZE);
   String s = q.toString();
   for (int i = 0; i < SIZE; ++i) {
     assertTrue(s.contains(String.valueOf(i)));
   }
 }
Beispiel #13
0
 /** poll succeeds unless empty */
 public void testDescendingPoll() {
   NavigableSet q = populatedSet(SIZE);
   for (int i = 0; i < SIZE; ++i) {
     assertEquals(i, q.pollFirst());
   }
   assertNull(q.pollFirst());
 }
Beispiel #14
0
  private void mergeStatuses(NavigableSet<Status> originalStatuses, List<Status> newStatuses) {
    originalStatuses.addAll(newStatuses);

    while (originalStatuses.size() >= 40) {
      originalStatuses.pollFirst();
    }
  }
  public ImmutableMap<String, Method> build() {

    final ImmutableMap.Builder<String, Method> lResultBuilder =
        new ImmutableMap.Builder<String, Method>();

    // iterate based on mMethodsOrdered to maintain
    // the order
    for (String lBeanPropName : mMethodsOrdered) {

      final NavigableSet<Method> lAllMethods = mMethodCache.getUnchecked(lBeanPropName);
      final Method lMostPreciseMethod = lAllMethods.last();

      LOGGER.trace(
          "propName [{}] selected method [{}] all methods[{}]",
          new Object[] {lBeanPropName, lMostPreciseMethod, lAllMethods});

      if (mBeanMethodFilter.accepts(lMostPreciseMethod, lBeanPropName)) {
        lResultBuilder.put(lBeanPropName, lMostPreciseMethod);
      } else {
        LOGGER.trace("rejected [{}]", lBeanPropName);
      }
    }

    return lResultBuilder.build();
  }
Beispiel #16
0
 /** contains(x) reports true when elements added but not yet removed */
 public void testDescendingContains() {
   NavigableSet q = populatedSet(SIZE);
   for (int i = 0; i < SIZE; ++i) {
     assertTrue(q.contains(new Integer(i)));
     q.pollFirst();
     assertFalse(q.contains(new Integer(i)));
   }
 }
  @Override
  protected T prefetch() throws Exception {
    while (buffer.size() < maxBufferSize && it.hasNext()) {
      buffer.add(it.next());
    }

    return buffer.isEmpty() ? finish() : buffer.pollFirst();
  }
Beispiel #18
0
 /** add(null) throws NPE */
 public void testAddNull() {
   NavigableSet q = set0();
   try {
     q.add(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
Beispiel #19
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);
 }
Beispiel #20
0
 /** addAll(null) throws NPE */
 public void testDescendingAddAll1() {
   NavigableSet q = dset0();
   try {
     q.addAll(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
Beispiel #21
0
 /** iterator iterates through all elements */
 public void testIterator() {
   NavigableSet q = populatedSet(SIZE);
   Iterator it = q.iterator();
   int i;
   for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next()));
   assertEquals(i, SIZE);
   assertIteratorExhausted(it);
 }
 public void addFoldingAreaPainter(AbstractFoldingAreaPainter painter) {
   if (myFoldingAreaPainters.contains(painter)) {
     return;
   }
   myFoldingAreaPainters.add(painter);
   relayout(true);
   repaint();
 }
 public void removeFoldingAreaPainter(AbstractFoldingAreaPainter painter) {
   if (!myFoldingAreaPainters.contains(painter)) {
     return;
   }
   myFoldingAreaPainters.remove(painter);
   relayout(true);
   repaint();
 }
 /*
  * Add the specified KeyValue to the list of deletes.
  * @param kv
  */
 private void addDelete(final KeyValue kv) {
   NavigableSet<KeyValue> rowdeletes = this.deletes.get(kv);
   if (rowdeletes == null) {
     rowdeletes = new TreeSet<KeyValue>(this.kvcomparator);
     this.deletes.put(kv, rowdeletes);
   }
   rowdeletes.add(kv);
 }
Beispiel #25
0
 /*
  * Test utility for building a NavigableSet for scanners.
  * @param strCols
  * @return
  */
 NavigableSet<byte[]> getCols(String... strCols) {
   NavigableSet<byte[]> cols = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
   for (String col : strCols) {
     byte[] bytes = Bytes.toBytes(col);
     cols.add(bytes);
   }
   return cols;
 }
Beispiel #26
0
 /**
  * Get the column from the specified family with the specified qualifier.
  *
  * <p>Overrides previous calls to addFamily for this family.
  *
  * @param family family name
  * @param qualifier column qualifier
  * @return this
  */
 public HaeinsaScan addColumn(byte[] family, byte[] qualifier) {
   NavigableSet<byte[]> set = familyMap.get(family);
   if (set == null) {
     set = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
   }
   set.add(qualifier);
   familyMap.put(family, set);
   return this;
 }
Beispiel #27
0
 @Override
 public NavigableSet<Character> getAlphabet() {
   if (alphabet == null) {
     NavigableSet<Character> lettersSet = new TreeSet<Character>();
     for (char c : letters) lettersSet.add(c);
     alphabet = new UnmodifiableNavigableSet<Character>(lettersSet);
   }
   return alphabet;
 }
Beispiel #28
0
 /** Add of non-Comparable throws CCE */
 public void testDescendingAddNonComparable() {
   NavigableSet q = dset0();
   try {
     q.add(new Object());
     q.add(new Object());
     shouldThrow();
   } catch (ClassCastException success) {
   }
 }
Beispiel #29
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) {
   }
 }
Beispiel #30
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());
 }