List of usage examples for java.util HashMap get
public V get(Object key)
From source file:DecorateMutationsSNP.java
/** * The procedure updates the SNPs of all populations that are directly connected to the ancestral population in input. * There can be at most two populations directly connected to an ancestral one. The procedure updates their SNPs based on the SNPs of the ancestral population that are transmitted * @param pop_up instance of the class PopulationARG that represents the ARG of a single population (in this case an ancestral population) * @see PopulationARG/*from w ww.jav a 2 s . c om*/ */ public static void updateMutationsForTheBottomPop(PopulationARG pop_up) { if (pop_up.getKind() == 1 || pop_up.getKind() == 2) { //Add all mutations to the mutation set Iterator<Integer> it_map = pop_up.getMaps_leaves_roots().keySet().iterator(); //System.out.println("**** UPDATING MUTATIONS FROM POPULATION "+pop_up.getId_pop()+" ****"); while (it_map.hasNext()) { Integer key_pop = it_map.next(); PopulationARG pop_buttom = GenerateAdmixturePopulations.getPopulations().get(key_pop); //System.out.println("------- Mapping with Population "+key_pop+" --------- \n"); HashMap<Integer, Integer> map_nodes = pop_up.getMaps_leaves_roots().get(key_pop); Iterator<Integer> it_mapping_nodes = map_nodes.keySet().iterator(); while (it_mapping_nodes.hasNext()) { Integer node_buttom = it_mapping_nodes.next(); Integer node_up = map_nodes.get(node_buttom); //System.out.println("node_up - node_buttom\n"); //System.out.println(node_up+" - "+node_buttom+"\n"); TreeSet<Integer> leaves_from_node_buttom = computeLeaves(node_buttom, pop_buttom); //for each mutation in node_up TreeSet<Double> muts = pop_up.getNodeSet().get(node_up).getMutation_set(); Iterator<Double> it_muts = muts.iterator(); while (it_muts.hasNext()) { //Prendo la mutazione Double mut_id = it_muts.next(); Mutation mut_up = pop_up.getMutationSet().get(mut_id); Mutation mut = new Mutation(); mut.setPositionID(mut_up.getPositionID()); mut.setSegment(mut_up.getSegment()); mut.setLeaves(leaves_from_node_buttom); mut.setIDfather(mut_up.getIDfather()); mut.setIDson(mut_up.getIDson()); mut.setID_original_pop(mut_up.getID_original_pop()); pop_buttom.getSNPpositionsList().add(mut.getPositionID()); pop_buttom.getMutationSet().put(mut.getPositionID(), mut); //For each leaf (in the treeset) that has the mutation mut, add mut to the leaf TreeSet<Integer> leaves = mut.getLeaves(); Iterator<Integer> it_leaves = leaves.iterator(); while (it_leaves.hasNext()) { int l = it_leaves.next(); pop_buttom.getNodeSet().get(l).getMutation_set().add(mut.getPositionID()); } } } //System.out.println("------------------------ End mapping ------------------------------- \n"); } } }
From source file:EndmemberExtraction.java
public static int[] assignInitialLabels(double[][] data, int nData, int nDim, int imgDim1, int imgDim2, double minThresholdAngle, double maxThresholdAngle, double stepSize, double minThresholdAbundance, String filepath) {// w w w . ja v a 2 s .com int[] exemplarLabel = new int[nData]; int[][] exemplarMat; iterativeORASIS(data, nData, nDim, minThresholdAngle, maxThresholdAngle, stepSize, minThresholdAbundance, exemplarLabel); HashSet<Integer> uniqueExemplars = new HashSet<>(); for (int i = 0; i < nData; i++) { uniqueExemplars.add(exemplarLabel[i]); } //System.out.println("Unique exemplars:"); HashMap<Integer, Integer> exemplars = new HashMap<>(); int count = 0; for (int i : uniqueExemplars) { if (i != -1) { exemplars.put(i, count); //System.out.print(i+"\t"); count++; } } System.out.println("Exemplar Count:" + count); //System.out.println(); for (int i = 0; i < nData; i++) { if (exemplarLabel[i] != -1) { exemplarLabel[i] = exemplars.get(exemplarLabel[i]); } } exemplarMat = reshape(exemplarLabel, imgDim1, imgDim2); IO.writeData(exemplarMat, imgDim1, imgDim2, filepath + "exemplarMat.txt"); /* for(int i=0;i<imgDim1;i++){ System.out.print(i+" : "); for(int j=0;j<imgDim2;j++){ System.out.print(exemplarMat[i][j]+"\t"); } System.out.println(); } */ //Display exemplar classification image File exemplarImg = new File(filepath + "ExemplarImg.png"); ImageProc.imagesc(exemplarImg, exemplarMat, uniqueExemplars.size(), imgDim1, imgDim2); return exemplarLabel; }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
private static SimpleDateFormat getFormat(String key) { HashMap<String, SimpleDateFormat> map = formatHolder.get(); if (map == null) { map = new HashMap<String, SimpleDateFormat>(2); formatHolder.set(map);// ? }/*from w w w . ja va 2 s .c om*/ SimpleDateFormat simpleDateFormat = map.get(key); if (simpleDateFormat == null) { simpleDateFormat = new SimpleDateFormat(key, Locale.CHINA); map.put(key, simpleDateFormat); formatHolder.set(map);// ? } return simpleDateFormat; }
From source file:com.ibm.util.merge.CompareArchives.java
/** * @param zip1/*from w ww .ja v a 2s . c o m*/ * @param files1 * @param zip2 * @param files2 * @throws IOException */ private static final void assertMembersEqual(ZipFile zip1, HashMap<String, ZipEntry> files1, ZipFile zip2, HashMap<String, ZipEntry> files2) throws IOException { if (files1.size() != files2.size()) { fail("Different Sizes, expected " + Integer.toString(files1.size()) + " found " + Integer.toString(files2.size())); } for (String key : files1.keySet()) { if (!files2.containsKey(key)) { fail("Expected file not in target " + key); } String file1 = IOUtils.toString(zip1.getInputStream(files1.get(key))); String file2 = IOUtils.toString(zip2.getInputStream(files2.get(key))); assertEquals(file1, file2); } }
From source file:de.tudarmstadt.ukp.dkpro.tc.crfsuite.CRFSuiteOutcomeIDReport.java
protected static Properties generateProperties(HashMap<String, Integer> aMapping, List<String> predictions, List<String> testFeatures) throws Exception { Properties props = new Properties(); int maxLines = predictions.size(); for (int idx = 1; idx < maxLines; idx++) { String entry = predictions.get(idx); String[] split = entry.split("\t"); if (split.length != 2) { continue; }//from w ww. j a va 2 s.c o m String featureEntry = testFeatures.get(idx - 1); String id = extractTCId(featureEntry); int numGold = aMapping.get(split[0]); int numPred = aMapping.get(split[1]); String propEntry = numPred + SEPARATOR_CHAR + numGold; props.setProperty(id, propEntry); } return props; }
From source file:com.concursive.connect.web.modules.calendar.utils.CalendarViewUtils.java
public static CalendarView generateCalendarView(Connection db, CalendarBean calendarInfo, Project project, User user, String filter) throws SQLException { // Generate a new calendar CalendarView calendarView = new CalendarView(calendarInfo, user.getLocale()); if (calendarInfo.getShowHolidays()) { // Add some holidays based on the user locale calendarView.addHolidays();//from w w w .ja va 2 s.co m } // Set Start and End Dates for the view, use the user's timezone offset // (always use Locale.US which matches the URL format) String startValue = calendarView.getCalendarStartDate(calendarInfo.getSource()); LOG.debug(startValue); String userStartValue = DateUtils.getUserToServerDateTimeString(calendarInfo.getTimeZone(), DateFormat.SHORT, DateFormat.LONG, startValue, Locale.US); LOG.debug(userStartValue); Timestamp startDate = DatabaseUtils.parseTimestamp(userStartValue); startDate.setNanos(0); LOG.debug(startDate); Timestamp endDate = DatabaseUtils.parseTimestamp( DateUtils.getUserToServerDateTimeString(calendarInfo.getTimeZone(), DateFormat.SHORT, DateFormat.LONG, calendarView.getCalendarEndDate(calendarInfo.getSource()), Locale.US)); endDate.setNanos(0); if (ProjectUtils.hasAccess(project.getId(), user, "project-tickets-view")) { // Show open and closed tickets TicketList ticketList = new TicketList(); ticketList.setProjectId(project.getId()); ticketList.setOnlyAssigned(true); ticketList.setAlertRangeStart(startDate); ticketList.setAlertRangeEnd(endDate); if ("pending".equals(filter)) { ticketList.setOnlyOpen(true); } else if ("completed".equals(filter)) { ticketList.setOnlyClosed(true); } // Retrieve the tickets that meet the criteria ticketList.buildList(db); for (Ticket thisTicket : ticketList) { if (thisTicket.getEstimatedResolutionDate() != null) { String alertDate = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user), DateFormat.SHORT, thisTicket.getEstimatedResolutionDate()); calendarView.addEvent(alertDate, CalendarEventList.EVENT_TYPES[11], thisTicket); } } // Retrieve the dates in which a ticket has been resolved HashMap<String, Integer> dayEvents = ticketList.queryRecordCount(db, UserUtils.getUserTimeZone(user)); for (String thisDay : dayEvents.keySet()) { calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.TICKET], dayEvents.get(thisDay)); } } if (ProjectUtils.hasAccess(project.getId(), user, "project-plan-view")) { // List open and closed Requirements RequirementList requirementList = new RequirementList(); requirementList.setProjectId(project.getId()); requirementList.setBuildAssignments(false); requirementList.setAlertRangeStart(startDate); requirementList.setAlertRangeEnd(endDate); if ("pending".equals(filter)) { requirementList.setOpenOnly(true); } else if ("completed".equals(filter)) { requirementList.setClosedOnly(true); } // Retrieve the requirements that meet the criteria requirementList.buildList(db); // @todo fix timezone for query counts requirementList.buildPlanActivityCounts(db); for (Requirement thisRequirement : requirementList) { // Display Milestone startDate if (thisRequirement.getStartDate() != null) { String start = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user), DateFormat.SHORT, thisRequirement.getStartDate()); calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[16], thisRequirement); } // Display Milestone endDate if (thisRequirement.getDeadline() != null) { String end = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user), DateFormat.SHORT, thisRequirement.getDeadline()); calendarView.addEvent(end, CalendarEventList.EVENT_TYPES[17], thisRequirement); } } // Retrieve the dates in which a requirement has a start or end date HashMap<String, HashMap<String, Integer>> dayGroups = requirementList.queryRecordCount(db, UserUtils.getUserTimeZone(user)); for (String type : dayGroups.keySet()) { if ("startdate".equals(type)) { HashMap<String, Integer> dayEvents = dayGroups.get(type); for (String thisDay : dayEvents.keySet()) { calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.MILESTONE_START], dayEvents.get(thisDay)); } } else if ("enddate".equals(type)) { HashMap<String, Integer> dayEvents = dayGroups.get(type); for (String thisDay : dayEvents.keySet()) { calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.MILESTONE_END], dayEvents.get(thisDay)); } } } // Retrieve assignments that meet the criteria AssignmentList assignmentList = new AssignmentList(); assignmentList.setProjectId(project.getId()); assignmentList.setOnlyIfRequirementOpen(true); assignmentList.setAlertRangeStart(startDate); assignmentList.setAlertRangeEnd(endDate); if ("pending".equals(filter)) { assignmentList.setIncompleteOnly(true); } else if ("completed".equals(filter)) { assignmentList.setClosedOnly(true); } // Display the user's assignments by due date assignmentList.buildList(db); for (Assignment thisAssignment : assignmentList) { if (thisAssignment.getDueDate() != null) { String dueDate = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user), DateFormat.SHORT, thisAssignment.getDueDate()); calendarView.addEvent(dueDate, CalendarEventList.EVENT_TYPES[8], thisAssignment); } } // Retrieve the dates in which an assignment has a due date HashMap<String, Integer> dayEvents = assignmentList.queryAssignmentRecordCount(db, UserUtils.getUserTimeZone(user)); for (String thisDay : dayEvents.keySet()) { calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.ASSIGNMENT], dayEvents.get(thisDay)); } } if (ProjectUtils.hasAccess(project.getId(), user, "project-calendar-view")) { MeetingList meetingList = new MeetingList(); meetingList.setProjectId(project.getId()); meetingList.setEventSpanStart(startDate); if (!calendarInfo.isAgendaView()) { // limit the events to the date range chosen meetingList.setEventSpanEnd(endDate); } meetingList.setBuildAttendees(true); meetingList.buildList(db); LOG.debug("Meeting count = " + meetingList.size()); // Display the meetings by date for (Meeting thisMeeting : meetingList) { if (thisMeeting.getStartDate() != null) { String start = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user), DateFormat.SHORT, thisMeeting.getStartDate()); if ("pending".equals(filter)) { if (thisMeeting.getStartDate().getTime() > System.currentTimeMillis()) { calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT], thisMeeting); } } else if ("completed".equals(filter)) { if (thisMeeting.getEndDate().getTime() < System.currentTimeMillis()) { calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT], thisMeeting); } } else { if (calendarInfo.isAgendaView()) { // Display meetings that started before today, but last greater than today, on the startDate of the calendar display if (thisMeeting.getStartDate().before(startDate)) { start = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user), DateFormat.SHORT, startDate); } } calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT], thisMeeting); } LOG.debug("Meeting added for date: " + start); } } // Retrieve the dates for meeting events HashMap<String, Integer> dayEvents = meetingList.queryRecordCount(db, UserUtils.getUserTimeZone(user)); for (String thisDay : dayEvents.keySet()) { LOG.debug("addingCount: " + thisDay + " = " + dayEvents.get(thisDay)); calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT], dayEvents.get(thisDay)); } } return calendarView; }
From source file:com.github.sakserv.lslock.cli.LockListerCli.java
/** * Prints the final output for the locks * * @param lockDirectory Directory to recurse for lock files * @throws IOException If the lockdirectory is missing *//*from w w w. jav a 2 s .com*/ public static void printLocks(File lockDirectory, HashMap<Integer, Integer> procLocksContents) throws IOException { Collection<File> fileList = FileUtils.listFiles(lockDirectory, null, true); // If not locks are found, output no locks found if (procLocksContents.isEmpty() || fileList.isEmpty()) { System.out.println("No locks found for " + lockDirectory); } else { // Setup the header System.out.printf("%-15s %-5s %n", "PID", "PATH"); // Iterative the files and print the PID and PATH for the lock for (File file : fileList) { System.out.printf("%-15s %15s %n", procLocksContents.get(getInode(file)), file); } } System.out.println(); }
From source file:com.caris.oscarexchange4j.proxy.PreviewCoverage.java
/** * Verify some expected parameters are present, set them if not so we will * have a happy request.//from w w w . j a va2 s . c o m * * @param parameterMap * The parameter map. */ private static void verifyParameters(HashMap<String, String> parameterMap) { if (!parameterMap.containsKey(PreviewCoverage.REQUEST)) { parameterMap.put(PreviewCoverage.REQUEST, "GetCoverage"); } parameterMap.put(STORE, STORE_VALUE); parameterMap.put(GRIDTYPE, EXPECTED_GRIDTYPE); parameterMap.put(SERVICE, SERVICE_VALUE); parameterMap.put(FORMAT, EXPECTED_FORMAT); if (parameterMap.containsKey(BOUNDINGBOX) && parameterMap.containsKey(GRIDBASECRS)) { if (!parameterMap.get(BOUNDINGBOX).endsWith("," + parameterMap.get(GRIDBASECRS))) { String bbox = parameterMap.get(BOUNDINGBOX) + "," + parameterMap.get(GRIDBASECRS); parameterMap.put(BOUNDINGBOX, bbox); } } }
From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java
public static JiriProjects getProjects(GerritRemoteReader reader, String repoKey, String ref, String manifest) throws ConfigInvalidException, IOException { try (RepoMap<String, Repository> repoMap = new RepoMap<>()) { repoMap.put(repoKey, reader.openRepository(repoKey)); Queue<ManifestItem> q = new LinkedList<>(); q.add(new ManifestItem(repoKey, manifest, ref, "", false)); HashMap<String, HashSet<String>> processedRepoFiles = new HashMap<>(); HashMap<String, JiriProjects.Project> projectMap = new HashMap<>(); while (q.size() != 0) { ManifestItem mi = q.remove(); Repository repo = repoMap.get(mi.repoKey); if (repo == null) { repo = reader.openRepository(mi.repoKey); repoMap.put(mi.repoKey, repo); }//from ww w . ja va2 s . com HashSet<String> processedFiles = processedRepoFiles.get(mi.repoKey); if (processedFiles == null) { processedFiles = new HashSet<String>(); processedRepoFiles.put(mi.repoKey, processedFiles); } if (processedFiles.contains(mi.manifest)) { continue; } processedFiles.add(mi.manifest); JiriManifest m; try { m = parseManifest(repo, mi.ref, mi.manifest); } catch (JAXBException | XMLStreamException e) { throw new ConfigInvalidException("XML parse error", e); } for (JiriProjects.Project project : m.projects.getProjects()) { project.fillDefault(); if (mi.revisionPinned && project.Key().equals(mi.projectKey)) { project.setRevision(mi.ref); } if (projectMap.containsKey(project.Key())) { if (!projectMap.get(project.Key()).equals(project)) throw new ConfigInvalidException(String.format( "Duplicate conflicting project %s in manifest %s\n%s\n%s", project.Key(), mi.manifest, project.toString(), projectMap.get(project.Key()).toString())); } else { projectMap.put(project.Key(), project); } } URI parentURI; try { parentURI = new URI(mi.manifest); } catch (URISyntaxException e) { throw new ConfigInvalidException("Invalid parent URI", e); } for (JiriManifest.LocalImport l : m.imports.getLocalImports()) { ManifestItem tw = new ManifestItem(mi.repoKey, parentURI.resolve(l.getFile()).getPath(), mi.ref, mi.projectKey, mi.revisionPinned); q.add(tw); } for (JiriManifest.Import i : m.imports.getImports()) { i.fillDefault(); URI uri; try { uri = new URI(i.getRemote()); } catch (URISyntaxException e) { throw new ConfigInvalidException("Invalid URI", e); } String iRepoKey = new Project.NameKey(StringUtils.strip(uri.getPath(), "/")).toString(); String iRef = i.getRevision(); boolean revisionPinned = true; if (iRef.isEmpty()) { iRef = REFS_HEADS + i.getRemotebranch(); revisionPinned = false; } ManifestItem tmi = new ManifestItem(iRepoKey, i.getManifest(), iRef, i.Key(), revisionPinned); q.add(tmi); } } return new JiriProjects(projectMap.values().toArray(new JiriProjects.Project[0])); } }
From source file:net.itransformers.idiscover.discoveryhelpers.xml.SnmpForXslt.java
public static String getByOid(String ipAddress, String oid, String community, String timeout, String retries) throws Exception { if (mockSnmpForXslt != null) { return mockSnmpForXslt.getByOid(ipAddress, oid, community, timeout, retries); }//from w ww . j ava 2 s .com HashMap<String, String> deviceNameMap = discoveredIPs.get(ipAddress); String deviceName = null; if (!ipAddressValidator.isValid(ipAddress)) return null; if (deviceNameMap != null) { deviceName = deviceNameMap.get(community); } if ("".equals(deviceName)) { return null; } else if (deviceName == null) { if ("".equals(retries) || retries == null) retries = "1"; if ("".equals(timeout) || timeout == null) timeout = "300"; Map<String, String> resourceParams = new HashMap<String, String>(); resourceParams.put("snmpCommunity", community); resourceParams.put("version", "1"); resourceParams.put("retries", retries); resourceParams.put("timeout", timeout); resourceParams.put("ipAddress", ipAddress); SnmpManager snmpManager = createSnmpManager(resourceParams); final String oidValue = snmpManager.snmpGet(oid); logger.debug("hostname:" + ipAddress + ", community: " + community + ", oidValue:" + oidValue); return oidValue; } else { return null; } }