Example usage for com.google.common.collect LinkedHashMultiset create

List of usage examples for com.google.common.collect LinkedHashMultiset create

Introduction

In this page you can find the example usage for com.google.common.collect LinkedHashMultiset create.

Prototype

public static <E> LinkedHashMultiset<E> create() 

Source Link

Document

Creates a new, empty LinkedHashMultiset using the default initial capacity.

Usage

From source file:org.sonar.api.utils.KeyValueFormat.java

/**
 * @since 2.7//from  w  ww.j  av  a 2  s  .  c  o m
 */
public static <K> Multiset<K> parseMultiset(String data, Converter<K> keyConverter) {
    Multiset<K> multiset = LinkedHashMultiset.create();// to keep the same order
    if (data != null) {
        String[] pairs = StringUtils.split(data, PAIR_SEPARATOR);
        for (String pair : pairs) {
            String[] keyValue = StringUtils.split(pair, FIELD_SEPARATOR);
            String key = keyValue[0];
            String value = (keyValue.length == 2 ? keyValue[1] : "0");
            multiset.add(keyConverter.parse(key), new IntegerConverter().parse(value));
        }
    }
    return multiset;
}

From source file:org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures.java

protected void computeAllOperationsFromSortedSuperTypes(JvmDeclaredType rootType,
        final Multimap<String, AbstractResolvedOperation> processedOperations) {
    class SuperTypes extends TypesSwitch<Boolean> {

        private Multiset<JvmType> interfaces = LinkedHashMultiset.create();
        private Set<JvmType> notInterfaces = Sets.newLinkedHashSet();

        public SuperTypes(JvmDeclaredType rootType) {
            doSwitch(rootType);// w  ww . j a v a 2 s. c  om
        }

        @Override
        public Boolean doSwitch(EObject theEObject) {
            if (theEObject == null)
                return Boolean.FALSE;
            return super.doSwitch(theEObject);
        }

        @Override
        public Boolean caseJvmTypeReference(JvmTypeReference object) {
            return doSwitch(object.getType());
        }

        @Override
        public Boolean caseJvmType(JvmType object) {
            return notInterfaces.add(object);
        }

        @Override
        public Boolean caseJvmDeclaredType(JvmDeclaredType object) {
            if (notInterfaces.add(object)) {
                for (JvmTypeReference superType : object.getSuperTypes()) {
                    doSwitch(superType);
                }
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }

        @Override
        public Boolean caseJvmGenericType(JvmGenericType object) {
            boolean traverseSuperTypes = false;
            if (object.isInterface()) {
                traverseSuperTypes = interfaces.add(object, 1) == 0;
            } else {
                traverseSuperTypes = notInterfaces.add(object);
            }
            if (traverseSuperTypes) {
                for (JvmTypeReference superType : object.getSuperTypes()) {
                    doSwitch(superType);
                }
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }

        public Collection<JvmType> getSuperTypesNoInterfaces() {
            return notInterfaces;
        }

        public int consumeInterfaceOccurrence(JvmGenericType intf) {
            return interfaces.remove(intf, 1);
        }

    }
    final SuperTypes superTypes = new SuperTypes(rootType);
    for (JvmType superClass : superTypes.getSuperTypesNoInterfaces()) {
        if (superClass instanceof JvmDeclaredType) {
            computeAllOperations((JvmDeclaredType) superClass, processedOperations);
        }
    }

    class SuperInterfaceConsumer extends TypesSwitch<Boolean> {

        private Set<JvmType> seen = Sets.newHashSet();

        @Override
        public Boolean doSwitch(EObject theEObject) {
            if (theEObject == null)
                return Boolean.FALSE;
            return super.doSwitch(theEObject);
        }

        @Override
        public Boolean defaultCase(EObject object) {
            return Boolean.FALSE;
        }

        @Override
        public Boolean caseJvmTypeReference(JvmTypeReference object) {
            return doSwitch(object.getType());
        }

        @Override
        public Boolean caseJvmDeclaredType(JvmDeclaredType object) {
            if (seen.add(object)) {
                for (JvmTypeReference superType : object.getSuperTypes()) {
                    doSwitch(superType);
                }
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }

        @Override
        public Boolean caseJvmGenericType(JvmGenericType object) {
            if (object.isInterface()) {
                int was = superTypes.consumeInterfaceOccurrence(object);
                if (was == 0) {
                    return Boolean.FALSE;
                }
                if (was == 1) {
                    computeAllOperations(object, processedOperations);
                }
                for (JvmTypeReference superType : object.getSuperTypes()) {
                    doSwitch(superType);
                }
                return was > 1;
            } else if (seen.add(object)) {
                for (JvmTypeReference superType : object.getSuperTypes()) {
                    doSwitch(superType);
                }
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }

        public void consume(JvmType rootType) {
            doSwitch(rootType);
        }

    }
    new SuperInterfaceConsumer().consume(rootType);
}

From source file:org.summer.dsl.model.types.util.TypeConformanceComputer.java

/**
 * Compute the common super type for the given types.
 * //w ww . j  a va 2 s .co m
 * May return <code>null</code> in case one of the types is primitive void but not all 
 * of them are.
 */
public JvmTypeReference getCommonSuperType(final List<JvmTypeReference> types) {
    if (types == null || types.isEmpty())
        throw new IllegalArgumentException("Types can't be null or empty " + types);
    if (types.size() == 1)
        return types.get(0);

    // Check the straight forward case - one of the types is a supertype of all the others.
    // Further more check if any of the types is Void.TYPE -> all have to be Void.TYPE
    for (JvmTypeReference type : types) {
        if (conformsToAll(type, types))
            return type;
        if (isPrimitiveVoid(type)) {
            // we saw void but was not conformant to all other
            return null;
        }
    }
    //      if (allTypesAreArrays(types)) {
    //         List<JvmTypeReference> componentTypes = getComponentTypes(types);
    //         JvmTypeReference resultComponent = doGetCommonSuperType(componentTypes, new TypeConformanceComputationArgument(false, false, false));
    //         if (resultComponent != null) {
    //            JvmGenericArrayTypeReference result = factory.createJvmGenericArrayTypeReference();
    //            result.setComponentType(resultComponent);
    //            return result;
    //         }
    //      }
    // TODO handle all primitives
    // TODO handle arrays
    if (containsPrimitiveOrAnyReferences(types)) {
        List<JvmTypeReference> withoutPrimitives = replacePrimitivesAndRemoveAnyReferences(types);
        if (withoutPrimitives.equals(types))
            return null;
        return getCommonSuperType(withoutPrimitives);
    }
    JvmTypeReference firstType = types.get(0);
    final List<JvmTypeReference> tail = types.subList(1, types.size());
    // mapping from rawtype to resolved parameterized types
    // used to determine the correct type arguments
    Multimap<JvmType, JvmTypeReference> all = LinkedHashMultimap.create();
    // cumulated rawtype to max distance (used for sorting)
    Multiset<JvmType> cumulatedDistance = LinkedHashMultiset.create();

    initializeDistance(firstType, all, cumulatedDistance);
    cumulateDistance(tail, all, cumulatedDistance);

    List<Entry<JvmType>> candidates = Lists.newArrayList(cumulatedDistance.entrySet());
    if (candidates.size() == 1) { // only one super type -> should be java.lang.Object
        JvmType firstRawType = candidates.get(0).getElement();
        return getFirstForRawType(all, firstRawType);
    }
    inplaceSortByDistanceAndName(candidates);
    // try to find a matching parameterized type for the raw types in ascending order
    List<JvmTypeReference> referencesWithSameDistance = Lists.newArrayListWithExpectedSize(2);
    int wasDistance = -1;
    boolean classSeen = false;
    outer: for (Entry<JvmType> rawTypeCandidate : candidates) {
        JvmType rawType = rawTypeCandidate.getElement();
        JvmTypeReference result = null;
        if (wasDistance == -1) {
            wasDistance = rawTypeCandidate.getCount();
        } else {
            if (wasDistance != rawTypeCandidate.getCount()) {
                if (classSeen)
                    break;
                result = getTypeParametersForSupertype(all, rawType, types);
                for (JvmTypeReference alreadyCollected : referencesWithSameDistance) {
                    if (isConformant(result, alreadyCollected, true)) {
                        classSeen = classSeen || isClass(rawType);
                        continue outer;
                    }
                }
                wasDistance = rawTypeCandidate.getCount();
            }
        }
        if (result == null)
            result = getTypeParametersForSupertype(all, rawType, types);
        if (result != null) {
            boolean isClass = isClass(rawType);
            classSeen = classSeen || isClass;
            if (isClass)
                referencesWithSameDistance.add(0, result);
            else
                referencesWithSameDistance.add(result);
        }
    }
    if (referencesWithSameDistance.size() == 1) {
        return referencesWithSameDistance.get(0);
    } else if (referencesWithSameDistance.size() > 1) {
        JvmMultiTypeReference result = typeReferences
                .createMultiTypeReference(referencesWithSameDistance.get(0).getType());
        if (result == null)
            return result;
        for (JvmTypeReference reference : referencesWithSameDistance) {
            result.getReferences().add(EcoreUtil2.cloneIfContained(reference));
        }
        return result;
    }
    return null;
}

From source file:org.summer.dsl.xbase.typesystem.conformance.TypeConformanceComputer.java

/**
 * Compute the common super type for the given types.
 * // www. j  a  va 2s .  c o  m
 * May return <code>null</code> in case one of the types is primitive void but not all 
 * of them are.
 */
@Nullable
public LightweightTypeReference getCommonSuperType(final @NonNull List<LightweightTypeReference> types,
        ITypeReferenceOwner owner) {
    if (types == null || types.isEmpty())
        throw new IllegalArgumentException("Types can't be null or empty " + types);
    if (types.size() == 1)
        return types.get(0);

    // Check the straight forward case - one of the types is a supertype of all the others.
    // Further more check if any of the types is Void.TYPE -> all have to be Void.TYPE
    boolean allVoid = true;
    for (LightweightTypeReference type : types) {
        if (!type.isPrimitiveVoid()) {
            allVoid = false;
            break;
        }
    }
    if (allVoid) {
        return types.get(0);
    }
    for (LightweightTypeReference type : types) {
        LightweightTypeReference conformantType = conformsToAll(type, types);
        if (conformantType != null)
            return conformantType;
        if (type.isPrimitiveVoid()) {
            // we saw void but was not all were void
            return null;
        }
    }
    if (containsPrimitiveOrAnyReferences(types)) {
        List<LightweightTypeReference> withoutPrimitives = replacePrimitivesAndRemoveAnyReferences(types);
        if (withoutPrimitives.equals(types))
            return null;
        return getCommonSuperType(withoutPrimitives, owner);
    }
    LightweightTypeReference firstType = types.get(0);
    final List<LightweightTypeReference> tail = types.subList(1, types.size());
    // mapping from rawtype to resolved parameterized types
    // used to determine the correct type arguments
    Multimap<JvmType, LightweightTypeReference> all = LinkedHashMultimap.create();
    // cumulated rawtype to max distance (used for sorting)
    Multiset<JvmType> cumulatedDistance = LinkedHashMultiset.create();

    initializeDistance(firstType, all, cumulatedDistance);
    cumulateDistance(tail, all, cumulatedDistance);

    List<Entry<JvmType>> candidates = Lists.newArrayList(cumulatedDistance.entrySet());
    if (candidates.size() == 1) { // only one super type -> should be java.lang.Object
        JvmType firstRawType = candidates.get(0).getElement();
        return getFirstForRawType(all, firstRawType);
    }
    inplaceSortByDistanceAndName(candidates);
    // try to find a matching parameterized type for the raw types in ascending order
    List<LightweightTypeReference> referencesWithSameDistance = Lists.newArrayListWithExpectedSize(2);
    int wasDistance = -1;
    boolean classSeen = false;
    outer: for (Entry<JvmType> rawTypeCandidate : candidates) {
        JvmType rawType = rawTypeCandidate.getElement();
        LightweightTypeReference result = null;
        if (wasDistance == -1) {
            wasDistance = rawTypeCandidate.getCount();
        } else {
            if (wasDistance != rawTypeCandidate.getCount()) {
                if (classSeen)
                    break;
                result = getTypeParametersForSupertype(all, rawType, owner, types);
                for (LightweightTypeReference alreadyCollected : referencesWithSameDistance) {
                    if ((isConformant(result, alreadyCollected,
                            RawTypeConformanceComputer.RAW_TYPE | ALLOW_BOXING_UNBOXING
                                    | ALLOW_PRIMITIVE_WIDENING | ALLOW_SYNONYMS | ALLOW_RAW_TYPE_CONVERSION)
                            & SUCCESS) != 0) {
                        classSeen = classSeen || isClass(rawType);
                        continue outer;
                    }
                }
                wasDistance = rawTypeCandidate.getCount();
            }
        }
        if (result == null)
            result = getTypeParametersForSupertype(all, rawType, owner, types);
        if (result != null) {
            boolean isClass = isClass(rawType);
            classSeen = classSeen || isClass;
            if (isClass)
                referencesWithSameDistance.add(0, result);
            else
                referencesWithSameDistance.add(result);
        }
    }
    if (referencesWithSameDistance.size() == 1) {
        return referencesWithSameDistance.get(0);
    } else if (referencesWithSameDistance.size() > 1) {
        CompoundTypeReference result = new CompoundTypeReference(owner, false);
        for (LightweightTypeReference reference : referencesWithSameDistance) {
            result.addComponent(reference);
        }
        return result;
    }
    return null;
}

From source file:de.hzi.helmholtz.Compare.PathwayComparisonWithModules.java

public Multimap<Double, String> SubsetIdentification(PathwayWithModules firstPathway,
        PathwayWithModules secondPathway, BiMap<Integer, Integer> newSourceGeneIdToPositionMap,
        BiMap<Integer, Integer> newTargetGeneIdToPositionMap, int Yes) {
    Multimap<Double, String> result = TreeMultimap.create(Ordering.natural().reverse(), Ordering.natural());

    Iterator<ModuleGene> sourceGeneIt = firstPathway.moduleGeneIterator();
    int currentQueryGene = 0;
    while (sourceGeneIt.hasNext()) {
        currentQueryGene++;/*  ww w  .j a  v  a  2 s  .com*/
        ModuleGene queryGene = sourceGeneIt.next();
        Multimap<Integer, String> resultr = TreeMultimap.create(Ordering.natural(), Ordering.natural());
        int currentTargetGene = 0;
        Multiset<String> qfunction = LinkedHashMultiset.create();
        List<String> qfunctionList = new ArrayList<String>();
        List<String> qactivity = new ArrayList<String>();
        List<Set<String>> qsubstrate = new ArrayList<Set<String>>();
        for (Module m : queryGene.getModule()) {
            for (Domain d : m.getDomains()) {
                qfunction.add(d.getDomainFunctionString());
                qfunctionList.add(d.getDomainFunctionString());
                qactivity.add(d.getStatus().toString());
                qsubstrate.add(d.getSubstrates());
            }
        }
        List<String> TargenesSelected = new ArrayList<String>();
        Iterator<ModuleGene> targetGeneIt = secondPathway.moduleGeneIterator();
        while (targetGeneIt.hasNext()) {
            currentTargetGene++;
            ModuleGene targetGene = targetGeneIt.next();
            Multiset<String> tfunction = LinkedHashMultiset.create();
            List<String> tactivity = new ArrayList<String>();
            List<Set<String>> tsubstrate = new ArrayList<Set<String>>();
            List<String> tfunctionList = new ArrayList<String>();
            Iterator<Module> mIter = targetGene.moduleIterator();
            while (mIter.hasNext()) {
                Module m = mIter.next();
                Iterator<Domain> dIter = m.domainIterator();
                while (dIter.hasNext()) {
                    Domain d = dIter.next();
                    tfunction.add(d.getDomainFunctionString());
                    tfunctionList.add(d.getDomainFunctionString());
                    tactivity.add(d.getStatus().toString());
                    tsubstrate.add(d.getSubstrates());
                }
            }
            Multiset<String> DomainsCovered = Multisets.intersection(qfunction, tfunction);
            int Differences = Math.max(Math.abs(DomainsCovered.size() - tfunction.size()),
                    Math.abs(DomainsCovered.size() - qfunction.size()));
            if (DomainsCovered.size() == tfunction.size() && tfunction.size() > 4) {
                TargenesSelected.add(Integer.toString(currentTargetGene));
            } else {
                resultr.put(Differences, Integer.toString(currentTargetGene));
            }

        }
        int count = 0;
        if (resultr.size() > 0) {
            while (TargenesSelected.size() < 2) {
                Multiset<String> k = LinkedHashMultiset.create(resultr.values());
                Multiset<String> t = LinkedHashMultiset.create(TargenesSelected);
                Multiset<String> Covered = Multisets.intersection(k, t);
                if (Covered.size() == k.size()) {
                    break;
                }

                try {
                    TargenesSelected.addAll(
                            resultr.get(Integer.parseInt(resultr.keySet().toArray()[count].toString())));
                } catch (Exception ds) {
                }
                count = count + 1;
            }
        }
        // //System.out.println(TargenesSelected);
        //  Permutation perm = new Permutation();
        //  List<String> perms = perm.run(TargenesSelected);
        CombinationGenerator c = new CombinationGenerator(10, 10);
        List<String> perms = c.GenerateAllPossibleCombinations(TargenesSelected);
        myFunction sim = new myFunction();
        double score = 0;
        String targetIdentified = "";
        List<ModuleGene> targetGenesList = secondPathway.getModulegenes();
        for (String permu : perms) {
            String[] values = permu.replace("[", "").replace("]", "").split(",");
            List<String> mergedTargetgenes = new ArrayList<String>();
            List<Integer> ToRemove = new ArrayList<Integer>();
            List<String> tactivity = new ArrayList<String>();
            List<Set<String>> tsubstrate = new ArrayList<Set<String>>();
            for (String j : values) {
                ToRemove.add(Integer.parseInt(j.trim()));
                for (Module m : targetGenesList.get(Integer.parseInt(j.trim()) - 1).getModule()) {
                    for (Domain i : m.getDomains()) {
                        mergedTargetgenes.add(i.getDomainFunctionString());
                        tactivity.add(i.getStatus().toString());
                        tsubstrate.add(i.getSubstrates());
                    }
                }
            }
            Multimap<Double, Multimap<String, Integer>> FunctionScores = sim.calculate(qfunctionList,
                    mergedTargetgenes);
            Multimap<Double, Multimap<String, Integer>> activityscores = myFunction.calculate(qactivity,
                    tactivity);
            Multimap<Double, Multimap<String, Integer>> substratescores = myFunction
                    .calculate(getSubstrateList(qsubstrate), getSubstrateList(tsubstrate));
            Object FunctionScore = FunctionScores.asMap().keySet().toArray()[0];
            Object activityScore = activityscores.asMap().keySet().toArray()[0];
            Object substrateScore = substratescores.asMap().keySet().toArray()[0];

            double finalScore = Math
                    .round((((2.9 * Double.parseDouble(FunctionScore.toString().trim()))
                            + (0.05 * Double.parseDouble(activityScore.toString().trim()))
                            + (0.05 * Double.parseDouble(substrateScore.toString().trim()))) / 3) * 100.0)
                    / 100.0;
            targetIdentified = permu.replace(",", "+");
            String ConvertedGeneIDs = "";
            if (Yes == 0) {
                ConvertedGeneIDs = reconstructWithGeneId(Integer.toString(currentQueryGene),
                        newSourceGeneIdToPositionMap) + "->"
                        + reconstructWithGeneId(targetIdentified.replace("[", "").replace("]", ""),
                                newTargetGeneIdToPositionMap);
            } else {
                ConvertedGeneIDs = reconstructWithGeneId(targetIdentified.replace("[", "").replace("]", ""),
                        newTargetGeneIdToPositionMap) + "->"
                        + reconstructWithGeneId(Integer.toString(currentQueryGene),
                                newSourceGeneIdToPositionMap);
            }
            // String ConvertedGeneIDs = reconstructWithGeneId(Integer.toString(currentQueryGene), newSourceGeneIdToPositionMap) + "->" + reconstructWithGeneId(targetIdentified.replace("[", "").replace("]", ""), newTargetGeneIdToPositionMap);

            result.put(finalScore, ConvertedGeneIDs);

            ScoreFunctionMatchMisMatch.putAll(ConvertedGeneIDs, FunctionScores.values());
            ScoreStatusMatchMisMatch.putAll(ConvertedGeneIDs, activityscores.values());
            ScoreSubstrateMatchMisMatch.putAll(ConvertedGeneIDs, substratescores.values());

        }

    }
    return result;
}

From source file:org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer.java

/**
 * Compute the common super type for the given types.
 * //from ww  w .j  a v  a2s.  c  o  m
 * May return <code>null</code> in case one of the types is primitive void but not all 
 * of them are.
 */
/* @Nullable */
public LightweightTypeReference getCommonSuperType(final /* @NonNull */ List<LightweightTypeReference> types,
        ITypeReferenceOwner owner) {
    if (types == null || types.isEmpty())
        throw new IllegalArgumentException("Types can't be null or empty " + types);
    if (types.size() == 1)
        return types.get(0);

    // Check the straight forward case - one of the types is a supertype of all the others.
    // Further more check if any of the types is Void.TYPE -> all have to be Void.TYPE
    boolean allVoid = true;
    for (LightweightTypeReference type : types) {
        if (!type.isPrimitiveVoid()) {
            allVoid = false;
            break;
        }
    }
    if (allVoid) {
        return types.get(0);
    }
    for (LightweightTypeReference type : types) {
        LightweightTypeReference conformantType = conformsToAll(type, types);
        if (conformantType != null)
            return conformantType;
        if (type.isPrimitiveVoid()) {
            // we saw void but was not all were void
            return null;
        }
    }
    if (containsPrimitiveOrAnyReferences(types)) {
        List<LightweightTypeReference> withoutPrimitives = replacePrimitivesAndRemoveAnyReferences(types);
        if (withoutPrimitives.equals(types))
            return null;
        return getCommonSuperType(withoutPrimitives, owner);
    }
    LightweightTypeReference firstType = types.get(0);
    final List<LightweightTypeReference> tail = types.subList(1, types.size());
    // mapping from rawtype to resolved parameterized types
    // used to determine the correct type arguments
    Multimap<JvmType, LightweightTypeReference> all = LinkedHashMultimap.create();
    // cumulated rawtype to max distance (used for sorting)
    Multiset<JvmType> cumulatedDistance = LinkedHashMultiset.create();

    initializeDistance(firstType, all, cumulatedDistance);
    cumulateDistance(tail, all, cumulatedDistance);

    List<Entry<JvmType>> candidates = Lists.newArrayList(cumulatedDistance.entrySet());
    if (candidates.size() == 1) { // only one super type -> should be java.lang.Object
        JvmType firstRawType = candidates.get(0).getElement();
        return getFirstForRawType(all, firstRawType);
    }
    inplaceSortByDistanceAndName(candidates);
    // try to find a matching parameterized type for the raw types in ascending order
    List<LightweightTypeReference> referencesWithSameDistance = Lists.newArrayListWithExpectedSize(2);
    int wasDistance = -1;
    boolean classSeen = false;
    outer: for (Entry<JvmType> rawTypeCandidate : candidates) {
        JvmType rawType = rawTypeCandidate.getElement();
        LightweightTypeReference result = null;
        if (wasDistance == -1) {
            wasDistance = rawTypeCandidate.getCount();
        } else {
            if (wasDistance != rawTypeCandidate.getCount()) {
                if (classSeen)
                    break;
                result = getTypeParametersForSupertype(all, rawType, owner, types);
                for (LightweightTypeReference alreadyCollected : referencesWithSameDistance) {
                    if ((isConformant(result, alreadyCollected,
                            RawTypeConformanceComputer.RAW_TYPE | ALLOW_BOXING_UNBOXING
                                    | ALLOW_PRIMITIVE_WIDENING | ALLOW_SYNONYMS | ALLOW_FUNCTION_CONVERSION
                                    | ALLOW_RAW_TYPE_CONVERSION)
                            & SUCCESS) != 0) {
                        classSeen = classSeen || isClass(rawType);
                        continue outer;
                    }
                }
                wasDistance = rawTypeCandidate.getCount();
            }
        }
        if (result == null)
            result = getTypeParametersForSupertype(all, rawType, owner, types);
        if (result != null) {
            boolean isClass = isClass(rawType);
            classSeen = classSeen || isClass;
            if (isClass)
                referencesWithSameDistance.add(0, result);
            else
                referencesWithSameDistance.add(result);
        }
    }
    if (referencesWithSameDistance.size() == 1) {
        return referencesWithSameDistance.get(0);
    } else if (referencesWithSameDistance.size() > 1) {
        CompoundTypeReference result = owner.newCompoundTypeReference(false);
        for (LightweightTypeReference reference : referencesWithSameDistance) {
            result.addComponent(reference);
        }
        return result;
    }
    return null;
}

From source file:de.hzi.helmholtz.Compare.SimpleCompareUsingModules.java

public void comparePathways(String ALGORITHM, String windowsize, String ProcessID) {
    try {//w w  w  .j av a  2 s.c om

        Iterator<DBPathwayUsingModules> firstIter = QueryPathway.iterator();
        Iterator<DBPathwayUsingModules> secondIter = allPathways.iterator();
        SizeofTargetPathwaysInDatabase = allPathways.size();
        maxWindowSize = Integer.parseInt(windowsize.trim());
        UniqueJobID = ProcessID;

        while (firstIter.hasNext()) {
            DBPathwayUsingModules source = firstIter.next();

            //secondIter.next();
            //////System.out.println("**************************************************");
            secondIter = allPathways.iterator();
            while (secondIter.hasNext()) {

                SizeofQueryPathway = 0;
                DBPathwayUsingModules target = secondIter.next();
                //////System.out.println(source.getPathwayID() + " && " + target.getPathwayID());

                Map<String, Integer> srcGeneIdToPositionMap = new TreeMap<String, Integer>();
                int temp = 0;

                sourcecopy = new PathwayUsingModules(source.convertToPathwayObj());
                targetcopy = new PathwayUsingModules(target.convertToPathwayObj());
                for (Map.Entry<String, List<String>> e : source.getPathway().entrySet()) {

                    SizeofQueryPathway += e.getValue().size();
                    srcGeneIdToPositionMap.put(e.getKey(), temp++);
                }
                Map<String, Integer> tgtGeneIdToPositionMap = new TreeMap<String, Integer>();
                temp = 0;
                for (Map.Entry<String, List<String>> e : target.getPathway().entrySet()) {
                    tgtGeneIdToPositionMap.put(e.getKey(), temp++);
                }
                source.printPathway();
                target.printPathway();
                //source.convertToPathwayObj().getModules()
                Iterator<Module> sourceGeneIt = source.convertToPathwayObj().geneIterator();
                Multiset<String> qfunction = LinkedHashMultiset.create();
                while (sourceGeneIt.hasNext()) {
                    Module queryGene = sourceGeneIt.next();
                    for (Domain d : queryGene.getDomains()) {
                        qfunction.add(d.getDomainFunctionString());
                    }
                }
                Iterator<Module> targetGeneIt = target.convertToPathwayObj().geneIterator();
                Multiset<String> tfunction = LinkedHashMultiset.create();
                while (targetGeneIt.hasNext()) {
                    Module targetGene = targetGeneIt.next();
                    for (Domain d : targetGene.getDomains()) {
                        tfunction.add(d.getDomainFunctionString());
                    }
                }
                Multiset<String> DomainsCommon = Multisets.intersection(qfunction, tfunction);
                if (DomainsCommon.size() > 5) {
                    PathwayComparisonUsingModules pComparison = new PathwayComparisonUsingModules(
                            source.convertToPathwayObj(), target.convertToPathwayObj(), maxWindowSize,
                            UniqueJobID, ALGORITHM, self);
                }

                //PathwayComparison pComparison = new PathwayComparison(target.convertToPathwayObj(), source.convertToPathwayObj());
                //
                //  //////System.out.println(SizeofQueryPathway + "                 " + SizeofTargetPathwaysInDatabase);
                //break;
            }

            //System.out.println("**************************************************");
        }
        //System.out.println("Done ... Enjoy with your results");
    } catch (Exception ex) {
        //System.out.println("Error in SimpleCompare:" + ex);
        Logger.getLogger(ThriftServer.class.getName()).log(Level.SEVERE, null, ex);
    }
    ////System.out.println("done");
    //  JOptionPane.showMessageDialog(null, "Done", "less arguments" + " sdsdsd321321", JOptionPane.INFORMATION_MESSAGE);

}

From source file:org.summer.dsl.xbase.typesystem.conformance.TypeConformanceComputer.java

/**
 * Keeps the cumulated distance for all the common raw super types of the given references.
 * Interfaces that are more directly implemented will get a lower total count than more general
 * interfaces.//ww w  . j  av a 2  s.  c  o m
 */
protected void cumulateDistance(final List<LightweightTypeReference> references,
        Multimap<JvmType, LightweightTypeReference> all, Multiset<JvmType> cumulatedDistance) {
    for (LightweightTypeReference other : references) {
        Multiset<JvmType> otherDistance = LinkedHashMultiset.create();
        initializeDistance(other, all, otherDistance);
        cumulatedDistance.retainAll(otherDistance);
        for (Multiset.Entry<JvmType> typeToDistance : otherDistance.entrySet()) {
            if (cumulatedDistance.contains(typeToDistance.getElement()))
                cumulatedDistance.add(typeToDistance.getElement(), typeToDistance.getCount());
        }
    }
}

From source file:com.hortonworks.streamline.common.Schema.java

private static Multiset<Field> parseArray(List<Object> array) throws ParserException {
    Multiset<Field> members = LinkedHashMultiset.create();
    for (Object member : array) {
        members.add(parseField(null, member));
    }//  ww w. j  av a  2s . c o m
    return members;
}

From source file:de.hzi.helmholtz.Compare.PathwayComparisonUsingModules.java

public Multimap<Double, String> SubsetsMatching(final PathwayUsingModules firstPathway,
        final PathwayUsingModules secondPathway, BiMap<String, Integer> newSourceGeneIdToPositionMap,
        BiMap<String, Integer> newTargetGeneIdToPositionMap, int Yes) {
    Multimap<Double, String> resultPerfect = TreeMultimap.create(Ordering.natural().reverse(),
            Ordering.natural());//  w w w.j  ava2 s .com
    PathwayUsingModules firstPathwayCopy = new PathwayUsingModules(firstPathway);// Copy of the Query pathway
    PathwayUsingModules secondPathwayCopy = new PathwayUsingModules(secondPathway);// Copy of the Target pathway'
    // PathwayUsingModules secondPathwayCopy1 = new PathwayUsingModules(secondPathway);
    int currentQueryGene = 0;
    Iterator<Module> sourceGeneIt = firstPathway.geneIterator();
    List<String> QueryToRemove = new ArrayList<String>();
    List<String> TargetToRemove = new ArrayList<String>();
    while (sourceGeneIt.hasNext()) {
        currentQueryGene++;
        Module queryGene = sourceGeneIt.next();

        int currentTargetGene = 0;
        Multiset<String> qfunction = LinkedHashMultiset.create();
        List<String> qfunctionList = new ArrayList<String>();
        List<String> qactivity = new ArrayList<String>();
        List<Set<String>> qsubstrate = new ArrayList<Set<String>>();
        for (Domain d : queryGene.getDomains()) {
            qfunction.add(d.getDomainFunctionString());
            qfunctionList.add(d.getDomainFunctionString());
            qactivity.add(d.getStatus().toString());
            qsubstrate.add(d.getSubstrates());
        }
        Iterator<Module> targetGeneIt = secondPathway.geneIterator();

        while (targetGeneIt.hasNext()) {
            currentTargetGene++;
            Module targetGene = targetGeneIt.next();
            Multiset<String> tfunction = LinkedHashMultiset.create();
            List<String> tfunctionList = new ArrayList<String>();
            List<String> tactivity = new ArrayList<String>();
            List<Set<String>> tsubstrate = new ArrayList<Set<String>>();
            for (Domain d : targetGene.getDomains()) {
                tfunctionList.add(d.getDomainFunctionString());
                tfunction.add(d.getDomainFunctionString());
                tactivity.add(d.getStatus().toString());
                tsubstrate.add(d.getSubstrates());
            }
            Multiset<String> DomainsCovered = Multisets.intersection(qfunction, tfunction);
            if (DomainsCovered.size() == qfunction.size() && DomainsCovered.size() == tfunction.size()) {
                Multimap<Double, Multimap<String, Integer>> activityscores = myFunction.calculate(qactivity,
                        tactivity);
                Multimap<String, Integer> Functionscores = ArrayListMultimap.create();

                int TranspositionDomains = LevenshteinDistance.computeLevenshteinDistance(qfunctionList,
                        tfunctionList);
                if (TranspositionDomains > 0) {
                    TranspositionDomains = 1;
                }

                Functionscores.put(qfunction.size() + "-0", TranspositionDomains);
                Multimap<Double, Multimap<String, Integer>> substratescore = myFunction
                        .calculate(getSubstrateList(qsubstrate), getSubstrateList(tsubstrate));
                Object activityScore = activityscores.asMap().keySet().toArray()[0];
                Object substrateScore = substratescore.asMap().keySet().toArray()[0];
                double finalScore = Math
                        .round((((2.9 * 1.0) + (0.05 * Double.parseDouble(activityScore.toString().trim()))
                                + (0.05 * Double.parseDouble(substrateScore.toString().trim()))) / 3) * 100.0)
                        / 100.0;
                String ConvertedGeneIDs = "";
                if (Yes == 0) {
                    ConvertedGeneIDs = reconstructWithGeneId(Integer.toString(currentQueryGene),
                            newSourceGeneIdToPositionMap) + "->"
                            + reconstructWithGeneId(Integer.toString(currentTargetGene),
                                    newTargetGeneIdToPositionMap);
                } else {
                    ConvertedGeneIDs = reconstructWithGeneId(Integer.toString(currentTargetGene),
                            newTargetGeneIdToPositionMap) + "->"
                            + reconstructWithGeneId(Integer.toString(currentQueryGene),
                                    newSourceGeneIdToPositionMap);
                }
                resultPerfect.put(finalScore, ConvertedGeneIDs);
                ScoreFunctionMatchMisMatch.put(ConvertedGeneIDs, Functionscores);
                ScoreStatusMatchMisMatch.putAll(ConvertedGeneIDs, activityscores.values());
                ScoreSubstrateMatchMisMatch.putAll(ConvertedGeneIDs, substratescore.values());

                TargetToRemove.add(reconstructWithGeneId(Integer.toString(currentTargetGene),
                        newTargetGeneIdToPositionMap));
                QueryToRemove.add(reconstructWithGeneId(Integer.toString(currentQueryGene),
                        newSourceGeneIdToPositionMap));
            }
        }

    }
    for (String i : TargetToRemove) {
        secondPathwayCopy.removeModule(i);
    }
    for (String i : QueryToRemove) {
        firstPathwayCopy.removeModule(i);
    }
    if (firstPathwayCopy.size() > 0 && secondPathwayCopy.size() > 0) {
        // Re-construct the bimaps
        newSourceGeneIdToPositionMap = HashBiMap.create();
        int temp = 0;
        for (Module e : firstPathwayCopy.getModules()) {
            temp = temp + 1;
            newSourceGeneIdToPositionMap.put(e.getModuleId(), temp);
        }
        newTargetGeneIdToPositionMap = HashBiMap.create();
        temp = 0;
        for (Module e : secondPathwayCopy.getModules()) {
            temp = temp + 1;
            newTargetGeneIdToPositionMap.put(e.getModuleId(), temp);
        }
        resultPerfect.putAll(SubsetIdentification(firstPathwayCopy, secondPathwayCopy,
                newSourceGeneIdToPositionMap, newTargetGeneIdToPositionMap, Yes));
    }
    ////System.out.println(resultPerfect);
    return resultPerfect;
}