List of usage examples for com.google.common.collect HashMultimap HashMultimap
private HashMultimap()
From source file:de.unisb.cs.st.javalanche.rhino.coverage.FailureMatrix.java
public static FailureMatrix parseFile(File f) { Multimap<String, String> failureMatrix = new HashMultimap<String, String>(); List<String> linesFromFile = Io.getLinesFromFile(f); for (String line : linesFromFile) { String[] split = line.split(","); if (split.length > 0) { String failureId = split[0]; for (int i = 1; i < split.length; i++) { failureMatrix.put(split[i], failureId); logger.info("Put: " + failureId + " " + split[i]); }/*from w ww . ja v a 2s.c o m*/ } } return new FailureMatrix(failureMatrix); }
From source file:uk.nhs.cfh.dsp.snomed.dao.impl.SnomedConceptDatabaseDAO.java
/** * Sets the relationships.// w w w . java 2s .c o m * * @param concept the new relationships * @throws SQLException the SQL exception */ private synchronized void setRelationships(SnomedConcept concept) throws SQLException { String conceptID = concept.getConceptID(); // get relationships Collection<SnomedRelationship> relationships = new ArrayList<SnomedRelationship>(); Multimap<String, SnomedRelationship> roleGroupsMap = new HashMultimap(); String relID = ""; String sourceConceptID = ""; String relationshipType = ""; String targetConceptID = ""; String relationshipGroup = ""; String relSource = ""; // set conceptID in getRelationshipsForConceptIDStatement and execute it getRelationshipsForConceptIDStatement.setString(1, conceptID); ResultSet relResultSet = getRelationshipsForConceptIDStatement.executeQuery(); while (relResultSet.next()) { /* Retrieval using column name is expensive but does the conversion for us... */ relID = relResultSet.getString(1); sourceConceptID = relResultSet.getString(2); relationshipType = relResultSet.getString(3); targetConceptID = relResultSet.getString(4); int characteristicType = relResultSet.getInt(5); int refinability = relResultSet.getInt(6); relationshipGroup = relResultSet.getString(7); relSource = relResultSet.getString(8); // process refinability and characteristic type returned. SnomedRelationship.Refinability relationshipRefinability = null; SnomedRelationship.RelationshipType type = null; // set value based on value passed if (refinability == 0) { relationshipRefinability = SnomedRelationship.Refinability.NOT_REFINABLE; } else if (refinability == 1) { relationshipRefinability = SnomedRelationship.Refinability.OPTIONAL; } else if (refinability == 2) { relationshipRefinability = SnomedRelationship.Refinability.MANDATORY; } else { logger.warn("Unknown refinability value : " + refinability); } // set characteristic type value based on value passed if (characteristicType == 0) { type = SnomedRelationship.RelationshipType.DEFINING; } else if (characteristicType == 1) { type = SnomedRelationship.RelationshipType.QUALIFIER; } else if (characteristicType == 2) { type = SnomedRelationship.RelationshipType.HISTORICAL; } else if (characteristicType == 3) { type = SnomedRelationship.RelationshipType.ADDITIONAL; } else { logger.warn("Unknown characteristic type passed : " + characteristicType); } // add relationship name String relationshipName = null; getPreferredTermStatement.setString(1, relationshipType); ResultSet rs = getPreferredTermStatement.executeQuery(); while (rs.next()) { relationshipName = rs.getString(1); } // close result set rs.close(); // create new relationship SnomedRelationship relationship = new SnomedRelationshipImpl(relID, sourceConceptID, relationshipType, targetConceptID, type, relationshipRefinability, relationshipGroup, relSource); if (relationshipName != null) { relationship.setName(relationshipName); } if (conceptID.equalsIgnoreCase(relationship.getSourceConceptID())) { concept.getSourceRelationships().add(relationship); // add relationship to concept concept.getRelationships().add(relationship); // check if relationship type is 'is a' if (ConceptType.ATTRIBUTE_IS_A.getID().equals(relationship.getRelationshipType())) { // we know this is a parent child relationship, so we add to children concept.getParentIDSet().add(relationship.getTargetConceptID()); } // add defining and refining relationships if (relationship.isDefiningRelation()) { /* we need to check that the relationship is a defining relationship and does not have a relationshipgroup of 0. Any defining relationship without any any relationship with others is assigned the default value of 0. */ if (!"0".equalsIgnoreCase(relationship.getRelationshipGroup())) { // add relationship to rolegroups map roleGroupsMap.put(relationshipGroup, relationship); } else { concept.getDefiningRelationships().add(relationship); } } if (relationship.isQualifyingRelation()) { concept.getRefiningRelationships().add(relationship); } if (relationship.isMandatory()) { concept.getMandatoryRelationships().add(relationship); } if (relationship.isOptional()) { concept.getOptionalRelationships().add(relationship); } } } relResultSet.close(); // get child relationship ids getChildRelationshipsForConceptIDStatement.setString(1, conceptID); ResultSet childrenSet = getChildRelationshipsForConceptIDStatement.executeQuery(); Collection<String> childIds = new HashSet<String>(); while (childrenSet.next()) { // add to concept's childIdSet childIds.add(childrenSet.getString(1)); } // close result set childrenSet.close(); concept.setChildIDSet(childIds); // add role groups Collection<SnomedRoleGroup> roleGroups = new ArrayList<SnomedRoleGroup>(); // loop through role group map and generate role groups as needed for (String relationshipGroupId : roleGroupsMap.keys()) { Collection<SnomedRelationship> rels = roleGroupsMap.get(relationshipGroupId); // create rolegroup with relationships SnomedRoleGroup roleGroup = new SnomedRoleGroupImpl(); roleGroup.setRelationships(new HashSet<SnomedRelationship>(rels)); // set relationship group id for role group roleGroup.setRelationshipGroupId(relationshipGroupId); // add to roleGroups roleGroups.add(roleGroup); } concept.setRoleGroups(roleGroups); }