Java Code Examples for java.util.NavigableSet#pollFirst()

The following examples show how to use java.util.NavigableSet#pollFirst() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BadQueryHistoryManagerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws Exception {
    BadQueryHistory history = BadQueryHistoryManager.getInstance(getTestConfig())
            .getBadQueriesForProject("default");
    System.out.println(JsonUtil.writeValueAsIndentString(history));

    NavigableSet<BadQueryEntry> entries = history.getEntries();
    assertEquals(3, entries.size());

    BadQueryEntry entry1 = entries.first();
    assertEquals("Pushdown", entry1.getAdj());
    assertEquals("sandbox.hortonworks.com", entry1.getServer());
    assertEquals("select * from test_kylin_fact limit 10", entry1.getSql());

    entries.pollFirst();
    BadQueryEntry entry2 = entries.first();
    assertTrue(entry2.getStartTime() > entry1.getStartTime());
}
 
Example 2
Source File: BadQueryHistoryManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
public BadQueryHistory upsertEntryToProject(BadQueryEntry badQueryEntry, String project) throws IOException {
    if (StringUtils.isEmpty(project) || badQueryEntry.getAdj() == null || badQueryEntry.getSql() == null)
        throw new IllegalArgumentException();

    BadQueryHistory badQueryHistory = getBadQueriesForProject(project);
    NavigableSet<BadQueryEntry> entries = badQueryHistory.getEntries();
    
    entries.remove(badQueryEntry); // in case the entry already exists and this call means to update
    
    entries.add(badQueryEntry);
    
    int maxSize = kylinConfig.getBadQueryHistoryNum();
    if (entries.size() > maxSize) {
        entries.pollFirst();
    }

    getStore().checkAndPutResource(badQueryHistory.getResourcePath(), badQueryHistory, BAD_QUERY_INSTANCE_SERIALIZER);
    return badQueryHistory;
}
 
Example 3
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testDescendingRetainAll() {
    NavigableSet q = populatedSet(SIZE);
    NavigableSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.pollFirst();
    }
}
 
Example 4
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    NavigableSet q = populatedSet(SIZE);
    NavigableSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE-i, q.size());
        p.pollFirst();
    }
}
 
Example 5
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testDescendingRetainAll() {
    NavigableSet q = populatedSet(SIZE);
    NavigableSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE-i, q.size());
        p.pollFirst();
    }
}
 
Example 6
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testDescendingRetainAll() {
    NavigableSet q = populatedSet(SIZE);
    NavigableSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.pollFirst();
    }
}
 
Example 7
Source File: RecyclingAllocator.java    From sfs with Apache License 2.0 6 votes vote down vote up
public long allocNextAvailable(long length) {
    Range match = null;
    synchronized (mutex) {
        Map.Entry<Long, NavigableSet<Range>> entry = bySize.ceilingEntry(length);
        if (entry != null) {
            long numberOfBlocks = entry.getKey();
            NavigableSet<Range> sortedByPosition = entry.getValue();
            Preconditions.checkNotNull(sortedByPosition);
            match = sortedByPosition.pollFirst();
            Preconditions.checkNotNull(match);
            if (sortedByPosition.isEmpty()) {
                Preconditions.checkState(sortedByPosition == bySize.remove(numberOfBlocks));
            }
            Preconditions.checkState(match == byPosition.remove(match.getFirst()));
            numberOfFreeRanges.decrementAndGet();
        }
        Preconditions.checkNotNull(match);
        long position = match.getFirst();
        Range[] updated = match.remove(position, computeLast(position, length));
        for (Range update : updated) {
            putRange(update);
        }
        return position;
    }
}
 
Example 8
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    NavigableSet q = populatedSet(SIZE);
    NavigableSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.pollFirst();
    }
}
 
Example 9
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        NavigableSet q = populatedSet(SIZE);
        NavigableSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE-i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer I = (Integer)(p.pollFirst());
            assertFalse(q.contains(I));
        }
    }
}
 
Example 10
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    NavigableSet q = newNavigableSet();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
Example 11
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * size changes when elements added and removed
 */
public void testDescendingSize() {
    NavigableSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE-i, q.size());
        q.pollFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
Example 12
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    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)));
    }
}
 
Example 13
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    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)));
    }
}
 
Example 14
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        NavigableSet q = populatedSet(SIZE);
        NavigableSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE-i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer I = (Integer)(p.pollFirst());
            assertFalse(q.contains(I));
        }
    }
}
 
Example 15
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        NavigableSet q = populatedSet(SIZE);
        NavigableSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.pollFirst());
            assertFalse(q.contains(x));
        }
    }
}
 
Example 16
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    NavigableSet q = set0();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
Example 17
Source File: DefaultHalResourceCache.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void ensureCapacityLimit() {
  if (size() > getCapacity()) {
    List<HalResourceCacheEntry> resources = new ArrayList<HalResourceCacheEntry>(cache.values());
    NavigableSet<HalResourceCacheEntry> remainingResources = new TreeSet<HalResourceCacheEntry>(COMPARATOR);

    // remove expired resources
    for (HalResourceCacheEntry resource : resources) {
      if (expired(resource)) {
        remove(resource.getId());
      }
      else {
        remainingResources.add(resource);
      }

      if (size() <= getCapacity()) {
        // abort if capacity is reached
        return;
      }
    }

    // if still exceed capacity remove oldest
    while (remainingResources.size() > capacity) {
      HalResourceCacheEntry resourceToRemove = remainingResources.pollFirst();
      if (resourceToRemove != null) {
        remove(resourceToRemove.getId());
      }
      else {
        break;
      }
    }
  }
}
 
Example 18
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testDescendingRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        NavigableSet q = populatedSet(SIZE);
        NavigableSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE-i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer I = (Integer)(p.pollFirst());
            assertFalse(q.contains(I));
        }
    }
}
 
Example 19
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    NavigableSet q = set0();
    assertTrue(q.isEmpty());
    assertTrue(q.add(new Integer(1)));
    assertFalse(q.isEmpty());
    assertTrue(q.add(new Integer(2)));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
Example 20
Source File: AggregateImplementation.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Gives the sum for a given combination of column qualifier and column
 * family, in the given row range as defined in the Scan object. In its
 * current implementation, it takes one column family and one column qualifier
 * (if provided). In case of null column qualifier, sum for the entire column
 * family will be returned.
 */
@Override
public void getSum(RpcController controller, AggregateRequest request,
        RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  long sum = 0L;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null;
    T temp;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<>();
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        temp = ci.getValue(colFamily, qualifier, results.get(i));
        if (temp != null) {
          sumVal = ci.add(sumVal, ci.castToReturnType(temp));
        }
      }
      results.clear();
    } while (hasMoreRows);
    if (sumVal != null) {
      response = AggregateResponse.newBuilder().addFirstPart(
        ci.getProtoForPromotedType(sumVal).toByteString()).build();
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.debug("Sum from this region is "
      + env.getRegion().getRegionInfo().getRegionNameAsString() + ": " + sum);
  done.run(response);
}