java.util.NavigableSet# pollFirst ( ) 源码实例Demo

下面列出了java.util.NavigableSet# pollFirst ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


@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());
}
 
源代码2 项目: openjdk-jdk9   文件: TreeSubSetTest.java

/**
 * 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();
    }
}
 
源代码3 项目: sfs   文件: RecyclingAllocator.java

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;
    }
}
 

/**
 * 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();
    }
}
 

/**
 * 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();
    }
}
 

/**
 * 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();
    }
}
 

/**
 * 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();
    }
}
 
源代码8 项目: kylin   文件: BadQueryHistoryManager.java

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;
}
 
源代码9 项目: j2objc   文件: TreeSubSetTest.java

/**
 * 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());
}
 
源代码10 项目: scava   文件: BTreeMapSubSetTest.java

/**
 * 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));
        }
    }
}
 

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;
      }
    }
  }
}
 
源代码12 项目: openjdk-jdk9   文件: TreeSubSetTest.java

/**
 * 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)));
    }
}
 
源代码13 项目: scava   文件: BTreeSet2Test.java

/**
 * 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));
        }
    }
}
 
源代码14 项目: scava   文件: BTreeSet2Test.java

/**
 * 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());
}
 

/**
 * 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));
    }
}
 

/**
 * 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)));
    }
}
 
源代码17 项目: scava   文件: BTreeMapSubSetTest.java

/**
 * 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));
        }
    }
}
 

/**
 * 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));
        }
    }
}
 

/**
 * 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());
}
 
源代码20 项目: hbase   文件: AggregateImplementation.java

/**
 * 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);
}