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() 

Source Link

Document

Constructs a new MutableInt with the default value of zero.

Usage

From source file:com.mgmtp.jfunk.core.module.TestModuleImplTest.java

@BeforeMethod
public void setUp() {
    counter = new MutableInt();
    module = new CountingTestModul(counter);
    module.stepExecutor = new StepExecutor(mock(Injector.class), mock(EventBus.class));
}

From source file:be.shad.tsqb.test.SelectionMergerTest.java

@Test
public void testSubselectValueMergerIsCalledAfterOtherSetters() {
    TestDataCreator creator = new TestDataCreator(getSessionFactory());
    Town town = creator.createTestTown();
    creator.createTestPerson(town, "JohnyTheKid");
    creator.createTestPerson(town, "Josh");

    Person personProxy = query.from(Person.class);

    PersonDto personDtoProxy = query.select(PersonDto.class);
    personDtoProxy.setId(personProxy.getId());
    personDtoProxy.setPersonAge(personProxy.getAge());

    final MutableInt counter = new MutableInt();
    SelectValue<String> subselectProxy = query.selectMergeValues(personDtoProxy,
            new SelectionMerger1<PersonDto, String>() {
                @Override/*from  w ww .j  a  v a 2  s .c  om*/
                public void mergeValueIntoResult(PersonDto partialResult, String personName) {
                    if (partialResult.getId() == null) {
                        fail("The ID property should be set before the value is merged into the dto.");
                    }
                    counter.increment();
                }
            });
    subselectProxy.setValue(personProxy.getName());

    validate("select hobj1.id as id, hobj1.age as personAge, hobj1.name as g1__value from Person hobj1");
    assertEquals("The merger should've been called for each row, expected 2 rows.", 2,
            counter.getValue().intValue());
}

From source file:com.mgmtp.jfunk.core.util.CsvDataProcessorTest.java

@Test
public void testCsvDataProcessor() {
    final Configuration config = new Configuration(Charsets.UTF_8);
    config.put("foo", "foovalue");

    final DataSource dataSource = new TestDataSource(config);

    CsvDataProcessor csvProc = new CsvDataProcessor(Providers.of(config), Providers.of(dataSource));
    final MutableInt counter = new MutableInt();

    csvProc.processFile(new StringReader(CSV_LINES), ";", '\0', new Runnable() {
        @Override// w ww  .j a  v a  2  s  . co  m
        public void run() {
            // generate does this
            dataSource.getNextDataSet("test");

            int counterValue = counter.intValue();
            assertEquals(config.get("foo"), "foo" + counterValue);
            assertEquals(dataSource.getCurrentDataSet("test").getValue("testKey1"),
                    "newTestValue1" + counterValue);
            assertEquals(dataSource.getCurrentDataSet("test").getValue("testKey2"), "testValue2");

            // write some random fixed values, which should be overridden/reset from CSV values
            dataSource.setFixedValue("test", "testKey1", "blablubb");
            dataSource.setFixedValue("test", "testKey2", "blablubb");

            counter.increment();
        }
    });
}

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);/*from   ww w. j ava2 s.c  o  m*/
    }

    counter.increment();
    return true;
}

From source file:com.mgmtp.jfunk.core.util.ScreenCapturerTest.java

@Test(dataProvider = "exception", groups = "excludeFromCI")
public void testHandleEvent(final Exception ex) {
    testFileOrDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    MutableInt counter = new MutableInt();

    Set<Class<? extends AbstractBaseEvent>> eventClasses = ImmutableSet
            .<Class<? extends AbstractBaseEvent>>of(BeforeModuleEvent.class);
    ScreenCapturer capturer = new ScreenCapturer(Providers.of(testFileOrDir), eventClasses,
            Providers.of(counter), ex != null);

    // get value before it is incremented
    int c = counter.intValue();

    EventBus eventBus = new EventBus();
    eventBus.register(capturer);// w  w w  . j  a  v a 2s  .  c o  m
    eventBus.post(new BeforeModuleEvent(new DummyModule()));
    eventBus.post(new AfterModuleEvent(new DummyModule(), ex));

    assertThat(new File(testFileOrDir, String.format("screenshots/%04d_BeforeModuleEvent.png", c))).exists();

    // no configured for screenshot

    if (ex == null) {
        assertThat(new File(testFileOrDir, String.format("screenshots/%04d_AfterModuleEvent.png", ++c)))
                .doesNotExist();
        assertThat(new File(testFileOrDir, String.format("screenshots/%04d_AfterModuleEvent_error.png", ++c)))
                .doesNotExist();
    } else {
        assertThat(new File(testFileOrDir, String.format("screenshots/%04d_AfterModuleEvent_error.png", ++c)))
                .exists();
    }
}

From source file:com.mgmtp.jfunk.web.util.DumpFileCreator.java

/**
 * Computes the best file to save the response to the current page.
 *//*ww w  .ja  va2  s. c  o m*/
public File createDumpFile(final File dir, final String extension, final String urlString,
        final String additionalInfo) {
    URI uri = URI.create(urlString);
    String path = uri.getPath();
    if (path == null) {
        log.warn("Cannot create dump file for URI: " + uri);
        return null;
    }

    String name = PATTERN_FIRST_LAST_SLASH.matcher(path).replaceAll("$1");
    name = PATTERN_ILLEGAL_CHARS.matcher(name).replaceAll("_");

    Key key = Key.get(dir.getPath(), extension);
    MutableInt counter = countersMap.get(key);
    if (counter == null) {
        counter = new MutableInt();
        countersMap.put(key, counter);
    }

    int counterValue = counter.intValue();
    counter.increment();

    StringBuilder sb = new StringBuilder();
    sb.append(String.format("%04d", counterValue));
    sb.append('_');
    sb.append(name);
    if (StringUtils.isNotBlank(additionalInfo)) {
        sb.append("_");
        sb.append(additionalInfo);
    }
    sb.append(".");
    sb.append(extension);

    return new File(dir, sb.toString());
}

From source file:com.mgmtp.perfload.perfalyzer.binning.ErrorCountBinningStragegy.java

@Override
public void binData(final Scanner scanner, final WritableByteChannel destChannel) throws IOException {
    BinManager binManager = new BinManager(startOfFirstBin, PerfAlyzerConstants.BIN_SIZE_MILLIS_30_SECONDS);

    while (scanner.hasNextLine()) {
        tokenizer.reset(scanner.nextLine());
        String[] tokens = tokenizer.getTokenArray();

        long timestampMillis = Long.parseLong(tokens[0]);

        boolean isError = "ERROR".equals(tokens[MEASURING_NORMALIZED_COL_RESULT]);
        if (isError) {
            String errorMsg = tokens[MEASURING_NORMALIZED_COL_ERROR_MSG];
            MutableInt errorsByTypeCounter = errorsByType.get(errorMsg);
            if (errorsByTypeCounter == null) {
                errorsByTypeCounter = new MutableInt();
                errorsByType.put(errorMsg, errorsByTypeCounter);
            }//from   w w  w .  j a v a  2s .  c om
            errorsByTypeCounter.increment();

            binManager.addValue(timestampMillis);
        }
    }

    binManager.toCsv(destChannel, "seconds", "count", intNumberFormat);
}

From source file:be.shad.tsqb.test.SelectionMergerTest.java

/**
 * Test selecting the same property path in the same query multiple times
 * doesn't generate overlapping aliases.
 *//*ww  w . j  a  va 2 s  . c o  m*/
@Test
public void testMultipleSubselectValueMergersWithSameSubpath() {
    TestDataCreator creator = new TestDataCreator(getSessionFactory());
    Town town = creator.createTestTown();
    creator.createTestPerson(town, "JohnyTheKid");
    creator.createTestPerson(town, "Josh");

    Person personProxy = query.from(Person.class);

    PersonDto personDtoProxy = query.select(PersonDto.class);
    personDtoProxy.setId(personProxy.getId());
    personDtoProxy.setPersonAge(personProxy.getAge());

    final MutableInt counter = new MutableInt();
    SelectValue<String> subselectProxy = query.selectMergeValues(personDtoProxy,
            new SelectionMerger1<PersonDto, String>() {
                @Override
                public void mergeValueIntoResult(PersonDto partialResult, String personName) {
                    if (partialResult.getId() == null) {
                        fail("The ID property should be set before the value is merged into the dto.");
                    }
                    counter.increment();
                }
            });
    subselectProxy.setValue(personProxy.getName());

    final MutableInt counter2 = new MutableInt();
    SelectValue<Integer> subselectProxy2 = query.selectMergeValues(personDtoProxy,
            new SelectionMerger1<PersonDto, Integer>() {
                @Override
                public void mergeValueIntoResult(PersonDto partialResult, Integer personAge) {
                    if (partialResult.getId() == null) {
                        fail("The ID property should be set before the value is merged into the dto.");
                    }
                    counter2.increment();
                }
            });
    subselectProxy2.setValue(personProxy.getAge());

    validate(
            "select hobj1.id as id, hobj1.age as personAge, hobj1.name as g1__value, hobj1.age as g2__value from Person hobj1");
    assertEquals("The merger should've been called for each row, expected 2 rows.", 2,
            counter.getValue().intValue());
    assertEquals("The merger should've been called for each row, expected 2 rows.", 2,
            counter2.getValue().intValue());
}

From source file:com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerGaeMinimalTest.java

/**
 * @throws Exception if an error occurs//w w w .j  av  a2s  .  co  m
 */
@Test
public void addJob_multipleExecution_removeJob() throws Exception {
    final MutableInt id = new MutableInt();
    final MutableInt count = new MutableInt(0);
    final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) {
        @Override
        public void run() {
            count.increment();
            if (count.intValue() >= 5) {
                manager_.removeJob(id.intValue());
            }
        }
    };
    id.setValue(manager_.addJob(job, page_));
    final int executedJobs = eventLoop_.pumpEventLoop(1000);
    assertEquals(5, executedJobs);
    assertEquals(5, count.intValue());
}

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 va  2s. c  om*/
        count.increment();
        thisInstance.getStatuses().put(status, count);
        totalRoot++;
    }
    thisInstance.setTotalRoots(totalRoot);
    return thisInstance;
}