Example usage for java.util SortedSet iterator

List of usage examples for java.util SortedSet iterator

Introduction

In this page you can find the example usage for java.util SortedSet iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:org.apache.hadoop.hbase.regionserver.DefaultMemStore.java

private boolean walkForwardInSingleRow(final SortedSet<KeyValue> set, final KeyValue firstOnRow,
        final GetClosestRowBeforeTracker state) {
    boolean foundCandidate = false;
    SortedSet<KeyValue> tail = set.tailSet(firstOnRow);
    if (tail.isEmpty())
        return foundCandidate;
    for (Iterator<KeyValue> i = tail.iterator(); i.hasNext();) {
        KeyValue kv = i.next();/*from  w  w w . j  a  v  a  2  s .c  om*/
        // Did we go beyond the target row? If so break.
        if (state.isTooFar(kv, firstOnRow))
            break;
        if (state.isExpired(kv)) {
            i.remove();
            continue;
        }
        // If we added something, this row is a contender. break.
        if (state.handle(kv)) {
            foundCandidate = true;
            break;
        }
    }
    return foundCandidate;
}

From source file:de.interactive_instruments.ShapeChange.Target.Mapping.Excel.java

private int createAllPropertyDefinitions(PackageInfo asi, ClassInfo ci, boolean local) {
    if (ci == null)
        return 0;
    if (ci.pkg() == null) {
        result.addError(null, 139, ci.name());
        return 0;
    }/*from   w  w w . j  av  a 2  s .  co  m*/

    int ct = 0;

    SortedSet<String> st = ci.supertypes();
    if (st != null) {
        for (Iterator<String> i = st.iterator(); i.hasNext();) {
            ct += createAllPropertyDefinitions(asi, model.classById(i.next()), false);
        }
    }
    for (Iterator<PropertyInfo> j = ci.properties().values().iterator(); j.hasNext();) {
        PropertyInfo propi = j.next();
        ct += createPropertyDefinition(asi, ci, propi, local);
    }

    return ct;
}

From source file:org.apache.hyracks.storage.am.btree.OrderedIndexTestUtils.java

@SuppressWarnings("unchecked")
public void checkRangeSearch(IIndexTestContext ctx, ITupleReference lowKey, ITupleReference highKey,
        boolean lowKeyInclusive, boolean highKeyInclusive) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Testing Range Search.");
    }// w w w  . java 2s .  c  om
    MultiComparator lowKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), lowKey);
    MultiComparator highKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), highKey);
    IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false);
    RangePredicate rangePred = new RangePredicate(lowKey, highKey, lowKeyInclusive, highKeyInclusive, lowKeyCmp,
            highKeyCmp);
    ctx.getIndexAccessor().search(searchCursor, rangePred);
    // Get the subset of elements from the expected set within given key
    // range.
    CheckTuple lowKeyCheck = createCheckTupleFromTuple(lowKey, ctx.getFieldSerdes(),
            lowKeyCmp.getKeyFieldCount());
    CheckTuple highKeyCheck = createCheckTupleFromTuple(highKey, ctx.getFieldSerdes(),
            highKeyCmp.getKeyFieldCount());
    SortedSet<CheckTuple> expectedSubset = null;
    if (lowKeyCmp.getKeyFieldCount() < ctx.getKeyFieldCount()
            || highKeyCmp.getKeyFieldCount() < ctx.getKeyFieldCount()) {
        // Searching on a key prefix (low key or high key or both).
        expectedSubset = getPrefixExpectedSubset((TreeSet<CheckTuple>) ctx.getCheckTuples(), lowKeyCheck,
                highKeyCheck);
    } else {
        // Searching on all key fields.
        expectedSubset = ((TreeSet<CheckTuple>) ctx.getCheckTuples()).subSet(lowKeyCheck, lowKeyInclusive,
                highKeyCheck, highKeyInclusive);
    }
    Iterator<CheckTuple> checkIter = expectedSubset.iterator();
    int actualCount = 0;
    try {
        while (searchCursor.hasNext()) {
            if (!checkIter.hasNext()) {
                fail("Range search returned more answers than expected.\nExpected: " + expectedSubset.size());
            }
            searchCursor.next();
            CheckTuple expectedTuple = checkIter.next();
            ITupleReference tuple = searchCursor.getTuple();
            compareActualAndExpected(tuple, expectedTuple, ctx.getFieldSerdes());
            actualCount++;
        }
        if (actualCount < expectedSubset.size()) {
            fail("Range search returned fewer answers than expected.\nExpected: " + expectedSubset.size()
                    + "\nActual  : " + actualCount);
        }
    } finally {
        searchCursor.close();
    }
}

From source file:org.apache.hadoop.hbase.regionserver.Memcache.java

private void getRowKeyBefore(ConcurrentSkipListSet<KeyValue> set, KeyValue search,
        NavigableSet<KeyValue> candidates, final NavigableSet<KeyValue> deletes, final long now) {
    NavigableSet<KeyValue> headSet = set.headSet(search);
    // If we tried to create a headMap and got an empty map, then there are
    // no keys at or before the search key, so we're done.
    if (headSet.isEmpty()) {
        return;// w  w w . j  ava 2s . com
    }

    // If there aren't any candidate keys at this point, we need to search
    // backwards until we find at least one candidate or run out of headMap.
    if (candidates.isEmpty()) {
        KeyValue lastFound = null;
        for (Iterator<KeyValue> i = headSet.descendingIterator(); i.hasNext();) {
            KeyValue found = i.next();
            // if the last row we found a candidate key for is different than
            // the row of the current candidate, we can stop looking -- if its
            // not a delete record.
            boolean deleted = found.isDeleteType();
            if (lastFound != null && this.comparator.matchingRows(lastFound, found) && !deleted) {
                break;
            }
            // If this isn't a delete, record it as a candidate key. Also 
            // take note of this candidate so that we'll know when
            // we cross the row boundary into the previous row.
            if (!deleted) {
                if (Store.notExpiredAndNotInDeletes(this.ttl, found, now, deletes)) {
                    lastFound = found;
                    candidates.add(found);
                } else {
                    // Its expired.
                    Store.expiredOrDeleted(set, found);
                }
            } else {
                // We are encountering items in reverse.  We may have just added
                // an item to candidates that this later item deletes.  Check.  If we
                // found something in candidates, remove it from the set.
                if (Store.handleDeletes(found, candidates, deletes)) {
                    remove(set, found);
                }
            }
        }
    } else {
        // If there are already some candidate keys, we only need to consider
        // the very last row's worth of keys in the headMap, because any 
        // smaller acceptable candidate keys would have caused us to start
        // our search earlier in the list, and we wouldn't be searching here.
        SortedSet<KeyValue> rowTailMap = headSet.tailSet(headSet.last().cloneRow(HConstants.LATEST_TIMESTAMP));
        Iterator<KeyValue> i = rowTailMap.iterator();
        do {
            KeyValue found = i.next();
            if (found.isDeleteType()) {
                Store.handleDeletes(found, candidates, deletes);
            } else {
                if (ttl == HConstants.FOREVER || now < found.getTimestamp() + ttl || !deletes.contains(found)) {
                    candidates.add(found);
                } else {
                    Store.expiredOrDeleted(set, found);
                }
            }
        } while (i.hasNext());
    }
}

From source file:org.libreplan.web.limitingresources.LimitingResourceQueueModel.java

private LimitingResourceQueueElement getFirstChild(SortedSet<LimitingResourceQueueElement> elements) {
    return elements.isEmpty() ? null : elements.iterator().next();
}

From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaUtil.java

/**
 * Store a log in Alfresco of the result of the import
 * // w  w  w. ja  va  2  s.c  o m
 * @param site
 */

private void logDocuments(SiteInfo site, List<String> globalMessages) {
    NodeRef folderNodeRef = createFolder(logPath, null, null, site);

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String currentDate = formatter.format(new Date());
    formatter = new SimpleDateFormat("yyyy-MM-dd HHmmss");
    String fileName = formatter.format(new Date()) + " Import.log";

    StringBuilder common = new StringBuilder();
    StringBuilder logged = new StringBuilder();

    Iterator<String> globalIt = globalMessages.iterator();
    while (globalIt.hasNext()) {
        String next = globalIt.next();
        logged.append(next + LINE_BREAK);
    }
    int failedCount = 0;
    SortedSet<ByggRedaDocument> sortedDocuments = new TreeSet<ByggRedaDocument>(new ByggRedaOrderComparator());
    sortedDocuments.addAll(documents);
    Iterator<ByggRedaDocument> it = sortedDocuments.iterator();
    while (it.hasNext()) {
        ByggRedaDocument next = it.next();
        if (!next.isReadSuccessfully()) {
            failedCount++;
        }
        if (!next.isReadSuccessfully() || StringUtils.hasText(next.getStatusMsg())) {
            logged.append("#" + next.getLineNumber() + " - " + next.getRecordDisplay() + " - "
                    + next.getBuildingDescription() + ": " + next.getStatusMsg() + LINE_BREAK);
        }
    }
    common.append("Sammastllning av importkrning " + LINE_BREAK);
    common.append("--------------------------" + LINE_BREAK);
    common.append("Datum/tidpunkt: " + currentDate + LINE_BREAK);
    common.append("Antal inlsta dokument frn styrfil: " + documents.size() + LINE_BREAK);
    common.append("Lyckade inlsningar: " + (documents.size() - failedCount) + LINE_BREAK);
    common.append("Misslyckade inlsningar: " + failedCount + LINE_BREAK);
    common.append("--------------------------" + LINE_BREAK + LINE_BREAK);
    if (logged.length() > 0) {
        common.append("Loggmeddelanden:" + LINE_BREAK);
        common.append("--------------------------" + LINE_BREAK);
        common.append(logged);
        common.append("--------------------------" + LINE_BREAK);
    }
    FileInfo fileInfo = fileFolderService.create(folderNodeRef, fileName, AkDmModel.TYPE_AKDM_DOCUMENT);

    logMessage = common.toString();
    try {
        InputStream is = new ByteArrayInputStream(common.toString().getBytes("UTF-8"));
        try {
            final ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(),
                    ContentModel.PROP_CONTENT, true);

            writer.setMimetype("text/plain");

            writer.putContent(is);
        } finally {
            IOUtils.closeQuietly(is);
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        LOG.error("Error while creating log file, Unsupported Encoding", e);
    }
}

From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java

private void printOptionsForm(PrintWriter printWriter, SortedMap inputOptions, String formId,
        String submitMethod, String submitLabel) {
    SortedSet tempSet = new TreeSet();
    for (Iterator entryIter = inputOptions.entrySet().iterator(); entryIter.hasNext();) {
        Entry tempEntry = (Entry) entryIter.next();
        tempSet.add(tempEntry.getValue().toString() + Character.MAX_VALUE + tempEntry.getKey().toString());
    }//  w w  w. ja  va 2 s  . c om

    printWriter.println(
            "<select class='select' name='pid' id='" + formId + "' onChange='" + submitMethod + "();'>");
    for (Iterator treeIter = tempSet.iterator(); treeIter.hasNext();) {
        String nextEntry = (String) treeIter.next();
        int specChar = nextEntry.indexOf(Character.MAX_VALUE);
        String partialEntry = nextEntry.substring(0, specChar);
        String entryKey = nextEntry.substring(specChar + STRING_FORWARD);
        printWriter.print("<option value='" + entryKey + "'>");
        printWriter.print(partialEntry);
        printWriter.println("</option>");
    }
    printWriter.println("</select>");
    printWriter.println("&nbsp;&nbsp;");
    printWriter.println("<input class='submit' type='button' value='" + submitLabel + "' onClick='"
            + submitMethod + "();' />");

}

From source file:org.apache.geode.pdx.internal.PdxInstanceImpl.java

@Override
public boolean equals(Object obj) {
    if (obj == this)
        return true;

    if (obj == null) {
        // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#0 o1=<" + this + "> o2=<" +
        // obj + ">");
        return false;
    }/* w w  w  .  j  av  a  2 s .c o  m*/
    if (!(obj instanceof PdxInstanceImpl)) {
        // if (!result) {
        // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#1 o1=<" + this + "> o2=<" +
        // obj + ">");
        // }
        return false;
    }
    final PdxInstanceImpl other = (PdxInstanceImpl) obj;
    PdxReaderImpl ur2 = other.getUnmodifiableReader();
    PdxReaderImpl ur1 = getUnmodifiableReader();

    if (!ur1.getPdxType().getClassName().equals(ur2.getPdxType().getClassName())) {
        // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#2 o1=<" + this + "> o2=<" +
        // obj + ">");
        return false;
    }

    SortedSet<PdxField> myFields = ur1.getPdxType().getSortedIdentityFields();
    SortedSet<PdxField> otherFields = ur2.getPdxType().getSortedIdentityFields();
    if (!myFields.equals(otherFields)) {
        // It is not ok to modify myFields and otherFields in place so make copies
        myFields = new TreeSet<PdxField>(myFields);
        otherFields = new TreeSet<PdxField>(otherFields);
        addDefaultFields(myFields, otherFields);
        addDefaultFields(otherFields, myFields);
    }

    Iterator<PdxField> myFieldIterator = myFields.iterator();
    Iterator<PdxField> otherFieldIterator = otherFields.iterator();
    while (myFieldIterator.hasNext()) {
        PdxField myType = myFieldIterator.next();
        PdxField otherType = otherFieldIterator.next();

        switch (myType.getFieldType()) {
        case CHAR:
        case BOOLEAN:
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case DATE:
        case FLOAT:
        case DOUBLE:
        case STRING:
        case BOOLEAN_ARRAY:
        case CHAR_ARRAY:
        case BYTE_ARRAY:
        case SHORT_ARRAY:
        case INT_ARRAY:
        case LONG_ARRAY:
        case FLOAT_ARRAY:
        case DOUBLE_ARRAY:
        case STRING_ARRAY:
        case ARRAY_OF_BYTE_ARRAYS: {
            ByteSource myBuffer = ur1.getRaw(myType);
            ByteSource otherBuffer = ur2.getRaw(otherType);
            if (!myBuffer.equals(otherBuffer)) {
                // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#4 o1=<" + this + ">
                // o2=<" + obj + ">");
                return false;
            }
        }
            break;

        case OBJECT_ARRAY: {
            Object[] myArray = ur1.readObjectArray(myType);
            Object[] otherArray = ur2.readObjectArray(otherType);
            if (!Arrays.deepEquals(myArray, otherArray)) {
                // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#5 o1=<" + this + ">
                // o2=<" + obj + ">");
                return false;
            }
        }
            break;

        case OBJECT: {
            Object myObject = ur1.readObject(myType);
            Object otherObject = ur2.readObject(otherType);
            if (myObject != otherObject) {
                if (myObject == null) {
                    // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#6 o1=<" + this + ">
                    // o2=<" + obj + ">");
                    return false;
                }
                if (otherObject == null) {
                    // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#7 o1=<" + this + ">
                    // o2=<" + obj + ">");
                    return false;
                }
                if (myObject.getClass().isArray()) { // for bug 42976
                    Class<?> myComponentType = myObject.getClass().getComponentType();
                    Class<?> otherComponentType = otherObject.getClass().getComponentType();
                    if (!myComponentType.equals(otherComponentType)) {
                        // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#8 o1=<" + this + ">
                        // o2=<" + obj + ">");
                        return false;
                    }
                    if (myComponentType.isPrimitive()) {
                        ByteSource myBuffer = getRaw(myType);
                        ByteSource otherBuffer = other.getRaw(otherType);
                        if (!myBuffer.equals(otherBuffer)) {
                            // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#9 o1=<" + this +
                            // "> o2=<" + obj + ">");
                            return false;
                        }
                    } else {
                        if (!Arrays.deepEquals((Object[]) myObject, (Object[]) otherObject)) {
                            // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#10 o1=<" + this +
                            // "> o2=<" + obj + ">");
                            return false;
                        }
                    }
                } else if (!myObject.equals(otherObject)) {
                    // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#11 fn=" +
                    // myType.getFieldName() + " myFieldClass=" + myObject.getClass() + "
                    // otherFieldCLass=" + otherObject.getClass() + " o1=<" + this + "> o2=<" + obj + ">"
                    // + "myObj=<" + myObject + "> otherObj=<" + otherObject + ">");
                    return false;
                }
            }
        }
            break;

        default:
            throw new InternalGemFireException("Unhandled field type " + myType.getFieldType());
        }
    }
    return true;
}

From source file:de.uni_potsdam.hpi.asg.logictool.mapping.SequenceBasedAndGateDecomposer.java

private void removeSubSequences(SortedSet<IOBehaviour> sequencesFront, SortedSet<IOBehaviour> sequencesBack,
        Set<IOBehaviour> newSequences, Set<IOBehaviour> rmSequences) {
    rmSequences.clear();/*from   w  w w.j  ava 2  s  . c  o m*/
    sequencesFront.addAll(newSequences);
    Iterator<IOBehaviour> it = sequencesFront.iterator();
    if (!it.hasNext()) {
        //TODO: why?
        return;
    }
    IOBehaviour curr = it.next();
    while (it.hasNext()) {
        IOBehaviour next = it.next();
        if (newSequences.contains(curr)) {
            if (curr.getStart().compareTo(next.getStart()) == 0) {
                int i = 0;
                while (true) {
                    if (curr.getSequence().size() == i) {
                        rmSequences.add(curr);
                        break;
                    }
                    //System.out.println(curr.toString() + " vs " + next.toString());
                    int cmpT = curr.getSequence().get(i).compareTo(next.getSequence().get(i));
                    if (cmpT != 0) {
                        break;
                    }
                    //gleich, check next trans
                    i++;
                }
            }
        }
        curr = next;
    }
    newSequences.removeAll(rmSequences);
    sequencesBack.addAll(newSequences);
    it = sequencesBack.iterator();
    curr = it.next();
    while (it.hasNext()) {
        IOBehaviour next = it.next();
        if (newSequences.contains(curr)) {
            if (curr.getEnd().compareTo(next.getEnd()) == 0) {
                int i = 0;
                while (true) {
                    if (curr.getSequence().size() == i) {
                        rmSequences.add(curr);
                        break;
                    }
                    int cmpT = curr.getSequence().get(curr.getSequence().size() - i - 1)
                            .compareTo(next.getSequence().get(next.getSequence().size() - i - 1));
                    if (cmpT != 0) {
                        break;
                    }
                    //gleich, check next trans
                    i++;
                }
            }
        }
        curr = next;
    }
}

From source file:net.sf.jasperreports.engine.fill.JRFillChart.java

/**
 * The series colors set in the main plot of a multiple axis chart are used for
 * all the rendered charts in the plot.  This is a problem with multiple line
 * charts, using different scales and thus different axis.  All the lines will
 * be drawn using the first series color (since they are the first series for that
 * rendered) and it will be impossible to tell them apart.
 * <br><br>//from   w  ww  .  j a va  2  s  .  co  m
 * For this reason we interpret series colors for charts included in a multiple
 * axis chart as specify absolute series colors for that renderer.
 *
 * @param renderer the renderer of the chart being created
 * @param jrPlot the Jasper view of that plot
 */
private void configureAxisSeriesColors(CategoryItemRenderer renderer, JRChartPlot jrPlot) {
    SortedSet<JRSeriesColor> seriesColors = jrPlot.getSeriesColors();

    if (seriesColors != null) {
        Iterator<JRSeriesColor> iter = seriesColors.iterator();
        while (iter.hasNext()) {
            JRSeriesColor seriesColor = iter.next();
            renderer.setSeriesPaint(seriesColor.getSeriesOrder(), seriesColor.getColor());
        }
    }
}