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

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

Introduction

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

Prototype

public MutableInt(final String value) throws NumberFormatException 

Source Link

Document

Constructs a new MutableInt parsing the given string.

Usage

From source file:com.flipkart.flux.MockActorRef.java

@Override
public void onReceive(Object message) throws Exception {
    if (!receivedMessages.containsKey(message)) {
        receivedMessages.put(message, new MutableInt(0));
    }/* ww w  . j av  a  2s . c  o m*/
    receivedMessages.get(message).increment();
}

From source file:com.flipkart.flux.client.utils.TestUtil.java

public static MethodInvocation dummyInvocation(Method methodToReturn, Object methodOwner) {
    return new MethodInvocation() {
        private final MutableInt numProceedInvoctions = new MutableInt(0);

        @Override//  w ww .  java  2s  .  c  o  m
        public Method getMethod() {
            return methodToReturn;
        }

        @Override
        public Object[] getArguments() {
            return new Object[0];
        }

        @Override
        public Object proceed() throws Throwable {
            numProceedInvoctions.increment();
            return null;
        }

        @Override
        public Object getThis() {
            return methodOwner;
        }

        @Override
        public AccessibleObject getStaticPart() {
            return null;
        }
    };
}

From source file:com.datatorrent.lib.appdata.gpo.SerdeListStringTest.java

@Test
public void simpleSerdeTest() {
    SerdeListString sls = SerdeListString.INSTANCE;

    List<String> testList = Lists.newArrayList("timothy", "farkas", "is", "the", "coolest");
    byte[] serializedObject = sls.serializeObject(testList);

    GPOByteArrayList gpoBytes = new GPOByteArrayList();
    byte[] bytesA = new byte[20];
    byte[] bytesB = new byte[13];

    gpoBytes.add(bytesA);// w  ww .  jav a2  s .  c  o m
    gpoBytes.add(serializedObject);
    gpoBytes.add(bytesB);

    MutableInt intVals = new MutableInt(bytesA.length);

    @SuppressWarnings("unchecked")
    List<String> deserializedList = (List<String>) sls.deserializeObject(gpoBytes.toByteArray(), intVals);

    Assert.assertEquals(testList, deserializedList);
}

From source file:com.datatorrent.lib.appdata.gpo.SerdeFieldsDescriptorTest.java

@Test
public void simpleTest() {
    Map<String, Type> fieldToType = Maps.newHashMap();

    fieldToType.put("a", Type.INTEGER);
    fieldToType.put("b", Type.CHAR);

    FieldsDescriptor fd = new FieldsDescriptor(fieldToType);

    byte[] bytes = SerdeFieldsDescriptor.INSTANCE.serializeObject(fd);
    FieldsDescriptor newfd = (FieldsDescriptor) SerdeFieldsDescriptor.INSTANCE.deserializeObject(bytes,
            new MutableInt(0));

    Assert.assertEquals(fd, newfd);/*from www. j ava  2  s.  com*/
}

From source file:com.flipkart.flux.client.intercept.DummyFluxRuntimeResource.java

@Path("/machines")
@Consumes(MediaType.APPLICATION_JSON)//from  w w  w .  ja v a  2s .  co  m
@Produces(MediaType.APPLICATION_JSON)
@POST
public String receiveTestStateMachines(StateMachineDefinition stateMachineDefinition) {
    if (!smToCountMap.containsKey(stateMachineDefinition)) {
        smToCountMap.put(stateMachineDefinition, new MutableInt(0));
    }
    smToCountMap.get(stateMachineDefinition).increment();
    return "some-id";
}

From source file:com.datatorrent.lib.appdata.gpo.SerdeListPrimitiveTest.java

@Test
public void simpleSerdeTest() {
    GPOByteArrayList bal = new GPOByteArrayList();

    List<Object> primitiveList = Lists.newArrayList();
    primitiveList.add(true);//from   w w  w  .j  a v a  2  s .  co m
    primitiveList.add(((byte) 5));
    primitiveList.add(((short) 16000));
    primitiveList.add(25000000);
    primitiveList.add(5000000000L);
    primitiveList.add('a');
    primitiveList.add("tim is the coolest");

    byte[] plBytes = SerdeListPrimitive.INSTANCE.serializeObject(primitiveList);

    bal.add(new byte[15]);
    bal.add(plBytes);
    bal.add(new byte[13]);

    @SuppressWarnings("unchecked")
    List<Object> newPrimitiveList = (List<Object>) SerdeListPrimitive.INSTANCE
            .deserializeObject(bal.toByteArray(), new MutableInt(15));

    Assert.assertEquals(primitiveList, newPrimitiveList);
}

From source file:com.blackducksoftware.ohcount4j.DiffSourceFile.java

public Diff diff(SourceFile from, SourceFile to) throws IOException {
    Language fromLanguage = Detector.detect(from);
    Language toLanguage = Detector.detect(to);

    LineDetailHandler fromLinehandler = new LineDetailHandler();
    fromLanguage.makeScanner().scan(from, fromLinehandler);

    LineDetailHandler toLinehandler = new LineDetailHandler();
    toLanguage.makeScanner().scan(to, toLinehandler);

    List<String> original = fromLinehandler.contentList;
    List<String> revised = toLinehandler.contentList;

    // Compute diff. Get the Patch object. Patch is the container for computed deltas.
    Patch<String> patch = DiffUtils.diff(original, revised);

    MutableInt cAdded = new MutableInt(0); // code added
    MutableInt cRemoved = new MutableInt(0); // code removed
    MutableInt bAdded = new MutableInt(0); // blank added
    MutableInt bRemoved = new MutableInt(0); // blank removed
    MutableInt cmtAdded = new MutableInt(0); // comment added
    MutableInt cmtRemoved = new MutableInt(0); // comment removed
    for (Delta<String> delta : patch.getDeltas()) {
        switch (delta.getType()) {
        case CHANGE: {
            // its considered as 1 is added and 1 is removed
            accountDiff(cAdded, cRemoved, bAdded, bRemoved, cmtAdded, cmtRemoved, Delta.TYPE.DELETE,
                    delta.getOriginal(), fromLinehandler);
            accountDiff(cAdded, cRemoved, bAdded, bRemoved, cmtAdded, cmtRemoved, Delta.TYPE.INSERT,
                    delta.getRevised(), toLinehandler);
            break;
        }// ww w  . j av  a  2s .c  om
        case DELETE: {
            accountDiff(cAdded, cRemoved, bAdded, bRemoved, cmtAdded, cmtRemoved, Delta.TYPE.DELETE,
                    delta.getOriginal(), fromLinehandler);
            break;
        }
        case INSERT: {
            accountDiff(cAdded, cRemoved, bAdded, bRemoved, cmtAdded, cmtRemoved, Delta.TYPE.INSERT,
                    delta.getRevised(), toLinehandler);
            break;
        }
        }

    }
    return new Diff(cAdded.intValue(), cRemoved.intValue(), cmtAdded.intValue(), cmtRemoved.intValue(),
            bAdded.intValue(), bRemoved.intValue());
}

From source file:net.sf.jabb.util.text.word.TestTextAnalyzer.java

protected void scan(AnalyzedText aText) {
    String text = aText.text;//from   www  . j a  va2s .  c o m
    if (text != null && text.length() > 0) {
        int i = 0;
        while (i < text.length()) {
            Word word = (Word) matcher.match(text, i);
            if (word == null) {
                i++;
            } else {
                int types = word.getTypes();
                if ((types & Word.TYPE_IGNORE) != 0) {

                } else if ((types & Word.TYPE_KEYWORD) != 0) {
                    Map<Object, MutableInt> matched = aText.getMatchedKeywords();
                    Object attachment = word.getKeywordAttachment();
                    if (matched.containsKey(attachment)) {
                        matched.get(attachment).increment();
                    } else {
                        matched.put(attachment, new MutableInt(1));
                    }

                } else if ((types & Word.TYPE_NORMAL) != 0) {
                    aText.getWords().add(word.getWord());
                    aText.getUniqueWords().add(word.getWord());

                } else if ((types & Word.TYPE_SEPARATOR) != 0) {
                    // skip over
                }
                i += word.getWord().length();
            }
        }
    }

}

From source file:com.datatorrent.demos.uniquecountdemo.RandomKeysGenerator.java

@Override
public void emitTuples() {
    for (int i = 0; i < tupleBlast; i++) {
        int key = random.nextInt(numKeys);
        outPort.emit(key);/*from   w  w w . j  a  va 2 s. com*/

        if (verificationPort.isConnected()) {
            // maintain history for later verification.
            MutableInt count = history.get(key);
            if (count == null) {
                count = new MutableInt(0);
                history.put(key, count);
            }
            count.increment();
        }

    }
    try {
        if (sleepTime != 0)
            Thread.sleep(sleepTime);
    } catch (Exception ex) {

    }
}

From source file:eu.project.ttc.resources.CharacterFootprintTermFilter.java

@Override
public boolean accept(RegexOccurrence occurrence) {
    if (allowedChars == null)
        return true;
    int totalChars = 0;
    int totalWords = 0;
    int nbBadWords = 0;
    MutableInt badChars = new MutableInt(0);
    for (LabelledAnnotation a : occurrence.getLabelledAnnotations()) {
        WordAnnotation w = (WordAnnotation) a.getAnnotation();
        totalChars += w.getCoveredText().length();
        totalWords += 1;/*from w w  w  .ja va 2s .  c o m*/
        if (isBadWord(w, badChars))
            nbBadWords += 1;
    }
    if (nbBadWords > 1)
        return false;
    if (totalChars <= totalWords * 3 && totalWords > 1)
        return false;
    int badCharRate = 100 * badChars.intValue() / totalChars;
    if (badCharRate >= BAD_CHAR_RATE_THRESHOLD)
        return false;
    return true;
}