Example usage for org.apache.commons.lang3.mutable MutableLong MutableLong

List of usage examples for org.apache.commons.lang3.mutable MutableLong MutableLong

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableLong MutableLong.

Prototype

public MutableLong(final String value) throws NumberFormatException 

Source Link

Document

Constructs a new MutableLong parsing the given string.

Usage

From source file:enumj.Reversible.java

/**
 * Applies a {@code Enumerator.map(BiFunction)} operation
 * upon {@code source}, in reverse if necessary.
 *
 * @param <E> type of unmapped enumerated elements.
 * @param <R> type of mapped enumerated elements.
 * @param source {@link Enumerator} to apply the operation on.
 * @param mapper {@link BiFunction} to apply.
 * @param reversed true if the operation is applied in reverse,
 * false otherwise.//from ww w  .ja va  2  s  .  c  o  m
 * @return mapped {@code Enumerator}.
 */
static <E, R> Enumerator<R> map(Enumerator<E> source, BiFunction<? super E, ? super Long, ? extends R> mapper,
        boolean reversed) {
    Checks.ensureNotNull(mapper, Messages.NULL_ENUMERATOR_MAPPER);
    final MutableLong index = new MutableLong(0);
    final Function<E, R> fun = e -> {
        final R result = mapper.apply(e, index.toLong());
        index.increment();
        return result;
    };
    if (reversed) {
        final PipeEnumerator pipe = (PipeEnumerator) source;
        return pipe.reversedMap(fun);
    }
    return source.map(fun);
}

From source file:com.datatorrent.lib.appdata.query.WEQueryQueueManagerTest.java

@Test
public void testSimpleAddOneRemove() {
    WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();

    wqqm.setup(null);//from  w  ww.ja v a  2 s .  c om
    wqqm.beginWindow(0);

    Query query = new MockQuery("1");
    wqqm.enqueue(query, null, new MutableLong(1L));

    Query queryD = wqqm.dequeue().getQuery();
    QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
    Query queryD1 = qb == null ? null : qb.getQuery();

    wqqm.endWindow();
    wqqm.teardown();

    Assert.assertEquals("The queries must match.", query, queryD);
    Assert.assertEquals("The queries must match.", null, queryD1);
}

From source file:com.datatorrent.lib.appdata.query.AppDataWindowEndQueueManager.java

@Override
public boolean enqueue(QUERY query, META_QUERY metaQuery, MutableLong context) {
    if (context != null) {
        query.setCountdown(context.getValue());
    }//from   w w w  .  j  av  a 2s. co m

    if (query.isOneTime()) {
        return super.enqueue(query, metaQuery, new MutableLong(1L));
    } else {
        return super.enqueue(query, metaQuery, new MutableLong(query.getCountdown()));
    }
}

From source file:info.mikaelsvensson.devtools.analysis.db2eventlog.QueryStatistics.java

void addSampleData(Db2EventLogSample sample) {
    MutableLong sum = operationsTime.get(sample.getOperation());
    if (sum == null) {
        sum = new MutableLong(sample.getResponseTime());
        operationsTime.put(sample.getOperation(), sum);
    } else {/*from   w w w .  j  av a  2s . co m*/
        sum.add(sample.getResponseTime());
    }
    totalSamples++;
    fetchCount += sample.getFetchCount();
    sorts += sample.getSorts();
    totalSortTime += sample.getTotalSortTime();
    sortOverflows += sample.getSortOverflows();
    rowsRead += sample.getRowsRead();
    rowsWritten += sample.getRowsWritten();

    if (lastTimeStamp == null || sample.getTimeStamp().after(lastTimeStamp)) {
        lastTimeStamp = sample.getTimeStamp();
    }
    if (firstTimeStamp == null || sample.getTimeStamp().before(firstTimeStamp)) {
        firstTimeStamp = sample.getTimeStamp();
    }
}

From source file:io.codis.nedis.handler.RedisResponseDecoder.java

private Long decodeLong(ByteBuf in) throws ProtocolException {
    byte sign = in.readByte();
    final MutableLong l;
    boolean negative;
    if (sign == '-') {
        negative = true;//w w  w.j  a va 2s.c o m
        l = new MutableLong(0);
    } else {
        negative = false;
        l = new MutableLong(toDigit(sign));
    }
    final MutableBoolean reachCR = new MutableBoolean(false);
    setReaderIndex(in, in.forEachByte(new ByteBufProcessor() {

        @Override
        public boolean process(byte value) throws Exception {
            if (value == '\r') {
                reachCR.setTrue();
                return false;
            } else {
                if (value >= '0' && value <= '9') {
                    l.setValue(l.longValue() * 10 + toDigit(value));
                } else {
                    throw new ProtocolException("Response is not ended by CRLF");
                }
                return true;
            }
        }
    }));
    if (!reachCR.booleanValue()) {
        return null;
    }
    if (!in.isReadable()) {
        return null;
    }
    if (in.readByte() != '\n') {
        throw new ProtocolException("Response is not ended by CRLF");
    }
    return negative ? -l.longValue() : l.longValue();
}

From source file:com.datatorrent.lib.appdata.query.WEQueryQueueManagerTest.java

@Test
public void testSimpleAddRemove2() {
    WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();

    wqqm.setup(null);/* ww  w  .jav  a  2 s  .com*/
    wqqm.beginWindow(0);

    Query query = new MockQuery("1");
    wqqm.enqueue(query, null, new MutableLong(1L));

    Query queryD = wqqm.dequeue().getQuery();
    QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
    Query queryD1 = qb == null ? null : qb.getQuery();

    Query query1 = new MockQuery("2");
    wqqm.enqueue(query1, null, new MutableLong(1L));

    Query query1D = wqqm.dequeue().getQuery();
    qb = wqqm.dequeue();
    Query query1D1 = qb == null ? null : qb.getQuery();

    wqqm.endWindow();
    wqqm.teardown();

    Assert.assertEquals("The queries must match.", query, queryD);
    Assert.assertEquals("The queries must match.", null, queryD1);

    Assert.assertEquals("The queries must match.", query1, query1D);
    Assert.assertEquals("The queries must match.", null, query1D1);
}

From source file:com.net2plan.interfaces.networkDesign.ReaderNetPlanN2PVersion_5.java

protected void parseNetwork(NetPlan netPlan) throws XMLStreamException {
    final String networkDescription_thisNetPlan = getString("description");
    final String networkName_thisNetPlan = getString("name");
    final Long nexElementId_thisNetPlan = getLong("nextElementId");
    netPlan.setNetworkDescription(networkDescription_thisNetPlan);
    netPlan.setNetworkName(networkName_thisNetPlan);
    netPlan.nextElementId = new MutableLong(nexElementId_thisNetPlan);
    if (netPlan.nextElementId.toLong() <= 0)
        throw new Net2PlanException("A network element has an id higher than the nextElementId");

    while (xmlStreamReader.hasNext()) {
        xmlStreamReader.next();/*from w  ww .  j av a 2  s.c  om*/
        switch (xmlStreamReader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            String startElementName = xmlStreamReader.getName().toString();
            switch (startElementName) {
            case "attribute":
                String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
                String name = xmlStreamReader
                        .getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
                netPlan.setAttribute(key, name);
                break;

            case "layer":
                parseLayer(netPlan);
                break;

            case "node":
                parseNode(netPlan);
                break;

            case "resource":
                parseResource(netPlan);
                break;

            case "srg":
                parseSRG(netPlan);
                break;

            case "layerCouplingDemand":
                final long upperLayerLinkId = getLong("upperLayerLinkId");
                final long lowerLayerDemandId = getLong("lowerLayerDemandId");
                netPlan.getDemandFromId(lowerLayerDemandId)
                        .coupleToUpperLayerLink(netPlan.getLinkFromId(upperLayerLinkId));
                break;

            case "layerCouplingMulticastDemand":
                final long lowerLayerMulticastDemandId = getLong("lowerLayerDemandId");
                final Set<Link> setLinksToCouple = getLinkSetFromIds(netPlan, getListLong("upperLayerLinkIds"));
                netPlan.getMulticastDemandFromId(lowerLayerMulticastDemandId).couple(setLinksToCouple);
                break;

            default:
                throw new RuntimeException("Bad");
            }

            break;

        case XMLEvent.END_ELEMENT:
            String endElementName = xmlStreamReader.getName().toString();
            if (endElementName.equals("network")) {
                //                  if (!netPlan.hasReadLayerZero && netPlan.layers.size() > 1) netPlan.removeNetworkLayer (netPlan.layers.get(0));
                return;
            }

            break;
        }
    }

    throw new RuntimeException("'Network' element not parsed correctly (end tag not found)");
}

From source file:com.datatorrent.lib.appdata.query.WEQueryQueueManagerTest.java

@Test
public void testSimpleAddAfterStarted() {
    WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();

    wqqm.setup(null);//from  ww  w.  j a v a2 s.c  o  m
    wqqm.beginWindow(0);

    Query query = new MockQuery("0");
    wqqm.enqueue(query, null, new MutableLong(1L));

    Query query1 = new MockQuery("1");
    wqqm.enqueue(query1, null, new MutableLong(1L));

    Query queryD = wqqm.dequeue().getQuery();

    Query query2 = new MockQuery("2");
    wqqm.enqueue(query2, null, new MutableLong(1L));

    Query query1D = wqqm.dequeue().getQuery();
    Query query2D = wqqm.dequeue().getQuery();
    QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
    Query query3D = qb == null ? null : qb.getQuery();

    wqqm.endWindow();
    wqqm.teardown();

    Assert.assertEquals("The queries must match.", query, queryD);
    Assert.assertEquals("The queries must match.", query1, query1D);
    Assert.assertEquals("The queries must match.", query2, query2D);
    Assert.assertEquals("The queries must match.", null, query3D);
}

From source file:com.datatorrent.contrib.dimensions.CompositeAggregatorDimensionsQueryTester.java

public DataResultDimensional doQuery() {
    List<Map<String, HDSQuery>> hdsQueries = Lists.newArrayList();
    List<Map<String, EventKey>> eventKeys = Lists.newArrayList();

    DimensionsQueryExecutor dqe = new DimensionsQueryExecutor(store, store.schemaRegistry);

    final String aggregatorName = "TOPN-SUM-10_location";
    final int aggregatorId = store.getAggregatorRegistry().getTopBottomAggregatorNameToID().get(aggregatorName);

    EventKey eventKey = null;/*from   ww  w .j  a v a 2 s .  c  o m*/
    for (EventKey ek : totalEventKeys) {
        if (ek.getAggregatorID() == aggregatorId) {
            eventKey = ek;
            break;
        }
    }

    issueHDSQuery(store, eventKey);

    Map<String, HDSQuery> aggregatorToQuery = Maps.newHashMap();
    aggregatorToQuery.put(aggregatorName, store.getQueries().values().iterator().next());
    hdsQueries.add(aggregatorToQuery);

    Map<String, EventKey> aggregatorToEventKey = Maps.newHashMap();
    aggregatorToEventKey.put(aggregatorName, eventKey);
    eventKeys.add(aggregatorToEventKey);

    QueryMeta queryMeta = new QueryMeta();
    queryMeta.setHdsQueries(hdsQueries);
    queryMeta.setEventKeys(eventKeys);

    long currentTime = 0L;
    FieldsDescriptor fdKey = eventSchema.getDimensionsDescriptorIDToKeyDescriptor().get(0);
    Map<String, Set<Object>> keyToValues = Maps.newHashMap();
    keyToValues.put("publisher", Sets.newHashSet());
    //keyToValues.put("advertiser", Sets.newHashSet());

    Map<String, Set<String>> fieldToAggregators = Maps.newHashMap();
    fieldToAggregators.put("impressions", Sets.newHashSet(aggregatorName));
    fieldToAggregators.put("cost", Sets.newHashSet(aggregatorName));

    FieldsAggregatable fieldsAggregatable = new FieldsAggregatable(fieldToAggregators);

    DataQueryDimensional query = new DataQueryDimensional("1", DataQueryDimensional.TYPE, currentTime,
            currentTime, new CustomTimeBucket(TimeBucket.MINUTE), fdKey, keyToValues, fieldsAggregatable, true);

    return (DataResultDimensional) dqe.executeQuery(query, queryMeta, new MutableLong(1L));
}

From source file:com.cg.mapreduce.fpgrowth.mahout.fpm.fpgrowth.FPGrowth.java

/**
 * Generate the Feature Frequency list from the given transaction whose
 * frequency > minSupport/*w ww.j a  va 2s  . co  m*/
 *
 * @param transactions
 *          Iterator over the transaction database
 * @param minSupport
 *          minSupport of the feature to be included
 * @return the List of features and their associated frequency as a Pair
 */
public final List<Pair<A, Long>> generateFList(Iterator<Pair<List<A>, Long>> transactions, int minSupport) {

    Map<A, MutableLong> attributeSupport = Maps.newHashMap();
    while (transactions.hasNext()) {
        Pair<List<A>, Long> transaction = transactions.next();
        for (A attribute : transaction.getFirst()) {
            if (attributeSupport.containsKey(attribute)) {
                attributeSupport.get(attribute).add(transaction.getSecond().longValue());
            } else {
                attributeSupport.put(attribute, new MutableLong(transaction.getSecond()));
            }
        }
    }
    List<Pair<A, Long>> fList = Lists.newArrayList();
    for (Entry<A, MutableLong> e : attributeSupport.entrySet()) {
        long value = e.getValue().longValue();
        if (value >= minSupport) {
            fList.add(new Pair<A, Long>(e.getKey(), value));
        }
    }

    Collections.sort(fList, new CountDescendingPairComparator<A, Long>());

    return fList;
}