List of usage examples for java.util TreeMap containsKey
public boolean containsKey(Object key)
From source file:com.unboundid.scim2.common.utils.JsonDiff.java
/** * Removes the value from an ArrayNode that matches the provided node. * * @param sourceValue The sourceValue node to match. * @param targetValues The ArrayNode containing the values to remove from. * @return The matching value that was removed or {@code null} if no matching * value was found./* www.j a va 2 s . c o m*/ */ private JsonNode removeMatchingValue(final JsonNode sourceValue, final ArrayNode targetValues) { if (sourceValue.isObject()) { // Find a target value that has the most fields in common with the source // and have identical values. Common fields that are also one of the // SCIM standard multi-value sub-attributes (ie. type, value, etc...) have // a higher weight when determining the best matching value. TreeMap<Integer, Integer> matchScoreToIndex = new TreeMap<Integer, Integer>(); for (int i = 0; i < targetValues.size(); i++) { JsonNode targetValue = targetValues.get(i); if (targetValue.isObject()) { int matchScore = 0; Iterator<String> si = sourceValue.fieldNames(); while (si.hasNext()) { String field = si.next(); if (sourceValue.get(field).equals(targetValue.path(field))) { if (field.equals("value") || field.equals("$ref")) { // These fields have the highest chance of having unique values. matchScore += 3; } else if (field.equals("type") || field.equals("display")) { // These fields should mostly be unique. matchScore += 2; } else if (field.equals("primary")) { // This field will definitely not be unique. matchScore += 0; } else { // Not one of the normative fields. Use the default weight. matchScore += 1; } } } // Only consider the match if there is not already match with the same // score. This will prefer matches at the same index in the array. if (matchScore > 0 && !matchScoreToIndex.containsKey(matchScore)) { matchScoreToIndex.put(matchScore, i); } } } if (!matchScoreToIndex.isEmpty()) { return targetValues.remove(matchScoreToIndex.lastEntry().getValue()); } } else { // Find an exact match for (int i = 0; i < targetValues.size(); i++) { if (JsonUtils.compareTo(sourceValue, targetValues.get(i), null) == 0) { return targetValues.remove(i); } } } // Can't find a match at all. return null; }
From source file:biblivre3.administration.ReportsDAO.java
public TreeMap<String, Set<Integer>> searchAuthors(String authorName) { TreeMap<String, Set<Integer>> results = new TreeMap<String, Set<Integer>>(); String[] terms = authorName.split(" "); Connection con = null;/* w ww.j a v a2 s . co m*/ try { con = getDataSource().getConnection(); StringBuilder sql = new StringBuilder(); sql.append("SELECT DISTINCT B.record_serial, B.record FROM cataloging_biblio B "); sql.append("INNER JOIN idx_author I ON I.record_serial = B.record_serial WHERE B.database = 0 "); for (int i = 0; i < terms.length; i++) { sql.append( "AND B.record_serial in (SELECT record_serial FROM idx_author WHERE index_word >= ? and index_word < ?) "); } PreparedStatement st = con.prepareStatement(sql.toString()); int index = 1; for (int i = 0; i < terms.length; i++) { st.setString(index++, terms[i]); st.setString(index++, TextUtils.incrementLastChar(terms[i])); } ResultSet rs = st.executeQuery(); if (rs != null) { while (rs.next()) { Integer id = rs.getInt("record_serial"); String iso2709 = new String(rs.getBytes("record"), "UTF-8"); Record record = MarcUtils.iso2709ToRecord(iso2709); String name = Indexer.listPrimaryAuthor(record); if (results.containsKey(name)) { Set<Integer> ids = results.get(name); ids.add(id); } else { Set<Integer> ids = new HashSet<Integer>(); ids.add(id); results.put(name, ids); } } } } catch (Exception e) { log.error(e.getMessage(), e); throw new ExceptionUser("ERROR_REPORT_DAO_EXCEPTION"); } finally { closeConnection(con); } return results; }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.Comparison.java
/** * Aim is to produce an aggregated data set for comparison totalling males * and females by MSOA to compare with CASUV003DataRecord *///from ww w . ja v a 2 s .c o m private void run3() throws IOException { boolean aggregateToMSOA = true; // boolean aggregateToMSOA = false; ToyModelDataHandler tToyModelDataHandler = new ToyModelDataHandler(); String startOfFilename = "C:/Work/Projects/MoSeS/Workspace/Leeds/ToyModel_SWR_OA_HSARHP_ISARCEP_0_5_5000_3_30_12_20"; // String startOfFilename = new String( // "C:/Work/Projects/MoSeS/Workspace/Leeds/ToyModel_SWR_OA_HSARHP_ISARCEP_0_5_1000_3_30_12_20" // ); // String startOfFilename = new String( // "C:/Work/Projects/MoSeS/Workspace/Leeds/ToyModel_SWR_OA_ISARHP_ISARCEP_0_5_200_3_30_12_20" // ); File tToyModelDataRecord2CSVFile = new File(startOfFilename + ".csv"); File tToyModelDataRecordMaleFemaleComparisonFile; if (aggregateToMSOA) { tToyModelDataRecordMaleFemaleComparisonFile = new File( startOfFilename + "_MSOAMaleFemaleComparison.csv"); } else { tToyModelDataRecordMaleFemaleComparisonFile = new File(startOfFilename + "_OAMaleFemaleComparison.csv"); } if (!tToyModelDataRecordMaleFemaleComparisonFile.exists()) { tToyModelDataRecordMaleFemaleComparisonFile.createNewFile(); } PrintWriter tToyModelDataRecordMaleFemaleComparisonFilePrintWriter = new PrintWriter( tToyModelDataRecordMaleFemaleComparisonFile); // CASUV003DataHandler tCASUV003DataHandler = new CASUV003DataHandler( // new File( // "C:/Work/Projects/MoSeS/Workspace/Leeds/CASUV003DataRecordsMSOA.dat" // ) ); CASUV003DataHandler tCASUV003DataHandler; CAS001DataHandler tCAS001DataHandler; if (aggregateToMSOA) { tCASUV003DataHandler = new CASUV003DataHandler( new File("C:/Work/Projects/MoSeS/Workspace/Leeds/CASUV003DataRecordsMSOA.dat")); tCAS001DataHandler = new CAS001DataHandler( new File("C:/Work/Projects/MoSeS/Workspace/Leeds/CAS001DataRecordsMSOA.dat")); } else { tCASUV003DataHandler = new CASUV003DataHandler( new File("C:/Work/Projects/MoSeS/Workspace/CASUV003DataRecords.dat")); tCAS001DataHandler = new CAS001DataHandler( new File("C:/Work/Projects/MoSeS/Workspace/CAS001DataRecords.dat")); } CASUV003DataRecord aCASUV003DataRecord; CAS001DataRecord aCAS001DataRecord; BufferedReader tBufferedReader = new BufferedReader( new InputStreamReader(new FileInputStream(tToyModelDataRecord2CSVFile))); StreamTokenizer tStreamTokenizer = new StreamTokenizer(tBufferedReader); Generic_StaticIO.setStreamTokenizerSyntax1(tStreamTokenizer); // Initialise int tMaleCount; int tFemaleCount; int tMaleCEPCount; int tMaleHPCount; int tFemaleCEPCount; int tFemaleHPCount; int tokenType = tStreamTokenizer.nextToken(); ToyModelDataRecord_2 aToyModelDataRecord2; String aZoneCode; HashMap tLookUpMSOAfromOAHashMap = null; CASDataHandler tCASDataHandler = new CASDataHandler(); if (aggregateToMSOA) { tLookUpMSOAfromOAHashMap = tCASDataHandler.get_LookUpMSOAfromOAHashMap(); } Counts aCounts; tToyModelDataRecordMaleFemaleComparisonFilePrintWriter.println( "ZoneCode,CAS001HPFemales,CAS001CEPFemales,CAS001Females,CASUV003Females,ToyModelFemales,ToyModelHPFemales,ToyModelCEPFemales,CAS001HPMales,CAS001CEPMales,CAS001Males,CASUV003Males,ToyModelMales,ToyModelHPMales,ToyModelCEPMales"); TreeMap result = new TreeMap(); while (tokenType != StreamTokenizer.TT_EOF) { switch (tokenType) { case StreamTokenizer.TT_WORD: aToyModelDataRecord2 = new ToyModelDataRecord_2(tToyModelDataHandler, tStreamTokenizer.sval); if (aggregateToMSOA) { aZoneCode = (String) tLookUpMSOAfromOAHashMap .get(new String(aToyModelDataRecord2.getZone_Code())); } else { aZoneCode = String.valueOf(aToyModelDataRecord2.getZone_Code()); } if (aToyModelDataRecord2.SEX == 0) { tFemaleCount = 1; if (aToyModelDataRecord2.tHouseholdID != -9) { tFemaleHPCount = 1; tFemaleCEPCount = 0; } else { tFemaleHPCount = 0; tFemaleCEPCount = 1; } tMaleCount = 0; tMaleHPCount = 0; tMaleCEPCount = 0; } else { tMaleCount = 1; if (aToyModelDataRecord2.tHouseholdID != -9) { tMaleHPCount = 1; tMaleCEPCount = 0; } else { tMaleHPCount = 0; tMaleCEPCount = 1; } tFemaleCount = 0; tFemaleHPCount = 0; tFemaleCEPCount = 0; } if (result.containsKey(aZoneCode)) { aCounts = (Counts) result.get(aZoneCode); result.remove(aZoneCode); aCounts.addToCounts(tMaleCount, tMaleCEPCount, tMaleHPCount, tFemaleCount, tFemaleCEPCount, tFemaleHPCount); result.put(aZoneCode, aCounts); } else { aCounts = new Counts(); aCounts.addToCounts(tMaleCount, tMaleCEPCount, tMaleHPCount, tFemaleCount, tFemaleCEPCount, tFemaleHPCount); result.put(aZoneCode, aCounts); } } tokenType = tStreamTokenizer.nextToken(); } Iterator aIterator = result.keySet().iterator(); Object key; while (aIterator.hasNext()) { key = aIterator.next(); aCounts = (Counts) result.get(key); aZoneCode = (String) key; aCASUV003DataRecord = (CASUV003DataRecord) tCASUV003DataHandler.getDataRecord(aZoneCode); aCAS001DataRecord = (CAS001DataRecord) tCAS001DataHandler.getDataRecord(aZoneCode); tToyModelDataRecordMaleFemaleComparisonFilePrintWriter.println("" + aZoneCode + ", " + aCAS001DataRecord.getHouseholdResidentsFemales() + ", " + aCAS001DataRecord.getCommunalEstablishmentResidentsFemales() + ", " + (aCAS001DataRecord.getHouseholdResidentsFemales() + aCAS001DataRecord.getCommunalEstablishmentResidentsFemales()) + ", " + aCASUV003DataRecord.getFemales() + ", " + aCounts.tFemaleCount + ", " + aCounts.tFemaleHPCount + ", " + aCounts.tFemaleCEPCount + ", " + aCAS001DataRecord.getHouseholdResidentsMales() + ", " + aCAS001DataRecord.getCommunalEstablishmentResidentsMales() + ", " + (aCAS001DataRecord.getHouseholdResidentsMales() + aCAS001DataRecord.getCommunalEstablishmentResidentsMales()) + ", " + aCASUV003DataRecord.getMales() + ", " + aCounts.tMaleCount + ", " + aCounts.tMaleHPCount + ", " + aCounts.tMaleCEPCount); } tBufferedReader.close(); tToyModelDataRecordMaleFemaleComparisonFilePrintWriter.close(); }
From source file:com.att.aro.core.packetanalysis.impl.VideoUsageAnalysisImpl.java
private TreeMap<Long, HttpRequestResponseInfo> collectReqByTS(List<Session> sessionlist) { int counter = 0; TreeMap<Long, HttpRequestResponseInfo> reqMap = new TreeMap<>(); for (Session session : sessionlist) { List<HttpRequestResponseInfo> rri = session.getRequestResponseInfo(); for (HttpRequestResponseInfo rrInfo : rri) { if (rrInfo.getDirection().equals(HttpDirection.REQUEST) && rrInfo.getRequestType() != null && rrInfo.getRequestType().equals(HttpRequestResponseInfo.HTTP_GET) && rrInfo.getObjNameWithoutParams().contains(".")) { rrInfo.setSession(session); Long key = getReqInfoKey(rrInfo, 0); if (reqMap.containsKey(key)) { do { key = getReqInfoKey(rrInfo, ++counter); } while (reqMap.containsKey(key)); counter = 0;/*from www . ja v a 2 s.c om*/ } reqMap.put(key, rrInfo); } } // Set a forward link for all packets in session to the next packet (within the session). // The last packet in session will not link anywhere of course! List<PacketInfo> packets = session.getPackets(); for (int i = 0; i < packets.size() - 1; i++) { packets.get(i).getPacket().setNextPacketInSession(packets.get(i + 1).getPacket()); } } return reqMap; }
From source file:xc.mst.services.marcaggregation.MarcAggregationService.java
/** * * map output records to corresponding input records map * * @param i_to_o_map// w w w. j a v a2 s . co m * @return */ private Map<Long, HashSet<Long>> createMergedRecordsO2Imap(TLongLongHashMap i_to_o_map) { LOG.info("start createMergedRecordsO2Imap"); TreeMap<Long, HashSet<Long>> results = new TreeMap<Long, HashSet<Long>>(); // obviously there can be multiple input records corresponding to one output record. for (Long in : i_to_o_map.keys()) { Long out = i_to_o_map.get(in); if (!results.containsKey(out)) { HashSet<Long> set = new HashSet<Long>(); set.add(in); results.put(out, set); } else { // this output record already had at least one input record associated with it. HashSet<Long> _set = results.get(out); _set.add(in); results.put(out, _set); } } LOG.info("done createMergedRecordsO2Imap"); return results; }
From source file:com.sfs.whichdoctor.dao.RelationshipDAOImpl.java
/** * Builds the inherited map.//from w w w . j a va 2 s. c om * * @param relationshipClass the relationship class * @param relationshipMap the relationship map * @return the tree map */ private TreeMap<Integer, RelationshipBean> buildInheritedMap(final String relationshipClass, final TreeMap<Integer, RelationshipBean> relationshipMap) { TreeMap<Integer, RelationshipBean> fullSupervisorMap = new TreeMap<Integer, RelationshipBean>(); // Load the supervisor type map TreeMap<Integer, String> types = null; try { types = loadSupervisorRelationships(relationshipClass); } catch (WhichDoctorDaoException wde) { dataLogger.error("Error loading the supervisor object types: " + wde.getMessage()); } int maxHierarchy = 0; if (types != null) { dataLogger.debug("Supervisor relationships: " + types.size()); for (Integer hierarchy : types.keySet()) { // Set the maxiumum hierarchy value by getting the last key if (hierarchy > maxHierarchy) { maxHierarchy = hierarchy; } } } dataLogger.debug("Maximum hierarchy: " + maxHierarchy); for (Integer hierarchy : types.keySet()) { final String typeName = types.get(hierarchy); if (dataLogger.isDebugEnabled()) { dataLogger.debug("Hierarchy key is: " + hierarchy); dataLogger.debug("Type is: " + typeName); } if (!relationshipMap.containsKey(hierarchy)) { // If the relationship is missing we need to find one RelationshipBean newSup = null; for (int i = 1; i < maxHierarchy + 1; i++) { dataLogger.debug("Looking up key: " + i); if (newSup == null && relationshipMap.containsKey(i)) { RelationshipBean exSup = relationshipMap.get(i); newSup = exSup.clone(); newSup.setRelationshipType(typeName); } } if (newSup != null) { if (dataLogger.isDebugEnabled()) { dataLogger.debug("Adding a new supervisor"); dataLogger.debug("GUID: " + newSup.getGUID()); dataLogger.debug("Identifier: " + newSup.getIdentifier()); dataLogger.debug("Relationship Class: " + newSup.getRelationshipClass()); dataLogger.debug("Relationship Type: " + newSup.getRelationshipType()); } fullSupervisorMap.put(hierarchy, newSup); } } else { RelationshipBean extSup = relationshipMap.get(hierarchy); if (dataLogger.isDebugEnabled()) { dataLogger.debug("Adding an existing supervisor"); dataLogger.debug("GUID: " + extSup.getGUID()); dataLogger.debug("Identifier: " + extSup.getIdentifier()); dataLogger.debug("Relationship Class: " + extSup.getRelationshipClass()); dataLogger.debug("Relationship Type: " + extSup.getRelationshipType()); } fullSupervisorMap.put(hierarchy, extSup); } } return fullSupervisorMap; }
From source file:org.ecocean.MarkedIndividual.java
public void setDynamicProperty(String name, String value) { name = name.replaceAll(";", "_").trim().replaceAll("%20", " "); value = value.replaceAll(";", "_").trim(); if (dynamicProperties == null) { dynamicProperties = name + "=" + value + ";"; } else {//w w w.j a v a 2 s .c o m //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); } if (tm.containsKey(name)) { tm.remove(name); tm.put(name, value); //now let's recreate the dynamicProperties String String newProps = tm.toString(); int stringSize = newProps.length(); dynamicProperties = newProps.substring(1, (stringSize - 1)).replaceAll(", ", ";") + ";"; } else { dynamicProperties = dynamicProperties + name + "=" + value + ";"; } } }
From source file:org.ecocean.MarkedIndividual.java
public String getDynamicPropertyValue(String name) { if (dynamicProperties != null) { name = name.replaceAll("%20", " "); //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); try { tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); } catch (IndexOutOfBoundsException ioob) { }/*from w w w . j a v a2 s .c o m*/ } if (tm.containsKey(name)) { return tm.get(name); } } return null; }
From source file:com.sfs.whichdoctor.webservice.RotationServiceImpl.java
/** * Find people based on the supplied parameters. * * @param year the year/* ww w . j av a 2s . c o m*/ * @param program the program * @param training_site_country_code the training_site_country_code * @param state the state * @param primary_site the primary_site * @param training_site the training_site * @param division the division * @param keyword the keyword * @param incl_prep the incl_prep * @param incl_non_prep the incl_non_prep * @return the string */ private List<Integer> findPeople(final int year, final String program, final String training_site_country_code, final String state, final String primary_site, final String training_site, final String division, final String keyword, final int incl_prep, final int incl_non_prep) { List<Integer> personIdentifiers = new ArrayList<Integer>(); TreeMap<Integer, Integer> people = new TreeMap<Integer, Integer>(); SearchBean search = initiateSearch(year, program, training_site_country_code, state, primary_site, training_site, division, keyword); // Load the list of relevant rotations to find the person identifiers SearchResultsBean results = null; try { results = searchDAO.search(search, new BuilderBean()); } catch (WhichDoctorSearchDaoException wse) { logger.error("Error performing search for rotations: " + wse.getMessage()); } if (incl_prep == 0 || incl_non_prep == 0) { // For the next part we need to set the search to neutral so that we may // perform a subsearch within the existing parameters. search.setSearchVectors(results.getSearchVectors()); search = searchPREP(search, incl_prep, incl_non_prep); try { results = searchDAO.search(search, new BuilderBean()); } catch (WhichDoctorSearchDaoException wse) { logger.error("Error performing search for rotations: " + wse.getMessage()); } } if (results != null && results.getSearchResults() != null) { for (Object obj : results.getSearchResults()) { RotationBean rotation = (RotationBean) obj; if (rotation.getPerson() != null) { int id = rotation.getPerson().getPersonIdentifier(); if (!people.containsKey(id)) { people.put(id, id); } } } } for (Integer id : people.keySet()) { personIdentifiers.add(id); } return personIdentifiers; }