Search in sources :

Example 6 with MutableInteger

use of jodd.mutable.MutableInteger in project jodd by oblac.

the class FuturesTest method testFailAfterOnManyTasks.

@Test
public void testFailAfterOnManyTasks() throws ExecutionException, InterruptedException {
    MutableInteger execCount = new MutableInteger();
    MutableInteger interruptCount = new MutableInteger();
    final CompletableFuture<String> asyncCode1 = CompletableFuture.supplyAsync(() -> {
        ThreadUtil.sleep(1000);
        execCount.value++;
        return "done";
    });
    final CompletableFuture<String> asyncCode2 = CompletableFuture.supplyAsync(() -> {
        ThreadUtil.sleep(2000);
        execCount.value++;
        return "done";
    });
    final CompletableFuture<String> asyncCode3 = CompletableFuture.supplyAsync(() -> {
        ThreadUtil.sleep(3000);
        execCount.value++;
        return "done";
    });
    CompletableFuture<String> f1 = Futures.within(asyncCode1, Duration.ofMillis(1500)).exceptionally(throwable -> {
        interruptCount.value++;
        return null;
    });
    CompletableFuture<String> f2 = Futures.within(asyncCode2, Duration.ofMillis(1500)).exceptionally(throwable -> {
        interruptCount.value++;
        return null;
    });
    CompletableFuture<String> f3 = Futures.within(asyncCode3, Duration.ofMillis(1500)).exceptionally(throwable -> {
        interruptCount.value++;
        return null;
    });
    CompletableFuture.allOf(f1, f2, f3).get();
    assertEquals(1, execCount.value);
    assertEquals(2, interruptCount.value);
}
Also used : MutableInteger(jodd.mutable.MutableInteger) Test(org.junit.Test)

Example 7 with MutableInteger

use of jodd.mutable.MutableInteger in project jodd by oblac.

the class LFUCacheTest method testOnRemove.

@Test
public void testOnRemove() {
    final MutableInteger mutableInteger = new MutableInteger();
    Cache<String, String> cache = new LFUCache<String, String>(2) {

        @Override
        protected void onRemove(String key, String cachedObject) {
            mutableInteger.value++;
        }
    };
    cache.put("1", "val1");
    cache.put("2", "val2");
    assertEquals(0, mutableInteger.value);
    cache.put("3", "val3");
    assertEquals(2, mutableInteger.value);
}
Also used : MutableInteger(jodd.mutable.MutableInteger) Test(org.junit.Test)

Example 8 with MutableInteger

use of jodd.mutable.MutableInteger in project jodd by oblac.

the class FindFileTest method testTwoAccept.

@Test
public void testTwoAccept() {
    FindFile ff = new WildcardFindFile().include("**/*file/a.png").include("**/*file/a.txt").setRecursive(true).setIncludeDirs(true).searchPath(dataRoot);
    final MutableInteger countFiles = new MutableInteger();
    final MutableInteger countDirs = new MutableInteger();
    ff.find(new FileConsumer() {

        @Override
        public boolean onFile(File f) {
            if (f.isDirectory()) {
                countDirs.value++;
            } else {
                countFiles.value++;
                String path = f.getAbsolutePath();
                path = FileNameUtil.separatorsToUnix(path);
                if (!path.startsWith("/")) {
                    path = '/' + path;
                }
                boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt");
                assertTrue(matched);
            }
            return true;
        }
    });
    assertEquals(0, countDirs.value);
    assertEquals(2, countFiles.value);
}
Also used : MutableInteger(jodd.mutable.MutableInteger) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FileConsumer(jodd.io.findfile.FileConsumer) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) RegExpFindFile(jodd.io.findfile.RegExpFindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) Test(org.junit.Test)

Example 9 with MutableInteger

use of jodd.mutable.MutableInteger in project jodd by oblac.

the class FormProcessorVisitor method valueToString.

/**
	 * Converts value to a string.
	 */
protected String valueToString(String name, Object valueObject) {
    if (!valueObject.getClass().isArray()) {
        return valueObject.toString();
    }
    // array
    String[] array = (String[]) valueObject;
    if (valueNameIndexes == null) {
        valueNameIndexes = new HashMap<>();
    }
    MutableInteger index = valueNameIndexes.get(name);
    if (index == null) {
        index = new MutableInteger(0);
        valueNameIndexes.put(name, index);
    }
    if (index.value >= array.length) {
        return null;
    }
    String result = array[index.value];
    index.value++;
    return result;
}
Also used : MutableInteger(jodd.mutable.MutableInteger)

Example 10 with MutableInteger

use of jodd.mutable.MutableInteger in project jodd by oblac.

the class ObjectUtilTest method testCloneViaSerialization.

@Test
public void testCloneViaSerialization() throws Exception {
    MutableInteger mu = new MutableInteger(183);
    MutableInteger mu2 = ObjectUtil.cloneViaSerialization(mu);
    assertFalse(mu == mu2);
    assertTrue(mu.equals(mu2));
    assertEquals(mu.intValue(), mu2.intValue());
}
Also used : MutableInteger(jodd.mutable.MutableInteger) Test(org.junit.Test)

Aggregations

MutableInteger (jodd.mutable.MutableInteger)11 Test (org.junit.Test)6 MutableIntegerConverter (jodd.typeconverter.impl.MutableIntegerConverter)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 FileConsumer (jodd.io.findfile.FileConsumer)1 FindFile (jodd.io.findfile.FindFile)1 RegExpFindFile (jodd.io.findfile.RegExpFindFile)1 WildcardFindFile (jodd.io.findfile.WildcardFindFile)1 EmptyTagVisitor (jodd.lagarto.EmptyTagVisitor)1 LagartoParser (jodd.lagarto.LagartoParser)1 Tag (jodd.lagarto.Tag)1 MutableByte (jodd.mutable.MutableByte)1 MutableDouble (jodd.mutable.MutableDouble)1 MutableFloat (jodd.mutable.MutableFloat)1 MutableLong (jodd.mutable.MutableLong)1 MutableShort (jodd.mutable.MutableShort)1