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:com.plancake.api.client.PlancakeApiClient.java

/**
*
* @param array params - including token/*from   ww  w. j av a  2 s. co  m*/
* @param string $methodName
* @return string
*/
private String getSignatureForRequest(Map<String, String> params, String methodName)
        throws UnsupportedEncodingException, NoSuchAlgorithmException {
    SortedSet<String> sortedSet = new TreeSet<String>(params.keySet());

    Iterator<String> it = sortedSet.iterator();

    String s = methodName;

    while (it.hasNext()) {
        String paramKey = it.next();
        String paramValue = (String) params.get(paramKey);
        s += paramKey + paramValue;
    }

    s += this.apiSecret;

    return Utils.md5(s);
}

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

/**
 * Inserts the specified KeyValue into MemStore and deletes any existing
 * versions of the same row/family/qualifier as the specified KeyValue.
 * <p>// w  ww  . j a  v  a  2s.  c o  m
 * First, the specified KeyValue is inserted into the Memstore.
 * <p>
 * If there are any existing KeyValues in this MemStore with the same row,
 * family, and qualifier, they are removed.
 * <p>
 * Callers must hold the read lock.
 *
 * @param kv
 * @return change in size of MemStore
 */
private long upsert(KeyValue kv) {
    // Add the KeyValue to the MemStore
    // Use the internalAdd method here since we (a) already have a lock
    // and (b) cannot safely use the MSLAB here without potentially
    // hitting OOME - see TestMemStore.testUpsertMSLAB for a
    // test that triggers the pathological case if we don't avoid MSLAB
    // here.
    long addedSize = internalAdd(kv);

    // Get the KeyValues for the row/family/qualifier regardless of timestamp.
    // For this case we want to clean up any other puts
    KeyValue firstKv = KeyValue.createFirstOnRow(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength(),
            kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength(), kv.getBuffer(), kv.getQualifierOffset(),
            kv.getQualifierLength());
    SortedSet<KeyValue> ss = kvset.tailSet(firstKv);
    Iterator<KeyValue> it = ss.iterator();
    while (it.hasNext()) {
        KeyValue cur = it.next();

        if (kv == cur) {
            // ignore the one just put in
            continue;
        }
        // if this isn't the row we are interested in, then bail
        if (!kv.matchingRow(cur)) {
            break;
        }

        // if the qualifier matches and it's a put, remove it
        if (kv.matchingQualifier(cur)) {

            // to be extra safe we only remove Puts that have a memstoreTS==0
            if (kv.getType() == KeyValue.Type.Put.getCode() && kv.getMemstoreTS() == 0) {
                // false means there was a change, so give us the size.
                addedSize -= heapSizeChange(kv, true);
                it.remove();
            }
        } else {
            // past the column, done
            break;
        }
    }
    return addedSize;
}

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

/**
 * Given the specs of a column, update it, first by inserting a new record,
 * then removing the old one.  Since there is only 1 KeyValue involved, the memstoreTS
 * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying
 * store will ensure that the insert/delete each are atomic. A scanner/reader will either
 * get the new value, or the old value and all readers will eventually only see the new
 * value after the old was removed./*from  w  w w .j a v  a  2 s  .  c  om*/
 *
 * @param row
 * @param family
 * @param qualifier
 * @param newValue
 * @param now
 * @return  Timestamp
 */
public long updateColumnValue(byte[] row, byte[] family, byte[] qualifier, long newValue, long now) {
    this.lock.readLock().lock();
    try {
        KeyValue firstKv = KeyValue.createFirstOnRow(row, family, qualifier);
        // Is there a KeyValue in 'snapshot' with the same TS? If so, upgrade the timestamp a bit.
        SortedSet<KeyValue> snSs = snapshot.tailSet(firstKv);
        if (!snSs.isEmpty()) {
            KeyValue snKv = snSs.first();
            // is there a matching KV in the snapshot?
            if (snKv.matchingRow(firstKv) && snKv.matchingQualifier(firstKv)) {
                if (snKv.getTimestamp() == now) {
                    // poop,
                    now += 1;
                }
            }
        }

        // logic here: the new ts MUST be at least 'now'. But it could be larger if necessary.
        // But the timestamp should also be max(now, mostRecentTsInMemstore)

        // so we cant add the new KV w/o knowing what's there already, but we also
        // want to take this chance to delete some kvs. So two loops (sad)

        SortedSet<KeyValue> ss = kvset.tailSet(firstKv);
        Iterator<KeyValue> it = ss.iterator();
        while (it.hasNext()) {
            KeyValue kv = it.next();

            // if this isnt the row we are interested in, then bail:
            if (!kv.matchingColumn(family, qualifier) || !kv.matchingRow(firstKv)) {
                break; // rows dont match, bail.
            }

            // if the qualifier matches and it's a put, just RM it out of the kvset.
            if (kv.getType() == KeyValue.Type.Put.getCode() && kv.getTimestamp() > now
                    && firstKv.matchingQualifier(kv)) {
                now = kv.getTimestamp();
            }
        }

        // create or update (upsert) a new KeyValue with
        // 'now' and a 0 memstoreTS == immediately visible
        return upsert(Arrays.asList(new KeyValue(row, family, qualifier, now, Bytes.toBytes(newValue))));
    } finally {
        this.lock.readLock().unlock();
    }
}

From source file:com.aurel.track.admin.customize.category.report.execute.ReportBeansToXML.java

private Element createLinkElement(SortedSet<ReportBeanLink> linkSet,
        Map<Integer, ILinkType> linkTypeIDToLinkTypeMap, Locale locale, Document dom) {
    if (linkSet != null && !linkSet.isEmpty()) {
        Element links = dom.createElement("links");
        Iterator<ReportBeanLink> iterator = linkSet.iterator();
        while (iterator.hasNext()) {
            ReportBeanLink reportBeanLink = iterator.next();
            Element linkElement = dom.createElement("link");
            linkElement.appendChild(createDomElement("linkTypeName", reportBeanLink.getLinkTypeName(), dom));
            if (reportBeanLink.getLinkDirection() != null) {
                linkElement.appendChild(
                        createDomElement("linkDirection", reportBeanLink.getLinkDirection().toString(), dom));
            }//from   w  w  w.  java2 s  .  co m
            if (reportBeanLink.getWorkItemID() != null) {
                linkElement.appendChild(
                        createDomElement("issueNo", reportBeanLink.getWorkItemID().toString(), dom));
            }
            Map<String, String> itemLinkSpecificMap = getLinkSpecificData(reportBeanLink,
                    linkTypeIDToLinkTypeMap, locale);
            if (itemLinkSpecificMap != null) {
                for (Map.Entry<String, String> entry : itemLinkSpecificMap.entrySet()) {
                    linkElement.appendChild(createDomElement(entry.getKey(), entry.getValue(), dom));
                }
            }
            links.appendChild(linkElement);
        }
        return links;
    }
    return null;
}

From source file:org.alfresco.reporting.db.DatabaseHelperBean.java

public void init() {
    if (logger.isInfoEnabled())
        logger.info("Starting init - " + reportingHelper.getDatabaseProvider());

    try {/*w  ww.j  av  a2 s.c o m*/
        Map<String, String> p = getShowTables();
        SortedSet<String> ss = new TreeSet<String>(p.keySet());
        Iterator<String> keys = ss.iterator();
        if (ss.size() == 0) {
            logger.info("  No reporting tables to display...");
        } else {
            while (keys.hasNext()) {
                String key = (String) keys.next();
                logger.info("  " + key + " (" + p.get(key) + ")");
            }
        } // end if ss.size()         
    } catch (Exception e) {
        logger.warn("Reporting table information could not be retrieved!!");
        logger.fatal("Exception was: " + e.getMessage());
    }

}

From source file:org.apache.cocoon.acting.DatabaseAddAction.java

/**
 * Inserts a row or a set of rows into the given table based on the
 * request parameters/*ww  w.j  a v a  2  s. c  o  m*/
 *
 * @param table the table's configuration
 * @param conn the database connection
 * @param request the request
 */
void processTable(Configuration table, Connection conn, Request request, Map results)
        throws SQLException, ConfigurationException, Exception {
    PreparedStatement statement = null;
    try {
        String query = this.getAddQuery(table);
        getLogger().debug("Add query: " + query);
        statement = conn.prepareStatement(query);
        Configuration[] keys = table.getChild("keys").getChildren("key");
        Configuration[] values = table.getChild("values").getChildren("value");
        int currentIndex = 1;
        boolean manyrows = false;
        int wildcardIndex = -1;
        String wildcardParam = null;
        for (int i = 0; i < keys.length; i++) {
            wildcardParam = keys[i].getAttribute("param");
            if ((wildcardIndex = wildcardParam.indexOf('*')) != -1) {
                manyrows = true;
                break;
            }
        }
        if (manyrows) {
            /**
             * This table has a column with a wildcard, so we're going
             * to be inserting n rows, where 0 <= n
             */
            String prefix = wildcardParam.substring(0, wildcardIndex);
            String suffix = StringUtils.substring(wildcardParam, wildcardIndex + 1);
            Enumeration names = request.getParameterNames();
            SortedSet matchset = new TreeSet();
            int prefixLength = prefix.length();
            int length = prefixLength + suffix.length();
            while (names.hasMoreElements()) {
                String name = (String) names.nextElement();
                if (name.startsWith(prefix) && name.endsWith(suffix)) {
                    String wildcard = StringUtils.mid(name, prefixLength, name.length() - length);
                    matchset.add(wildcard);
                }
            }
            int rowIndex = 1;
            Iterator iterator = matchset.iterator();
            while (iterator.hasNext()) {
                String wildcard = (String) iterator.next();
                currentIndex = 1;
                for (int j = 0; j < keys.length; j++) {
                    String myparam = getActualParam(keys[j].getAttribute("param"), wildcard);
                    currentIndex += setKey(table, keys[j], conn, statement, currentIndex, request, myparam,
                            results);
                }
                for (int j = 0; j < values.length; j++) {
                    String myparam = getActualParam(values[j].getAttribute("param"), wildcard);
                    this.setColumn(statement, currentIndex, request, values[j], myparam,
                            request.getParameter(myparam), rowIndex);
                    currentIndex++;
                }
                statement.execute();
                rowIndex++;
            }
        } else {
            /**
             * This table has no wildcard columns, so we're going to
             * be inserting 1 row.
             */
            for (int i = 0; i < keys.length; i++) {
                currentIndex += setKey(table, keys[i], conn, statement, currentIndex, request,
                        keys[i].getAttribute("param", ""), results);
            }
            for (int i = 0; i < values.length; i++, currentIndex++) {
                this.setColumn(statement, currentIndex, request, values[i]);
            }
            statement.execute();
            /** Done processing table **/
        }
    } finally {
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
        }
    }
}

From source file:org.parosproxy.paros.network.HttpMessage.java

public String[] getParamNames() {
    Vector<String> v = new Vector<>();
    // Get the params names from the query
    SortedSet<String> pns = this.getParamNameSet(HtmlParameter.Type.url);
    Iterator<String> iterator = pns.iterator();
    while (iterator.hasNext()) {
        String name = iterator.next();
        if (name != null) {
            v.add(name);//from  ww w. j  a  va 2 s.  c o m
        }
    }
    if (getRequestHeader().getMethod().equalsIgnoreCase(HttpRequestHeader.POST)) {
        // Get the param names from the POST
        pns = this.getParamNameSet(HtmlParameter.Type.form);
        iterator = pns.iterator();
        while (iterator.hasNext()) {
            String name = iterator.next();
            if (name != null) {
                v.add(name);
            }

        }
    }
    String[] a = new String[v.size()];
    v.toArray(a);
    return a;
}

From source file:org.talend.license.LicenseRetriver.java

public Collection<File> updateLicense(final String version, final File file) {
    logger.info("start to update {} license ", version);
    String url = String.format(Configer.getBuildURL() + Configer.getLicenseURL(), version);

    Document doc = connector.getPage(url);
    if (null == doc) {
        logger.error("no {} license page url:{}", version, url);
        return null;
    }//from   w  ww .  j a  v  a 2s . c  om
    String regex = String.format(Configer.getLicenseItem(), version);

    Elements eles = doc.getElementsMatchingOwnText(regex);

    if (eles.isEmpty()) {
        logger.error("no {} license page url:{}", version, url);
        return null;
    }

    final Pattern pattern = Pattern.compile(regex);

    SortedSet<String> set = new TreeSet<String>(new Comparator<String>() {

        public int compare(String o1, String o2) {
            String m1;
            String m2;
            Matcher matcher = pattern.matcher(o1);
            if (matcher.find()) {
                m1 = matcher.group(2);
            } else {
                return 1;
            }
            matcher = pattern.matcher(o2);
            if (matcher.find()) {
                m2 = matcher.group(2);
            } else {
                return -1;
            }
            return m2.compareTo(m1);
        }
    });
    logger.info("there are {} license build", eles.size());
    for (Element ele : eles) {
        String text = ele.text();
        set.add(text);
    }
    if (set.isEmpty()) {
        return null;
    }

    Iterator<String> ite = set.iterator();
    while (ite.hasNext()) {
        String target = ite.next();
        url = url + target;
        logger.info("retrive from newest build {}", url);
        Collection<File> fs = checkout(version, file, url);
        if (!fs.isEmpty()) {
            return fs;
        }
        logger.info("no available license in build");
    }
    logger.error("retrive license failed");
    return null;
}

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

/**
 * Inserts the specified KeyValue into MemStore and deletes any existing
 * versions of the same row/family/qualifier as the specified KeyValue.
 * <p>/*from  w  w  w  .  j a v  a 2 s .co  m*/
 * First, the specified KeyValue is inserted into the Memstore.
 * <p>
 * If there are any existing KeyValues in this MemStore with the same row,
 * family, and qualifier, they are removed.
 * <p>
 * Callers must hold the read lock.
 *
 * @param cell
 * @return change in size of MemStore
 */
private long upsert(Cell cell, long readpoint) {
    // Add the KeyValue to the MemStore
    // Use the internalAdd method here since we (a) already have a lock
    // and (b) cannot safely use the MSLAB here without potentially
    // hitting OOME - see TestMemStore.testUpsertMSLAB for a
    // test that triggers the pathological case if we don't avoid MSLAB
    // here.
    KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
    long addedSize = internalAdd(kv);

    // Get the KeyValues for the row/family/qualifier regardless of timestamp.
    // For this case we want to clean up any other puts
    KeyValue firstKv = KeyValueUtil.createFirstOnRow(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(),
            kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(), kv.getQualifierArray(),
            kv.getQualifierOffset(), kv.getQualifierLength());
    SortedSet<KeyValue> ss = kvset.tailSet(firstKv);
    Iterator<KeyValue> it = ss.iterator();
    // versions visible to oldest scanner
    int versionsVisible = 0;
    while (it.hasNext()) {
        KeyValue cur = it.next();

        if (kv == cur) {
            // ignore the one just put in
            continue;
        }
        // check that this is the row and column we are interested in, otherwise bail
        if (CellUtil.matchingRow(kv, cur) && CellUtil.matchingQualifier(kv, cur)) {
            // only remove Puts that concurrent scanners cannot possibly see
            if (cur.getTypeByte() == KeyValue.Type.Put.getCode() && cur.getMvccVersion() <= readpoint) {
                if (versionsVisible > 1) {
                    // if we get here we have seen at least one version visible to the oldest scanner,
                    // which means we can prove that no scanner will see this version

                    // false means there was a change, so give us the size.
                    long delta = heapSizeChange(cur, true);
                    addedSize -= delta;
                    this.size.addAndGet(-delta);
                    it.remove();
                    setOldestEditTimeToNow();
                } else {
                    versionsVisible++;
                }
            }
        } else {
            // past the row or column, done
            break;
        }
    }
    return addedSize;
}

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

private void supertypelist(Element e, SortedSet<String> st) {
    for (Iterator<String> i = st.iterator(); i.hasNext();) {
        ClassInfo sti = model.classById(i.next());
        if (sti.isAbstract()) {
            Element e1 = document.createElementNS(NS_HTML, "I");
            e1.appendChild(document.createTextNode("\r" + sti.name()));
            e.appendChild(e1);//from  w w  w.j  a  v  a 2 s. c o  m
        } else {
            e.appendChild(document.createTextNode("\r" + sti.name()));
        }
        SortedSet<String> st2 = sti.supertypes();
        if (st2 != null)
            supertypelist(e, st2);
    }
}