Example usage for org.apache.commons.collections4.map LazyMap LazyMap

List of usage examples for org.apache.commons.collections4.map LazyMap LazyMap

Introduction

In this page you can find the example usage for org.apache.commons.collections4.map LazyMap LazyMap.

Prototype

protected LazyMap(final Map<K, V> map, final Transformer<? super K, ? extends V> factory) 

Source Link

Document

Constructor that wraps (not copies).

Usage

From source file:com.tussle.postprocess.PostprocessSystem.java

public PostprocessSystem(int p) {
    super(p);/*  www . ja v a2s .c o m*/
    componentListMap = LazyMap.lazyMap(new LinkedHashMap<Class<Component>, Map<Entity, PostprocessStep>>(),
            () -> LazyMap.lazyMap(new LinkedHashMap<>(), FactoryUtils.constantFactory(((Component c) -> {
            }))));
}

From source file:com.haulmont.cuba.core.global.TemplateHelper.java

protected static Map<String, Object> prepareParams(Map<String, ?> parameterValues) {
    Map<String, Object> parameterValuesWithStats = new HashMap<>(parameterValues);
    parameterValuesWithStats.put("statics", BeansWrapper.getDefaultInstance().getStaticModels());

    @SuppressWarnings("unchecked")
    Map<String, Object> params = LazyMap.lazyMap(parameterValuesWithStats, propertyName -> {
        for (String appProperty : AppContext.getPropertyNames()) {
            if (appProperty.replace(".", "_").equals(propertyName)) {
                return AppContext.getProperty(propertyName);
            }/* ww  w. j  av a  2s  .c o m*/
        }
        return null;
    });

    return params;
}

From source file:com.tussle.script.SubactionScriptSystem.java

public SubactionScriptSystem(int i) {
    super(Family.all(ScriptContextComponent.class).get(), i);
    PipeBufferWriter warnStream = new PipeBufferWriter();
    processingErrStream = new PipeBufferWriter();
    stdInProcessor = new JsonDistributingWriter(warnStream);
    stdOutProcessor = new JsonCollectingWriter(warnStream.getNewReader());
    stdErrProcessor = new JsonCollectingWriter(processingErrStream.getNewReader());

    stdinInterpreter = new JsonParsingWriter(processingErrStream);
    destructionSignaller = new Signal<>();
    entityContexts = LazyMap.lazyMap(new HashMap<>(),
            (Entity ent) -> new EntityActionContext(subactionInterpreter.getContext(), new SimpleBindings(), //TODO: Insert API bindings
                    new SimpleBindings(), new SimpleBindings(), stdInProcessor.openReaderFor(ent),
                    stdOutProcessor.openWriterFor(ent), stdErrProcessor.openWriterFor(ent)));
}

From source file:de.alpharogroup.collections.MapExtensions.java

/**
 * Factory method for create a new {@link LazyMap} from commons-collections4.
 *
 * @param <K>//  w  w  w  .ja  v a  2  s .  co m
 *            the generic type of the key
 * @param <V>
 *            the generic type of the value
 *
 * @return The new {@link LazyMap}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, V> Map<K, V> newLazyMap() {
    return LazyMap.lazyMap(new HashMap<K, V>(), new InstantiateFactory(HashMap.class));
}

From source file:com.tussle.motion.MotionSystem.java

public CollisionTriad ecbHit(Map<StageElement<CollisionStadium>, CollisionStadium> beforeBoxes,
        Map<StageElement<CollisionStadium>, CollisionStadium> afterBoxes,
        Map<StageElement, CollisionShape> beforeSurfaces, Map<StageElement, CollisionShape> afterSurfaces,
        CollisionMap fores) {// ww  w.  jav a2s  .  c  om
    if (fores.isEmpty())
        return null;

    //Split the given surfaces into two groups: those which are not worth timestep subdividing,
    //and those which are
    Predicate<Pair<StageElement<CollisionStadium>, StageElement>> splitHeuristic = (
            Pair<StageElement<CollisionStadium>, StageElement> m) -> {
        StageElement<CollisionStadium> c = m.getLeft();
        StageElement s = m.getRight();
        double[] velocity = Utility.displacementDiff(beforeSurfaces.get(s), afterSurfaces.get(s),
                beforeBoxes.get(c), afterBoxes.get(c));
        return FastMath.hypot(velocity[0], velocity[1]) >= PIXEL_STEP;
    };

    if (fores.keySet().stream().anyMatch(splitHeuristic)) {
        //Split in half, and run
        Map<StageElement<CollisionStadium>, CollisionStadium> middleBoxes = LazyMap.lazyMap(new HashMap<>(),
                (StageElement<CollisionStadium> c) -> beforeBoxes.get(c).interpolate(afterBoxes.get(c)));
        Map<StageElement, CollisionShape> middleSurfaces = LazyMap.lazyMap(new HashMap<>(),
                (StageElement s) -> beforeSurfaces.get(s).interpolate(afterSurfaces.get(s)));
        CollisionTriad latestHit = ecbHit(beforeBoxes, middleBoxes, beforeSurfaces, middleSurfaces, fores);

        Map<StageElement<CollisionStadium>, CollisionStadium> postMiddleBoxes;
        Map<StageElement<CollisionStadium>, CollisionStadium> postAfterBoxes;
        Map<StageElement, CollisionShape> postMiddleSurfaces;
        Map<StageElement, CollisionShape> postAfterSurfaces;
        if (latestHit != null) {
            double xDisp = latestHit.cumulativeX;
            double yDisp = latestHit.cumulativeY;
            postMiddleBoxes = LazyMap.lazyMap(new HashMap<>(),
                    (StageElement<CollisionStadium> c) -> middleBoxes.get(c).displacementBy(xDisp, yDisp));
            postAfterBoxes = LazyMap.lazyMap(new HashMap<>(),
                    (StageElement<CollisionStadium> c) -> afterBoxes.get(c).displacementBy(xDisp, yDisp));
            postMiddleSurfaces = LazyMap.lazyMap(new HashMap<>(),
                    (StageElement s) -> middleSurfaces.get(s).displacementBy(xDisp, yDisp));
            postAfterSurfaces = LazyMap.lazyMap(new HashMap<>(),
                    (StageElement s) -> afterSurfaces.get(s).displacementBy(xDisp, yDisp));
        } else {
            postMiddleBoxes = middleBoxes;
            postAfterBoxes = afterBoxes;
            postMiddleSurfaces = middleSurfaces;
            postAfterSurfaces = afterSurfaces;
        }

        //Populate a new collision map for the second half
        CollisionMap mids = new CollisionMap();
        for (Map.Entry<Pair<StageElement<CollisionStadium>, StageElement>, ProjectionVector> foreEntry : fores
                .entrySet()) {
            StageElement<CollisionStadium> c = foreEntry.getKey().getLeft();
            StageElement s = foreEntry.getKey().getRight();
            mids.put(c, s, s.getBefore().interpolate(s.getAfter()).depth(postMiddleBoxes.get(c)));
        }
        CollisionTriad secondHalfHit = ecbHit(postMiddleBoxes, postAfterBoxes, postMiddleSurfaces,
                postAfterSurfaces, mids);
        if (secondHalfHit != null)
            latestHit = latestHit == null ? secondHalfHit : new CollisionTriad(latestHit, secondHalfHit);
        return latestHit;
    } else {
        //Take the whole step at once
        CollisionMap afts = new CollisionMap();
        for (Pair<StageElement<CollisionStadium>, StageElement> foreKey : fores.keySet()) {
            if (foreKey.getRight().getBefore().collidesWith(beforeBoxes.get(foreKey.getLeft()))
                    || foreKey.getRight().getAfter().collidesWith(afterBoxes.get(foreKey.getLeft()))) {
                afts.put(foreKey, foreKey.getRight().getAfter().depth(afterBoxes.get(foreKey.getLeft())));
            }
        }
        ProjectionVector combinedVectors = Utility.combineProjections(Utility.prunedProjections(afts.values()));
        return combinedVectors == null ? null : new CollisionTriad(combinedVectors);
    }
}

From source file:org.opendolphin.mvndemo.clientlazy.DemoController.java

private void initLazyModle(String[] colNames) {
    lazyModel.clear();//from   www  .  ja va2  s .  c  om
    Factory<SimpleStringProperty> factory = new Factory<SimpleStringProperty>() {
        public SimpleStringProperty create() {
            return new SimpleStringProperty("...");
        }
    };
    for (String colName : colNames) {
        Map<String, SimpleStringProperty> colProps = LazyMap
                .lazyMap(new HashMap<String, SimpleStringProperty>(), factory);
        lazyModel.add(colProps);
    }
}

From source file:org.settings4j.util.ELConnectorWrapper.java

/**
 * Usage: <code>${connectors.string['xyz']}</code> returns the first founded Value in all Connectors:
 * <code>connector.getString("xyz");</code>.
 *
 * @return the first founded Value in all connectors
 *//*  ww  w .j  a  v a  2s . c om*/
public Map<String, String> getString() {
    final Transformer<String, String> transformer = new Transformer<String, String>() {

        @Override
        public String transform(final String key) {
            if (key != null) {
                for (Connector connector : ELConnectorWrapper.this.connectors) {
                    final String result = connector.getString(key);
                    if (result != null) {
                        return result;
                    }
                }
            }
            return null;
        }
    };
    return LazyMap.lazyMap(new HashMap<String, String>(), transformer);
}

From source file:org.settings4j.util.ELConnectorWrapper.java

/**
 * Usage: <code>${connectors.content['xyz']}</code> returns the first founded Value in all Connectors:
 * <code>connector.getContent("xyz");</code>.
 *
 * @return the first founded Value in all connectors
 *//*  w ww . j a  v  a 2  s. c  om*/
public Map<String, byte[]> getContent() {
    final Transformer<String, byte[]> transformer = new Transformer<String, byte[]>() {

        // SuppressWarnings PMD.ReturnEmptyArrayRatherThanNull: returning null for this byte-Arrays is OK.
        @Override
        @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull")
        public byte[] transform(final String key) {
            if (key != null) {
                for (Connector connector : ELConnectorWrapper.this.connectors) {
                    final byte[] result = connector.getContent(key);
                    if (result != null) {
                        return result;
                    }
                }
            }
            return null;
        }
    };
    return LazyMap.lazyMap(new HashMap<String, byte[]>(), transformer);
}

From source file:org.settings4j.util.ELConnectorWrapper.java

/**
 * Usage: <code>${connectors.object['xyz']}</code> returns the first founded Value in all Connectors:
 * <code>connector.getObject("xyz");</code>.
 *
 * @return the first founded Value in all connectors
 *//*from   www  . j  a va  2s . com*/
public Map<String, Object> getObject() {
    final Transformer<String, Object> transformer = new Transformer<String, Object>() {

        @Override
        public Object transform(final String key) {
            if (key != null) {
                for (Connector connector : ELConnectorWrapper.this.connectors) {
                    final Object result = connector.getObject(key);
                    if (result != null) {
                        return result;
                    }
                }
            }
            return null;
        }
    };
    return LazyMap.lazyMap(new HashMap<String, Object>(), transformer);
}

From source file:org.settings4j.util.ExpressionLanguageUtilTest.java

/**
 * TestCase for {@link LazyMap#lazyMap(Map, org.apache.commons.collections4.Factory)}
 * and {@link MatchPatternTransformer}.// ww  w . j  a va 2 s. c o  m
 *
 * @throws Exception if an error occurs.
 */
@Test
public void testLazyMapMatchPattern() throws Exception {

    // the Map with all params
    Map<String, Object> context = new HashMap<String, Object>();

    /*
     * A complex Test to parse a LazyMap and access the dynamic generated values
     */
    context.put("test",
            LazyMap.lazyMap(new HashMap<String, Boolean>(), new MatchPatternTransformer("testString")));

    Assert.assertTrue(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['testString']}", context, Boolean.class)).booleanValue());
    Assert.assertFalse(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['teststring']}", context, Boolean.class)).booleanValue());
    Assert.assertFalse(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['tesString']}", context, Boolean.class)).booleanValue());
    Assert.assertTrue(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['.*String']}", context, Boolean.class)).booleanValue());
    Assert.assertFalse(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['.*string']}", context, Boolean.class)).booleanValue());
    Assert.assertTrue(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['test.*']}", context, Boolean.class)).booleanValue());
    Assert.assertFalse(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['askjlf.*']}", context, Boolean.class)).booleanValue());
    Assert.assertFalse(((Boolean) ExpressionLanguageUtil.evaluateExpressionLanguage(//
            "${test['invalid Expresion: \\\\']}", context, Boolean.class)).booleanValue());

}