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

The following examples show how to use java.util.NavigableSet#last() . 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: TDFATransitionTable.java    From tree-regex with Apache License 2.0 6 votes vote down vote up
NextDFAState availableTransition(DFAState t, char a) {
  final Integer fromState = mapping.mapping.get(t);
  if (fromState == null) {
    return null;
  }
  final Builder.Entry probe = new Entry(a, a, null, fromState, -1, null);
  final NavigableSet<Builder.Entry> headSet = transitions.headSet(probe, true);
  if (headSet.isEmpty()) {
    return null;
  }
  final Builder.Entry found = headSet.last();
  if (found.state != probe.state || !(found.from <= a && a <= found.to)) {
    return null;
  }

  return new NextDFAState(found.instructions, found.toDFA);
}
 
Example 2
Source File: BadQueryHistoryManagerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddEntryToProject() throws IOException {
    KylinConfig kylinConfig = getTestConfig();
    BadQueryHistoryManager manager = BadQueryHistoryManager.getInstance(kylinConfig);
    BadQueryEntry entry = new BadQueryEntry("sql", "adj", 1459362239992L, 100, "server", "t-0", "user",
            RandomUtil.randomUUID().toString(), "cube");
    BadQueryHistory history = manager.upsertEntryToProject(entry, "default");
    NavigableSet<BadQueryEntry> entries = history.getEntries();
    assertEquals(4, entries.size());

    BadQueryEntry newEntry = entries.last();

    System.out.println(newEntry);
    assertEquals("sql", newEntry.getSql());
    assertEquals("adj", newEntry.getAdj());
    assertEquals(1459362239992L, newEntry.getStartTime());
    assertEquals("server", newEntry.getServer());
    assertEquals("user", newEntry.getUser());
    assertEquals("t-0", newEntry.getThread());

    for (int i = 0; i < kylinConfig.getBadQueryHistoryNum(); i++) {
        BadQueryEntry tmp = new BadQueryEntry("sql", "adj", 1459362239993L + i, 100 + i, "server", "t-0", "user",
                RandomUtil.randomUUID().toString(), "cube");
        history = manager.upsertEntryToProject(tmp, "default");
    }
    assertEquals(kylinConfig.getBadQueryHistoryNum(), history.getEntries().size());
}
 
Example 3
Source File: ArtifactRetriever.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the most recent version of the artifact in the repo,
 * possibly a beta, alpha, or pre-release but not a snapshot version.
 */
public ArtifactVersion getLatestVersion(String groupId, String artifactId) {
  String coordinates = idToKey(groupId, artifactId);
  try {
    NavigableSet<ArtifactVersion> versions = availableVersions.get(coordinates);
    return versions.last();
  } catch (ExecutionException ex) {
    logger.log(
        Level.WARNING,
        "Could not retrieve version for artifact " + coordinates,
        ex.getCause());
    return null;
  }
}
 
Example 4
Source File: BadQueryHistoryManagerTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddEntryToProject() throws IOException {
    KylinConfig kylinConfig = getTestConfig();
    BadQueryHistoryManager manager = BadQueryHistoryManager.getInstance(kylinConfig);
    BadQueryEntry entry = new BadQueryEntry("sql", "adj", 1459362239992L, 100, "server", "t-0", "user",
            RandomUtil.randomUUID().toString(), "cube");
    BadQueryHistory history = manager.upsertEntryToProject(entry, "default");
    NavigableSet<BadQueryEntry> entries = history.getEntries();
    assertEquals(4, entries.size());

    BadQueryEntry newEntry = entries.last();

    System.out.println(newEntry);
    assertEquals("sql", newEntry.getSql());
    assertEquals("adj", newEntry.getAdj());
    assertEquals(1459362239992L, newEntry.getStartTime());
    assertEquals("server", newEntry.getServer());
    assertEquals("user", newEntry.getUser());
    assertEquals("t-0", newEntry.getThread());

    for (int i = 0; i < kylinConfig.getBadQueryHistoryNum(); i++) {
        BadQueryEntry tmp = new BadQueryEntry("sql", "adj", 1459362239993L + i, 100 + i, "server", "t-0", "user",
                RandomUtil.randomUUID().toString(), "cube");
        history = manager.upsertEntryToProject(tmp, "default");
    }
    assertEquals(kylinConfig.getBadQueryHistoryNum(), history.getEntries().size());
}
 
Example 5
Source File: IndexSegmentTest.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Adds ttl update entries to {@code segment}.
 * @param idsToTtlUpdate the {@link Set} of IDs to create ttl update entries for.
 * @param segment the {@link IndexSegment} to add the entries to.
 * @param referenceIndex the {@link NavigableMap} to add all the entries to. This represents the source of truth for
 *                       all checks.
 * @throws StoreException
 */
private void addTtlUpdateEntries(Set<MockId> idsToTtlUpdate, IndexSegment segment,
    NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex) throws StoreException {
  for (MockId id : idsToTtlUpdate) {
    Offset offset = segment.getEndOffset();
    NavigableSet<IndexValue> values = segment.find(id);
    IndexValue value;
    if (values == null) {
      // create an index value with a random log segment name
      value = IndexValueTest.getIndexValue(1, new Offset(TestUtils.getRandomString(1), 0), Utils.Infinite_Time,
          time.milliseconds(), id.getAccountId(), id.getContainerId(), (short) 1, formatVersion);
    } else if (values.last().isDelete()) {
      throw new IllegalArgumentException(id + " is deleted");
    } else if (values.last().isTtlUpdate()) {
      throw new IllegalArgumentException("TTL of " + id + " is already updated");
    } else {
      value = values.last();
    }
    IndexValue newValue = IndexValueTest.getIndexValue(value, formatVersion);
    newValue.setFlag(IndexValue.Flags.Ttl_Update_Index);
    newValue.setExpiresAtMs(Utils.Infinite_Time);
    newValue.setNewOffset(offset);
    newValue.setNewSize(TTL_UPDATE_FILE_SPAN_SIZE);
    segment.addEntry(new IndexEntry(id, newValue),
        new Offset(offset.getName(), offset.getOffset() + TTL_UPDATE_FILE_SPAN_SIZE));
    referenceIndex.computeIfAbsent(id, k -> new TreeSet<>()).add(newValue);
  }
}
 
Example 6
Source File: ThreadStatusDataProvider.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create the list of arrows to follow the current thread on a CPU
 *
 * @param trace
 *            trace displayed in the view
 * @param entryList
 *            entry list for this trace
 * @param intervals
 *            sorted collection of the current thread intervals for a CPU
 * @return the list of arrows to follow the current thread on a CPU
 * @throws StateSystemDisposedException
 *             If the query is sent after the state system has been disposed
 */
private List<@NonNull TimeGraphArrow> createCpuArrows(ITmfStateSystem ss, NavigableSet<ITmfStateInterval> intervals)
        throws StateSystemDisposedException {
    if (intervals.isEmpty()) {
        return Collections.emptyList();
    }
    /*
     * Add the previous interval if it is the first query iteration and the first
     * interval has currentThread=0. Add the following interval if the last interval
     * has currentThread=0. These are diagonal arrows crossing the query iteration
     * range.
     */
    ITmfStateInterval first = intervals.first();
    long start = first.getStartTime() - 1;
    if (start >= ss.getStartTime() && Objects.equals(first.getValue(), 0)) {
        intervals.add(ss.querySingleState(start, first.getAttribute()));
    }
    ITmfStateInterval last = intervals.last();
    long end = last.getEndTime() + 1;
    if (end <= ss.getCurrentEndTime() && Objects.equals(last.getValue(), 0)) {
        intervals.add(ss.querySingleState(end, last.getAttribute()));
    }

    List<@NonNull TimeGraphArrow> linkList = new ArrayList<>();
    long prevEnd = 0;
    long lastEnd = 0;
    long prevEntry = -1;
    for (ITmfStateInterval currentThreadInterval : intervals) {
        long time = currentThreadInterval.getStartTime();
        if (time != lastEnd) {
            /*
             * Don't create links where there are gaps in intervals due to the resolution
             */
            prevEntry = -1;
            prevEnd = 0;
        }
        Integer tid = (Integer) currentThreadInterval.getValue();
        lastEnd = currentThreadInterval.getEndTime() + 1;
        long nextEntry = -1;
        if (tid != null && tid > 0) {
            nextEntry = findEntry(tid, time);
            if (prevEntry >= 0 && nextEntry >= 0) {
                TimeGraphArrow arrow = new TimeGraphArrow(prevEntry, nextEntry, prevEnd, time - prevEnd, getElementStyle(LINK_VALUE));
                linkList.add(arrow);
            }
            prevEntry = nextEntry;
            prevEnd = lastEnd;
        }
    }
    return linkList;
}
 
Example 7
Source File: AsyncAggregationClient.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static <R, S, P extends Message, Q extends Message, T extends Message> void findMedian(
        CompletableFuture<R> future, AsyncTable<AdvancedScanResultConsumer> table,
        ColumnInterpreter<R, S, P, Q, T> ci, Scan scan, NavigableMap<byte[], S> sumByRegion) {
  double halfSum = ci.divideForAvg(sumByRegion.values().stream().reduce(ci::add).get(), 2L);
  S movingSum = null;
  byte[] startRow = null;
  for (Map.Entry<byte[], S> entry : sumByRegion.entrySet()) {
    startRow = entry.getKey();
    S newMovingSum = ci.add(movingSum, entry.getValue());
    if (ci.divideForAvg(newMovingSum, 1L) > halfSum) {
      break;
    }
    movingSum = newMovingSum;
  }
  if (startRow != null) {
    scan.withStartRow(startRow);
  }
  // we can not pass movingSum directly to an anonymous class as it is not final.
  S baseSum = movingSum;
  byte[] family = scan.getFamilies()[0];
  NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(family);
  byte[] weightQualifier = qualifiers.last();
  byte[] valueQualifier = qualifiers.first();
  table.scan(scan, new AdvancedScanResultConsumer() {
    private S sum = baseSum;

    private R value = null;

    @Override
    public void onNext(Result[] results, ScanController controller) {
      try {
        for (Result result : results) {
          Cell weightCell = result.getColumnLatestCell(family, weightQualifier);
          R weight = ci.getValue(family, weightQualifier, weightCell);
          sum = ci.add(sum, ci.castToReturnType(weight));
          if (ci.divideForAvg(sum, 1L) > halfSum) {
            if (value != null) {
              future.complete(value);
            } else {
              future.completeExceptionally(new NoSuchElementException());
            }
            controller.terminate();
            return;
          }
          Cell valueCell = result.getColumnLatestCell(family, valueQualifier);
          value = ci.getValue(family, valueQualifier, valueCell);
        }
      } catch (IOException e) {
        future.completeExceptionally(e);
        controller.terminate();
      }
    }

    @Override
    public void onError(Throwable error) {
      future.completeExceptionally(error);
    }

    @Override
    public void onComplete() {
      if (!future.isDone()) {
        // we should not reach here as the future should be completed in onNext.
        future.completeExceptionally(new NoSuchElementException());
      }
    }
  });
}