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

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

Introduction

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

Prototype

public void increment() 

Source Link

Document

Increments the value.

Usage

From source file:com.norconex.jefmon.instances.InstancesManager.java

public static InstanceSummary createThisJefMonInstance() {
    JEFMonConfig config = JEFMonApplication.get().getConfig();
    JEFMonInstance suitesStatusesMonitor = JEFMonApplication.get().getJobSuitesStatusesMonitor();
    InstanceSummary thisInstance = new InstanceSummary(null);
    thisInstance.setName(config.getInstanceName());
    Collection<JobSuiteStatusSnapshot> suitesStatuses = suitesStatusesMonitor.getJobSuitesStatuses();
    int totalRoot = 0;
    for (JobSuiteStatusSnapshot suiteStatuses : suitesStatuses) {
        JobState status = suiteStatuses.getRoot().getState();
        MutableInt count = thisInstance.getStatuses().get(status);
        if (count == null) {
            count = new MutableInt();
        }/* w w w.  j  a v a 2 s .  c  o m*/
        count.increment();
        thisInstance.getStatuses().put(status, count);
        totalRoot++;
    }
    thisInstance.setTotalRoots(totalRoot);
    return thisInstance;
}

From source file:com.norconex.commons.lang.file.FileUtil.java

/**
 * Deletes all directories that are empty and are <b>older</b> 
 * than the given date.  If the date is <code>null</code>, all empty 
 * directories will be deleted, regardless of their date.
 * @param parentDir the directory where to start looking for empty 
 *        directories//from  w  w  w . ja  v  a 2s  . co  m
 * @param date the date to compare empty directories against
 * @return the number of deleted directories
 * @since 1.3.0
 */
public static int deleteEmptyDirs(File parentDir, final Date date) {
    final MutableInt dirCount = new MutableInt(0);
    visitEmptyDirs(parentDir, new IFileVisitor() {
        @Override
        public void visit(File file) {
            if (date == null || FileUtils.isFileOlder(file, date)) {
                String[] children = file.list();
                if (file.isDirectory() && (children == null || children.length == 0)) {
                    try {
                        FileUtil.delete(file);
                        dirCount.increment();
                    } catch (IOException e) {
                        LOG.error("Could not be delete directory: " + file, e);
                    }
                }
            }
        }
    });
    return dirCount.intValue();
}

From source file:com.replaymod.replaystudio.filter.PacketCountFilter.java

@Override
public boolean onPacket(PacketStream stream, PacketData data) {
    Class<?> cls = WrappedPacket.getWrapped(data.getPacket());

    MutableInt counter = count.get(cls);
    if (counter == null) {
        counter = new MutableInt();
        count.put(cls, counter);//ww w  . j a  va 2 s.  c o m
    }

    counter.increment();
    return true;
}

From source file:com.addthis.hydra.data.query.QueryElementProperty.java

public QueryElementProperty parse(String tok, MutableInt nextColumn) {
    if (tok.startsWith("+")) {
        // show = true;
        column = Integer.toString(nextColumn.intValue());
        nextColumn.increment();
        tok = tok.substring(1);/* w  w  w . j a v  a  2 s.  c o m*/
    }
    key = new BoundedValue().parse(tok, nextColumn);
    return this;
}

From source file:com.gs.obevo.mongodb.impl.MongoDbDeployExecutionDao.java

@Override
public void persistNew(DeployExecution deployExecution, PhysicalSchema physicalSchema) {
    MongoDatabase database = mongoClient.getDatabase(physicalSchema.getPhysicalName());
    MongoCollection<Document> auditCollection = database.getCollection(deployExecutionTableName);

    MutableInt mutableInt = nextIdBySchema.get(physicalSchema);
    mutableInt.increment();
    ((DeployExecutionImpl) deployExecution).setId(mutableInt.longValue());
    Document doc = getDocumentFromDeployExecution(deployExecution, false);
    auditCollection.insertOne(doc);/*from  w w w. ja  v a 2  s  .  co  m*/
}

From source file:com.addthis.hydra.data.query.QueryElementField.java

public QueryElementField parse(String tok, MutableInt nextColumn) {
    if (tok.startsWith("+")) {
        // show = true;
        column = Integer.toString(nextColumn.intValue());
        nextColumn.increment();
        tok = tok.substring(1);//from   w w  w  .  j a  v a 2s.c o  m
    } else if (tok.startsWith("?")) {
        // show = true;
        column = Integer.toString(nextColumn.intValue());
        nextColumn.increment();
        tok = tok.substring(1);
        keys = memKey;
    }
    String[] kv = LessStrings.splitArray(LessBytes.urldecode(tok), "=");
    if (kv.length == 2) {
        name = kv[0];
        String[] keyarr = LessStrings.splitArray(kv[1], ",");
        keys = new BoundedValue[keyarr.length];
        for (int i = 0; i < keyarr.length; i++) {
            keys[i] = new BoundedValue().parse(keyarr[i], nextColumn);
        }
    } else if (kv.length == 1) {
        name = kv[0];
        if (keys == null) {
            keys = new BoundedValue[1];
            keys[0] = new BoundedValue();
        }
    }
    return this;
}

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.  ja  va 2  s. c  o m*/

        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:com.datatorrent.demos.uniquecount.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 .ja v  a  2 s . c o m

        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) {
        // Ignore.
    }
}

From source file:io.cloudslang.lang.cli.services.ConsolePrinterImplTest.java

@Test
public void testConsolePrint() throws Exception {
    final List<Runnable> runnableList = new ArrayList<>();
    final MutableInt mutableInt = new MutableInt(0);
    doAnswer(new Answer() {
        @Override/*from  w ww.  j a  v a 2 s. co m*/
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            mutableInt.increment();
            Object[] arguments = invocationOnMock.getArguments();
            runnableList.add((Runnable) arguments[0]);
            if (mutableInt.getValue() == 1) {
                return ConcurrentUtils.constantFuture("firstMessage");
            } else if (mutableInt.getValue() == 2) {
                return ConcurrentUtils.constantFuture("secondMessage");
            } else {
                return null;
            }
        }
    }).when(singleThreadExecutor).submit(Mockito.any(Runnable.class));

    consolePrinter.printWithColor(GREEN, "firstMessage");
    Future lastFuture = consolePrinter.printWithColor(GREEN, "secondMessage");

    assertEquals("secondMessage", lastFuture.get());

    assertEquals(2, runnableList.size());

    assertTrue(runnableList.get(0) instanceof ConsolePrinterImpl.ConsolePrinterRunnable);
    assertTrue(runnableList.get(1) instanceof ConsolePrinterImpl.ConsolePrinterRunnable);

    assertEquals(new ConsolePrinterImpl.ConsolePrinterRunnable(GREEN, "firstMessage"), runnableList.get(0));
    assertEquals(new ConsolePrinterImpl.ConsolePrinterRunnable(GREEN, "secondMessage"), runnableList.get(1));
}

From source file:events.TeamVsTeam.TeamVsTeam.java

private static void checkKillsAndAnnounce(Player player) {
    if ((player == null) || (_pScore == null)) {
        return;/*  w ww .j  a  v  a 2 s  .c  om*/
    }
    int score1 = 0;
    if (_pScore.get(player.getObjectId()) != null) {
        score1 = _pScore.get(player.getObjectId());
    }
    _pScore.put(player.getObjectId(), score1 + 1);

    MutableInt points = score.get(player.getObjectId());
    points.increment();

    String text = "";

    switch (_pScore.get(player.getObjectId())) {
    case 0:
    case 1:
        return;
    case 10:
        text = "" + player.getName() + ": Killing Spree";
        break;
    case 20:
        text = "" + player.getName() + ": Rampage";
        break;
    case 30:
        text = "" + player.getName() + ": Unstoppable";
        break;
    case 40:
        text = "" + player.getName() + ": Dominating";
        break;
    case 50:
        text = "" + player.getName() + ": Godlike";
        break;
    case 60:
        text = "" + player.getName() + ": Legendary";
        break;
    case 70:
        text = "" + player.getName() + ": Arena Master";
        break;
    case 80:
        text = "" + player.getName() + ": Best Player";
        break;
    default:
        return;
    }
    for (Player player1 : getPlayers(players_list1)) {
        player1.sendPacket(new ExShowScreenMessage(text, 3000, ScreenMessageAlign.TOP_CENTER, true));
    }

    for (Player player2 : getPlayers(players_list2)) {
        player2.sendPacket(new ExShowScreenMessage(text, 3000, ScreenMessageAlign.TOP_CENTER, true));
    }
}