Example usage for org.apache.commons.lang.mutable MutableInt MutableInt

List of usage examples for org.apache.commons.lang.mutable MutableInt MutableInt

Introduction

In this page you can find the example usage for org.apache.commons.lang.mutable MutableInt MutableInt.

Prototype

public MutableInt(Number value) 

Source Link

Document

Constructs a new MutableInt with the specified value.

Usage

From source file:net.pj.games.eulerproject.elements.StringPermutator.java

private static int getIndexOfMax(String s) {

    final MutableInt maxIndex = new MutableInt(-1);
    s.chars().max().ifPresent(m -> maxIndex.setValue(s.indexOf(m)));
    return maxIndex.intValue();
}

From source file:de.tudarmstadt.ukp.csniper.webapp.search.tgrep.PennTreeUtils.java

public static PennTreeNode selectDfs(PennTreeNode aNode, int aIndex) {
    return dfs(aIndex, new MutableInt(0), aNode);
}

From source file:com.linkedin.pinot.common.utils.request.RequestUtils.java

/**
 * Generates thrift compliant filterQuery and populate it in the broker request
 * @param filterQueryTree/*from  w w  w  . j  a  va  2  s . c o m*/
 * @param request
 */
public static void generateFilterFromTree(FilterQueryTree filterQueryTree, BrokerRequest request) {
    Map<Integer, FilterQuery> filterQueryMap = new HashMap<>();
    MutableInt currentId = new MutableInt(0);
    FilterQuery root = traverseFilterQueryAndPopulateMap(filterQueryTree, filterQueryMap, currentId);
    filterQueryMap.put(root.getId(), root);
    request.setFilterQuery(root);
    FilterQueryMap mp = new FilterQueryMap();
    mp.setFilterQueryMap(filterQueryMap);
    request.setFilterSubQueryMap(mp);
}

From source file:com.datatorrent.lib.util.BaseUniqueKeyCounter.java

/**
 * Reference counts each tuple/*from  w ww  .  j  ava2 s .  com*/
 *
 * @param tuple
 */
public void processTuple(K tuple) {
    MutableInt i = map.get(tuple);
    if (i == null) {
        i = new MutableInt(0);
        map.put(cloneKey(tuple), i);
    }
    i.increment();
}

From source file:com.datatorrent.lib.multiwindow.SimpleMovingAverageObject.java

public SimpleMovingAverageObject() {
    sum = new MutableDouble(0);
    count = new MutableInt(0);
}

From source file:com.datatorrent.lib.util.BaseUniqueKeyValueCounter.java

/**
 * Reference counts each tuple//  w  w w  .  j  ava2  s.  c om
 * @param key tuple key
 * @param val tuple value
 */
public void processTuple(K key, V val) {
    HashMap<K, V> tuple = new HashMap<K, V>(1);
    tuple.put(key, val);
    MutableInt i = map.get(tuple);
    if (i == null) {
        i = new MutableInt(0);
        map.put(cloneTuple(tuple), i);
    }
    i.increment();
}

From source file:com.datatorrent.lib.util.AbstractBaseFrequentKey.java

/**
 * Counts frequency of a key/*from ww  w  .j  a v a 2  s  . c  om*/
 * @param tuple
 */
public void processTuple(K tuple) {
    MutableInt count = keycount.get(tuple);
    if (count == null) {
        count = new MutableInt(0);
        keycount.put(cloneKey(tuple), count);
    }
    count.increment();
}

From source file:com.datatorrent.lib.testbench.HashTestSink.java

@Override
public void put(T tuple) {
    this.count++;
    MutableInt val = map.get(tuple);
    if (val == null) {
        val = new MutableInt(0);
        map.put(tuple, val);
    }/*from w ww  . j  a va2 s .  c o m*/
    val.increment();
}

From source file:com.datatorrent.lib.testbench.ArrayListTestSink.java

@Override
public void put(T tuple) {
    this.count++;
    @SuppressWarnings("unchecked")
    ArrayList<Object> list = (ArrayList<Object>) tuple;
    for (Object o : list) {
        MutableInt val = map.get(o);
        if (val == null) {
            val = new MutableInt(0);
            map.put(o, val);
        }//from  w w  w.  j ava 2  s  . com
        val.increment();
    }
}

From source file:com.searchtechnologies.aspire.components.heritrixconnector.ProcessUncrawledStage.java

@Override
public void process(Job j) throws AspireException {

    AspireObject doc = j.get();/*from  w  w  w .ja va  2s  . co m*/

    MutableInt contentSize = new MutableInt(0);
    String md5 = null;
    byte[] contentBytes = null;
    try {
        InputStream is = (InputStream) j.getVariable(Standards.Basic.CONTENT_STREAM_KEY);
        //InputStream is = HeritrixScanner.openURLInputStream(doc.getText(Standards.Basic.FETCH_URL_TAG),true);

        contentBytes = AspireHeritrixProcessor.getStringFromInputStream(is).getBytes();

        md5 = HeritrixScanner.computeMD5(new ByteArrayInputStream(contentBytes), contentSize);

    } catch (NoSuchAlgorithmException e) {
        throw new AspireException(
                "com.searchtechnologies.aspire.components.heritrixconnector.ProcessUncrawledStage", e,
                "Error computing md5 sum");
    } catch (IOException e) {
        throw new AspireException(
                "com.searchtechnologies.aspire.components.heritrixconnector.ProcessUncrawledStage", e,
                "Error computing md5 sum");
    }

    HeritrixScanner scanner = ((HeritrixScanner) this.getComponent("/" + this.getAppName() + "/Main/Scanner"));

    String lastMd5 = doc.getText("md5");
    //Check MD5 Signature
    if (lastMd5.equals(md5)) {
        doc.add(Scanner.ACTION_TAG, Scanner.Action.noChange.toString());
        j.set(doc);
        j.terminate();
        scanner.reportNoChange(doc.getText(Standards.Basic.FETCH_URL_TAG));
        return;
    } else {

        j.getVariableMap().remove(Standards.Basic.CONTENT_STREAM_KEY);
        if (contentBytes != null)
            j.putVariable(Standards.Basic.CONTENT_BYTES_KEY, contentBytes);
        doc.add(Scanner.ACTION_TAG, Scanner.Action.update.toString());
        doc.removeChildren("md5");
        doc.add("md5", md5);
        doc.add("contentSize", contentSize);
        doc.set(Standards.Scanner.DOC_TYPE_TAG, DocType.item.toString());
        j.set(doc);
        scanner.reportUpdate(doc.getText(Standards.Basic.FETCH_URL_TAG));
    }
}