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

The following examples show how to use java.util.NavigableSet#isEmpty() . 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: ContentOrderedEvaluator.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param sub
 *            current sored set being evaluated
 * @param skipped
 *            list of terms that were skipped for being out of order, sorted in the same order as the set
 * @param term
 *            current term that failed against the current found terms
 * @param direction
 *            1 == FORWARD, -1 == REVERSE
 * @param found
 *            updated as required, if subsequent traversal yields a match for all terms
 * @return number of found terms for the given criteria
 */
protected List<EvaluateTermPosition> traverseFailure(NavigableSet<EvaluateTermPosition> sub, List<EvaluateTermPosition> skipped, EvaluateTermPosition term,
                int direction, List<EvaluateTermPosition> found) {
    
    // Failure for current root node find next
    NavigableSet<EvaluateTermPosition> subB;
    if (!skipped.isEmpty()) {
        subB = sub.tailSet(skipped.get(0), true);
    } else {
        subB = sub.tailSet(term, true);
    }
    
    if (!subB.isEmpty()) { // Nothing after a, so it will fall out of the loop
        List<EvaluateTermPosition> results = traverse(subB, direction);
        if (null != results && results.size() == terms.length) {
            found.clear();
            found.addAll(results);
        }
        return results;
    }
    
    return null;
}
 
Example 3
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * A deserialized serialized set has same elements
 */
public void testDescendingSerialization() throws Exception {
    NavigableSet x = dset5();
    NavigableSet y = serialClone(x);

    assertNotSame(x, y);
    assertEquals(x.size(), y.size());
    assertEquals(x.toString(), y.toString());
    assertEquals(x, y);
    assertEquals(y, x);
    while (!x.isEmpty()) {
        assertFalse(y.isEmpty());
        assertEquals(x.pollFirst(), y.pollFirst());
    }
    assertTrue(y.isEmpty());
}
 
Example 4
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A deserialized serialized set has same elements
 */
public void testDescendingSerialization() throws Exception {
    NavigableSet x = dset5();
    NavigableSet y = serialClone(x);

    assertNotSame(x, y);
    assertEquals(x.size(), y.size());
    assertEquals(x.toString(), y.toString());
    assertEquals(x, y);
    assertEquals(y, x);
    while (!x.isEmpty()) {
        assertFalse(y.isEmpty());
        assertEquals(x.pollFirst(), y.pollFirst());
    }
    assertTrue(y.isEmpty());
}
 
Example 5
Source File: TreeSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A deserialized serialized set has same elements
 */
public void testSerialization() throws Exception {
    NavigableSet x = populatedSet(SIZE);
    NavigableSet y = serialClone(x);

    assertNotSame(x, y);
    assertEquals(x.size(), y.size());
    assertEquals(x, y);
    assertEquals(y, x);
    while (!x.isEmpty()) {
        assertFalse(y.isEmpty());
        assertEquals(x.pollFirst(), y.pollFirst());
    }
    assertTrue(y.isEmpty());
}
 
Example 6
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any get operation.
 * @param get The original get request
 * @return The modified get request with the family delete qualifiers represented
 */
private Get projectFamilyDeletes(Get get) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      get.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return get;
}
 
Example 7
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any get operation.
 * @param get The original get request
 * @return The modified get request with the family delete qualifiers represented
 */
private Get projectFamilyDeletes(Get get) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      get.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return get;
}
 
Example 8
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any get operation.
 * @param get The original get request
 * @return The modified get request with the family delete qualifiers represented
 */
private Get projectFamilyDeletes(Get get) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      get.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return get;
}
 
Example 9
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A deserialized serialized set has same elements
 */
public void testSerialization() throws Exception {
    NavigableSet x = populatedSet(SIZE);
    NavigableSet y = serialClone(x);

    assertNotSame(x, y);
    assertEquals(x.size(), y.size());
    assertEquals(x, y);
    assertEquals(y, x);
    while (!x.isEmpty()) {
        assertFalse(y.isEmpty());
        assertEquals(x.pollFirst(), y.pollFirst());
    }
    assertTrue(y.isEmpty());
}
 
Example 10
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any get operation.
 * @param get The original get request
 * @return The modified get request with the family delete qualifiers represented
 */
private Get projectFamilyDeletes(Get get) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      get.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return get;
}
 
Example 11
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any scan operation.
 * @param scan The original scan request
 * @return The modified scan request with the family delete qualifiers represented
 */
private Scan projectFamilyDeletes(Scan scan) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      scan.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return scan;
}
 
Example 12
Source File: FuzzyFieldProcessor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private boolean greaterScore(NavigableSet<MatchCandidate> matchCandidates, int score) {
  boolean isMaxScore = false;
  if (matchCandidates.isEmpty()) {
    isMaxScore = true;
  } else if (matchCandidates.last().getScore() < score) {
    isMaxScore = true;
  }
  return isMaxScore;
}
 
Example 13
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any scan operation.
 * @param scan The original scan request
 * @return The modified scan request with the family delete qualifiers represented
 */
private Scan projectFamilyDeletes(Scan scan) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      scan.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return scan;
}
 
Example 14
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * A deserialized serialized set has same elements
 */
public void testSerialization() throws Exception {
    NavigableSet x = populatedSet(SIZE);
    NavigableSet y = serialClone(x);

    assertNotSame(y, x);
    assertEquals(x.size(), y.size());
    assertEquals(x, y);
    assertEquals(y, x);
    while (!x.isEmpty()) {
        assertFalse(y.isEmpty());
        assertEquals(x.pollFirst(), y.pollFirst());
    }
    assertTrue(y.isEmpty());
}
 
Example 15
Source File: Program.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
static BitSet buildReachableBytecodesMask(byte[] code) {
    NavigableSet<Integer> gotos = new TreeSet<>();
    ByteCodeIterator it = new ByteCodeIterator(code);
    BitSet ret = new BitSet(code.length);
    int lastPush = 0;
    int lastPushPC = 0;
    do {
        ret.set(it.getPC()); // reachable bytecode
        if (it.isPush()) {
            lastPush = new BigInteger(1, it.getCurOpcodeArg()).intValue();
            lastPushPC = it.getPC();
        }
        if (it.getCurOpcode() == OpCode.JUMP || it.getCurOpcode() == OpCode.JUMPI) {
            if (it.getPC() != lastPushPC + 1) {
                // some PC arithmetic we totally can't deal with
                // assuming all bytecodes are reachable as a fallback
                ret.set(0, code.length);
                return ret;
            }
            int jumpPC = lastPush;
            if (!ret.get(jumpPC)) {
                // code was not explored yet
                gotos.add(jumpPC);
            }
        }
        if (it.getCurOpcode() == OpCode.JUMP || it.getCurOpcode() == OpCode.RETURN
                || it.getCurOpcode() == OpCode.STOP) {
            if (gotos.isEmpty()) {
                break;
            }
            it.setPC(gotos.pollFirst());
        }
    } while (it.next());
    return ret;
}
 
Example 16
Source File: ResourceParallelCopier.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
void divideGroups(NavigableSet<String> resources, String prefixSoFar, TreeMap<String, Integer> groupCollector) {
    if (resources.isEmpty())
        return;
    if (resources.size() <= groupSize) {
        String group = longestCommonPrefix(resources, prefixSoFar);
        groupCollector.put(group, resources.size());
        return;
    }

    // the resources set is too big, divide it
    TreeSet<String> newSet = new TreeSet<>();
    String newPrefix = null;
    int newPrefixLen = prefixSoFar.length() + 1;
    for (String path : resources) {
        String myPrefix = path.length() < newPrefixLen ? path : path.substring(0, newPrefixLen);
        if (newPrefix != null && !myPrefix.equals(newPrefix)) {
            // cut off last group
            divideGroups(newSet, newPrefix, groupCollector);
            newSet.clear();
            newPrefix = null;
        }

        if (newPrefix == null)
            newPrefix = myPrefix;

        newSet.add(path);
    }

    // the last group
    if (!newSet.isEmpty()) {
        divideGroups(newSet, newPrefix, groupCollector);
    }
}
 
Example 17
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * A deserialized serialized set has same elements
 */
public void testSerialization() throws Exception {
    NavigableSet x = populatedSet(SIZE);
    NavigableSet y = serialClone(x);

    assertNotSame(x, y);
    assertEquals(x.size(), y.size());
    assertEquals(x, y);
    assertEquals(y, x);
    while (!x.isEmpty()) {
        assertFalse(y.isEmpty());
        assertEquals(x.pollFirst(), y.pollFirst());
    }
    assertTrue(y.isEmpty());
}
 
Example 18
Source File: AggregateImplementation.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Gives the row count for the given column family and column qualifier, in
 * the given row range as defined in the Scan object.
 */
@Override
public void getRowNum(RpcController controller, AggregateRequest request,
        RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  long counter = 0L;
  List<Cell> results = new ArrayList<>();
  InternalScanner scanner = null;
  try {
    Scan scan = ProtobufUtil.toScan(request.getScan());
    byte[][] colFamilies = scan.getFamilies();
    byte[] colFamily = colFamilies != null ? colFamilies[0] : null;
    NavigableSet<byte[]> qualifiers = colFamilies != null ?
        scan.getFamilyMap().get(colFamily) : null;
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    if (scan.getFilter() == null && qualifier == null) {
      scan.setFilter(new FirstKeyOnlyFilter());
    }
    scanner = env.getRegion().getScanner(scan);
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      if (results.size() > 0) {
        counter++;
      }
      results.clear();
    } while (hasMoreRows);
    ByteBuffer bb = ByteBuffer.allocate(8).putLong(counter);
    bb.rewind();
    response = AggregateResponse.newBuilder().addFirstPart(
        ByteString.copyFrom(bb)).build();
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.info("Row counter from this region is "
      + env.getRegion().getRegionInfo().getRegionNameAsString() + ": " + counter);
  done.run(response);
}
 
Example 19
Source File: StepRenderer.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void performRender ( final Graphics g, final Rectangle clientRect )
{
    final XAxis xAxis = this.seriesData.getXAxis ();
    final YAxis yAxis = this.seriesData.getYAxis ();

    final NavigableSet<DataEntry> entries = this.seriesData.getViewData ().getEntries ();
    if ( entries.isEmpty () )
    {
        return;
    }

    final Path path = g.createPath ();
    try
    {
        boolean first = true;

        final DataPoint point = new DataPoint ();
        Float previousX = null;
        Float previousY = null;

        logger.trace ( "Render steps" );

        final long now = System.currentTimeMillis ();

        for ( final DataEntry entry : entries )
        {
            final boolean hasData = translateToPoint ( clientRect, xAxis, yAxis, point, entry );

            logger.trace ( "Entry - {}, hasData: {}, point: {}", new Object[] { entry, hasData, point } );

            final boolean skip = this.noFuture && entry.getTimestamp () > now;

            if ( hasData && !skip )
            {
                if ( first )
                {
                    first = false;
                    path.moveTo ( point.x, point.y );
                }
                else
                {
                    if ( previousX != null && previousX + 1 == point.x )
                    {
                        /* is the special case were we only advance one pixel.
                         * so we can draw a direct line and allow the
                         * antialiasing to kick in */

                        path.lineTo ( point.x, point.y );
                    }
                    else
                    {
                        path.lineTo ( point.x, previousY );
                        path.lineTo ( point.x, point.y );
                    }
                }
                previousX = point.x;
                previousY = point.y;
            }
            else
            {
                first = true;
                if ( previousY != null )
                {
                    path.lineTo ( point.x, previousY );
                    previousY = null;
                }
                previousX = null;
            }
        }

        g.setAlpha ( 255 );
        g.setLineAttributes ( this.lineAttributes );
        g.setForeground ( this.lineColor );
        g.setAntialias ( true );

        g.setClipping ( clientRect );
        g.drawPath ( path );
    }
    finally
    {
        path.dispose ();
    }
}
 
Example 20
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;
}