Package com.ajjpj.amapper.core2.tpe

Examples of com.ajjpj.amapper.core2.tpe.AQualifier


    public R expectedEntryFor(AQualifiedSourceAndTargetType key, APath path) {
        final AOption<R> raw = tryEntryFor(key);

        if(raw.isEmpty()) {
            throw new AMapperException(notFoundMessage + key, path);
        }
        return raw.get();
    }
View Full Code Here


    public void register(Object source, Object target, APath path) {
        if(map.containsKey(source)) {
            final Object prev = map.get(source);
            if(prev == target) {
                throw new AMapperException("duplicate registration of same target " + target + " for " + source, path);
            }
            else {
                throw new  AMapperException("duplicate registration of different target " + target + " and " + prev + " for " + source, path);
            }
        }
        else {
            map.put(source, AOption.some(target));
        }
View Full Code Here

        final AQualifiedSourceAndTargetType elementTypes = new AQualifiedSourceAndTargetType(h.elementType(types.sourceType), types.sourceQualifier, h.elementType(types.targetType), types.targetQualifier);

        if(targetColl.isEmpty()) {
            // this is an optimization for the common case that the target collection is initially empty
            for(Object s: sourceColl) {
                final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(s, types));

                final AOption<Object> optT = worker.map(elPath, s, null, elementTypes, context);
                if(optT.isDefined()) {
                    targetColl.add(optT.get());
                }
            }
            return h.fromJuCollection(targetColl, types.target());
        }

        final Equiv equiv = new Equiv(sourceColl, targetColl, types, worker.getIdentifierExtractor());

        // now apply the changes to the target collection
        targetColl.removeAll(equiv.targetWithoutSource);
        for (Object s: equiv.sourceWithoutTarget) {
            final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(s, types));
            final AOption<Object> tc = worker.map(elPath, s, null, elementTypes, context);
            if(tc.isDefined()) {
                targetColl.add(tc.get());
            }
        }
        for (Map.Entry<Object, Object> e: equiv.equiv.entrySet()) {
            final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(e.getKey(), types));
            final AOption<Object> tc = worker.map(elPath, e.getKey(), e.getValue(), elementTypes, context);

            if(tc.isEmpty()) {
                targetColl.remove(e.getValue());
            }
View Full Code Here

        final Equiv equiv = new Equiv(sourceOldColl, sourceNewColl, sourceTypes, worker.getIdentifierExtractor());

        // elements present in both old and new collection: no difference as far as the collection is concerned, recursive diff
        for(Map.Entry<Object,Object> e: equiv.equiv.entrySet()) {
            final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(e.getKey(), elementTypes));
            worker.diff(elPath, e.getKey(), e.getValue(), elementTypes, contextOld, contextNew, isDerived);
        }

        // elements only in the new collection: 'added' diff element + recursive diff with 'derived' = true
        for(Object newEl: equiv.targetWithoutSource) {
            final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(newEl, elementTypes));
            worker.diff(elPath, null, newEl, elementTypes, contextOld, contextNew, isDerived);
        }

        // elements only in the old collection: 'removed' diff element + recursive diff with 'derived' = true
        for(Object oldEl: equiv.sourceWithoutTarget) {
            final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(oldEl, elementTypes));
            worker.diff(elPath, oldEl, null, elementTypes, contextOld, contextNew, isDerived);
        }
    }
View Full Code Here

        if(source == null) {
            return null;
        }

        final Collection<Object> targetColl = target != null ? h.asJuCollection(target, types.target()) : h.createEmptyCollection(types.target());
        final AQualifiedSourceAndTargetType elementTypes = new AQualifiedSourceAndTargetType(h.elementType(types.sourceType), types.sourceQualifier, h.elementType(types.targetType), types.targetQualifier);

        if(targetColl.isEmpty()) {
            // this is an optimization for the common case that the target collection is initially empty
            for(Object s: sourceColl) {
                final APath elPath = ACollectionMappingTools.elementPath(path, worker.getIdentifierExtractor().uniqueIdentifier(s, types));
View Full Code Here

        final ACollectionHelper h = worker.getHelpers();

        final Collection<Object> sourceOldColl = h.asJuCollection(sourceOld, types.source());
        final Collection<Object> sourceNewColl = h.asJuCollection(sourceNew, types.target());

        final AQualifiedSourceAndTargetType elementTypes = new AQualifiedSourceAndTargetType(h.elementType(types.sourceType), types.sourceQualifier, h.elementType(types.targetType), types.targetQualifier);
        final AQualifiedSourceAndTargetType sourceTypes = new AQualifiedSourceAndTargetType(types.sourceType, types.sourceQualifier, types.sourceType, types.sourceQualifier);

        final Equiv equiv = new Equiv(sourceOldColl, sourceNewColl, sourceTypes, worker.getIdentifierExtractor());

        // elements present in both old and new collection: no difference as far as the collection is concerned, recursive diff
        for(Map.Entry<Object,Object> e: equiv.equiv.entrySet()) {
View Full Code Here

        public Equiv(Collection<Object> sourceColl, Collection<Object> targetColl, AQualifiedSourceAndTargetType types, AIdentifierExtractor identifierExtractor) {
            targetWithoutSource.addAll(targetColl);

            // 'types' for calculating target element identifiers in term of the target type
            final AQualifiedSourceAndTargetType targetTypes = new AQualifiedSourceAndTargetType(types.targetType, types.targetQualifier, types.targetType, types.targetQualifier);

            // iterate through all source elements and sort source / target elements according to identifier equality
            for(Object s: sourceColl) {
                final Object sourceIdent = identifierExtractor.uniqueIdentifier(s, types);
                final AOption<Object> equivTarget = findTarget(targetColl, sourceIdent, identifierExtractor, targetTypes);
View Full Code Here

        }

        this.sourceProp = sourceProp;
        this.targetProp = targetProp;

        this.types = new AQualifiedSourceAndTargetType (sourceProp.getType(), sourceProp.getSourceQualifier(), targetProp.getType(), targetProp.getTargetQualifier());
    }
View Full Code Here

    }

    @Override public AOption<Object> map(Object source, AType sourceType, AQualifier sourceQualifier, Object target, AType targetType, AQualifier targetQualifier) throws Exception {
        final Queue<AVoidFunction0<Exception>> deferredWork = new LinkedList<AVoidFunction0<Exception>>();
        final AMapperWorker<H> worker = new AMapperWorkerImpl<H>(valueMappings, objectMappings, logger, helperFactory.apply(), identifierExtractor, contextExtractor, preProcessors, postProcessors, deferredWork);
        final AOption<Object> result = worker.map(APath.EMPTY, source, target, new AQualifiedSourceAndTargetType(sourceType, sourceQualifier, targetType, targetQualifier), EMPTY_CONTEXT);

        while(!deferredWork.isEmpty()) {
            deferredWork.remove().apply();
        }
View Full Code Here

    }

    @Override public ADiff diff(Object sourceOld, Object sourceNew, AType sourceType, AQualifier sourceQualifier, AType targetType, AQualifier targetQualifier) throws Exception {
        final Queue<AVoidFunction0<Exception>> deferredWork = new LinkedList<AVoidFunction0<Exception>>();
        final AMapperDiffWorkerImpl worker = new AMapperDiffWorkerImpl(valueMappings, objectMappings, logger, helperFactory.apply(), identifierExtractor, contextExtractor, preProcessors, deferredWork);
        worker.diff(APath.EMPTY, sourceOld, sourceNew, new AQualifiedSourceAndTargetType(sourceType, sourceQualifier, targetType, targetQualifier), EMPTY_CONTEXT, EMPTY_CONTEXT, false);

        while(!deferredWork.isEmpty()) {
            deferredWork.remove().apply();
        }
View Full Code Here

TOP

Related Classes of com.ajjpj.amapper.core2.tpe.AQualifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.