List of usage examples for java.util Map.Entry get
V get(Object key);
From source file:de.citec.csra.elancsv.parser.SimpleParser.java
public static void main(String[] args) throws IOException, ParseException { Options opts = new Options(); opts.addOption("file", true, "Tab-separated ELAN export file to load."); opts.addOption("tier", true, "Tier to analyze. Optional: Append ::num to interpret annotations numerically."); opts.addOption("format", true, "How to read information from the file name. %V -> participant, %A -> annoatator, %C -> condition, e.g. \"%V - %A\""); opts.addOption("help", false, "Print this help and exit"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("help")) { helpExit(opts, "where OPTION includes:"); }/*from w w w . j a v a 2 s . c o m*/ String infile = cmd.getOptionValue("file"); if (infile == null) { helpExit(opts, "Error: no file given."); } String format = cmd.getOptionValue("format"); if (format == null) { helpExit(opts, "Error: no format given."); } String tier = cmd.getOptionValue("tier"); if (tier == null) { helpExit(opts, "Error: no tier given."); } // TODO count values in annotations (e.g. search all robot occurrences) String[] tn = tier.split("::"); boolean numeric = false; if (tn.length == 2 && tn[1].equals("num")) { numeric = true; tier = tn[0]; } format = "^" + format + "$"; format = format.replaceFirst("%V", "(?<V>.*?)"); format = format.replaceFirst("%A", "(?<A>.*?)"); format = format.replaceFirst("%C", "(?<C>.*?)"); Pattern pa = Pattern.compile(format); Map<String, Participant> participants = new HashMap<>(); BufferedReader br = new BufferedReader(new FileReader(infile)); String line; int lineno = 0; while ((line = br.readLine()) != null) { String[] parts = line.split("\t"); lineno++; if (parts.length < 5) { System.err.println("WARNING: line '" + lineno + "' too short '" + line + "'"); continue; } Annotation a = new Annotation(Long.valueOf(parts[ElanFormat.START.field]), Long.valueOf(parts[ElanFormat.STOP.field]), Long.valueOf(parts[ElanFormat.DURATION.field]), parts[ElanFormat.VALUE.field]); String tname = parts[ElanFormat.TIER.field]; String file = parts[ElanFormat.FILE.field].replaceAll(".eaf", ""); Matcher m = pa.matcher(file); String vp = file; String condition = "?"; String annotator = "?"; String participantID = vp; if (m.find()) { vp = m.group("V"); if (format.indexOf("<A>") > 0) { annotator = m.group("A"); } if (format.indexOf("<C>") > 0) { condition = m.group("C"); } } participantID = vp + ";" + annotator; if (!participants.containsKey(participantID)) { participants.put(participantID, new Participant(vp, condition, annotator)); } Participant p = participants.get(participantID); if (!p.tiers.containsKey(tname)) { p.tiers.put(tname, new Tier(tname)); } p.tiers.get(tname).annotations.add(a); } Map<String, Map<String, Number>> values = new HashMap<>(); Set<String> rownames = new HashSet<>(); String allCountKey = "c: all values"; String allDurationKey = "d: all values"; String allMeanKey = "m: all values"; for (Map.Entry<String, Participant> e : participants.entrySet()) { // System.out.println(e); Tier t = e.getValue().tiers.get(tier); String participantID = e.getKey(); if (!values.containsKey(participantID)) { values.put(participantID, new HashMap<String, Number>()); } Map<String, Number> row = values.get(participantID); //participant id if (t != null) { row.put(allCountKey, 0l); row.put(allDurationKey, 0l); row.put(allMeanKey, 0l); for (Annotation a : t.annotations) { long countAll = (long) row.get(allCountKey) + 1; long durationAll = (long) row.get(allDurationKey) + a.duration; long meanAll = durationAll / countAll; row.put(allCountKey, countAll); row.put(allDurationKey, durationAll); row.put(allMeanKey, meanAll); if (!numeric) { String countKey = "c: " + a.value; String durationKey = "d: " + a.value; String meanKey = "m: " + a.value; if (!row.containsKey(countKey)) { row.put(countKey, 0l); } if (!row.containsKey(durationKey)) { row.put(durationKey, 0l); } if (!row.containsKey(meanKey)) { row.put(meanKey, 0d); } long count = (long) row.get(countKey) + 1; long duration = (long) row.get(durationKey) + a.duration; double mean = duration * 1.0 / count; row.put(countKey, count); row.put(durationKey, duration); row.put(meanKey, mean); rownames.add(countKey); rownames.add(durationKey); rownames.add(meanKey); } else { String countKey = "c: " + t.name; String sumKey = "s: " + t.name; String meanKey = "m: " + t.name; if (!row.containsKey(countKey)) { row.put(countKey, 0l); } if (!row.containsKey(sumKey)) { row.put(sumKey, 0d); } if (!row.containsKey(meanKey)) { row.put(meanKey, 0d); } double d = 0; try { d = Double.valueOf(a.value); } catch (NumberFormatException ex) { } long count = (long) row.get(countKey) + 1; double sum = (double) row.get(sumKey) + d; double mean = sum / count; row.put(countKey, count); row.put(sumKey, sum); row.put(meanKey, mean); rownames.add(countKey); rownames.add(sumKey); rownames.add(meanKey); } } } } ArrayList<String> list = new ArrayList(rownames); Collections.sort(list); StringBuilder header = new StringBuilder("ID;Annotator;"); header.append(allCountKey); header.append(";"); header.append(allDurationKey); header.append(";"); header.append(allMeanKey); header.append(";"); for (String l : list) { header.append(l); header.append(";"); } System.out.println(header); for (Map.Entry<String, Map<String, Number>> e : values.entrySet()) { StringBuilder row = new StringBuilder(e.getKey()); row.append(";"); if (e.getValue().containsKey(allCountKey)) { row.append(e.getValue().get(allCountKey)); } else { row.append("0"); } row.append(";"); if (e.getValue().containsKey(allDurationKey)) { row.append(e.getValue().get(allDurationKey)); } else { row.append("0"); } row.append(";"); if (e.getValue().containsKey(allMeanKey)) { row.append(e.getValue().get(allMeanKey)); } else { row.append("0"); } row.append(";"); for (String l : list) { if (e.getValue().containsKey(l)) { row.append(e.getValue().get(l)); } else { row.append("0"); } row.append(";"); } System.out.println(row); } }
From source file:com.px100systems.data.utility.RestoreUtility.java
public static void main(String[] args) { if (args.length < 3) { System.err.println("Usage: java -cp ... com.px100systems.data.utility.RestoreUtility " + "<springXmlConfigFile> <persisterBeanName> <backupDirectory> [compare]"); return;/* ww w. j av a 2 s .com*/ } FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("file:" + args[0]); try { PersistenceProvider persister = ctx.getBean(args[1], PersistenceProvider.class); File directory = new File(args[2]); if (!directory.isDirectory()) { System.err.println(directory.getName() + " is not a directory"); return; } List<File> files = new ArrayList<File>(); //noinspection ConstantConditions for (File file : directory.listFiles()) if (BackupFile.isBackup(file)) files.add(file); if (files.isEmpty()) { System.err.println(directory.getName() + " directory has no backup files"); return; } if (args.length == 4 && args[3].equalsIgnoreCase("compare")) { final Map<String, Map<Long, RawRecord>> units = new HashMap<String, Map<Long, RawRecord>>(); for (String storage : persister.storage()) { System.out.println("Storage " + storage); persister.loadByStorage(storage, new PersistenceProvider.LoadCallback() { @Override public void process(RawRecord record) { Map<Long, RawRecord> unitList = units.get(record.getUnitName()); if (unitList == null) { unitList = new HashMap<Long, RawRecord>(); units.put(record.getUnitName(), unitList); } unitList.put(record.getId(), record); } }); for (final Map.Entry<String, Map<Long, RawRecord>> unit : units.entrySet()) { BackupFile file = null; for (int i = 0, n = files.size(); i < n; i++) if (BackupFile.isBackup(files.get(i), unit.getKey())) { file = new BackupFile(files.get(i)); files.remove(i); break; } if (file == null) throw new RuntimeException("Could not find backup file for unit " + unit.getKey()); final Long[] count = new Long[] { 0L }; file.read(new PersistenceProvider.LoadCallback() { @Override public void process(RawRecord record) { RawRecord r = unit.getValue().get(record.getId()); if (r == null) throw new RuntimeException("Could not find persisted record " + record.getId() + " for unit " + unit.getKey()); if (!r.equals(record)) throw new RuntimeException( "Record " + record.getId() + " mismatch for unit " + unit.getKey()); count[0] = count[0] + 1; } }); if (count[0] != unit.getValue().size()) throw new RuntimeException("Extra persisted records for unit " + unit.getKey()); System.out.println(" Unit " + unit.getKey() + ": OK"); } units.clear(); } if (!files.isEmpty()) { System.err.println("Extra backups: "); for (File file : files) System.err.println(" " + file.getName()); } } else { persister.init(); for (File file : files) { InMemoryDatabase.readBackupFile(file, persister); System.out.println("Loaded " + file.getName()); } } } catch (Exception e) { throw new RuntimeException(e); } finally { ctx.close(); } }
From source file:com.streamsets.datacollector.util.ValidationUtil.java
public static String getFirstIssueAsString(String name, Issues issues) { StringBuilder sb = new StringBuilder(); if (issues.getPipelineIssues().size() > 0) { sb.append("[").append(name).append("] ").append(issues.getPipelineIssues().get(0).getMessage()); } else if (issues.getStageIssues().entrySet().size() > 0) { Map.Entry<String, List<Issue>> e = issues.getStageIssues().entrySet().iterator().next(); sb.append("[").append(e.getKey()).append("] ").append(e.getValue().get(0).getMessage()); }/*from ww w. jav a 2 s. com*/ sb.append("..."); return sb.toString(); }
From source file:au.edu.anu.portal.portlets.sakaiconnector.support.WebServiceSupport.java
/** * Make a web service call to the given endpoint, calling the method and using the params supplied * @param endpoint wsdl url// w w w.j a v a 2 s . com * @param method method to call * @param params LinkedHashMap of params: * 1. Must be in order required to be sent * 2. Must be keyed on the parameter name to be sent, must match the webservice param exactly or it will fail * 3. Should contained a single Map of items, containing 'value' and 'type' keys * 4. The type attribute will be converted and supported values are string or boolean, case insensitive * * @return the response, or null if any exception is thrown. */ public static String call(String endpoint, String method, Map<String, Map<String, String>> params) { Service service = new Service(); try { Call nc = (Call) service.createCall(); nc.setTargetEndpointAddress(endpoint); nc.removeAllParameters(); nc.setOperationName(method); List<Object> values = new ArrayList<Object>(); for (Map.Entry<String, Map<String, String>> entry : params.entrySet()) { //add value values.add(entry.getValue().get("value")); //setup the type QName qname = null; try { qname = getNameForType(entry.getValue().get("type")); } catch (SOAPException e) { e.printStackTrace(); return null; } //add the parameter nc.addParameter(entry.getKey(), qname, ParameterMode.IN); } nc.setReturnType(XMLType.XSD_STRING); return (String) nc.invoke(values.toArray()); } catch (RemoteException e) { //e.printStackTrace(); log.error("A connection error occurred: " + e.getClass() + ": " + e.getMessage()); } catch (ServiceException e) { //e.printStackTrace(); log.error("A connection error occurred: " + e.getClass() + ": " + e.getMessage()); } return null; }
From source file:com.hortonworks.releng.hdpbuildredirect.Resource.java
private static synchronized void cacheRepoInfo() { Map<String, TreeMap<Version, String>> mapping = new HashMap<>(); Response response = target.request().accept(MediaType.APPLICATION_JSON_TYPE).get(Response.class); JsonNode json = response.readEntity(JsonNode.class); Iterator<Map.Entry<String, JsonNode>> versions = json.fields(); while (versions.hasNext()) { Map.Entry<String, JsonNode> series = versions.next(); //System.out.println( series.getKey() ); JsonNode latest = series.getValue().get("latest"); Iterator<Map.Entry<String, JsonNode>> builds = latest.fields(); while (builds.hasNext()) { Map.Entry<String, JsonNode> build = builds.next(); String platform = build.getKey(); String uri = build.getValue().asText(); Version version = extractVersionFromRepoUri(uri); getVerToUriMap(mapping, platform).put(version, uri); //System.out.println( " " + build.getKey() + ":" + build.getValue().asText() ); }/*from ww w . j a v a 2s . c o m*/ } cache = mapping; timestamp = System.currentTimeMillis(); }
From source file:com.vmware.bdd.plugin.ambari.utils.AmUtils.java
private static void updateServiceUserConfigInConfiguration(Map<String, Object> configuration) { if (configuration == null) { return;/*from w ww. j a v a 2 s . co m*/ } Map<String, Map<String, String>> serviceUserConfigs = (Map<String, Map<String, String>>) configuration .get(UserMgmtConstants.SERVICE_USER_CONFIG_IN_SPEC_FILE); if (MapUtils.isEmpty(serviceUserConfigs)) { return; } for (Map.Entry<String, Map<String, String>> serviceUserConfig : serviceUserConfigs.entrySet()) { String serviceUser = serviceUserConfig.getValue().get(UserMgmtConstants.SERVICE_USER_NAME); if (!StringUtils.isBlank(serviceUser)) { String serviceUserParentConfigName = serviceName2EnvName(serviceUserConfig.getKey()); String serviceUserConfigName = serviceUserConfig.getKey().toLowerCase() + "_user"; Map<String, String> serviceConfig = (Map<String, String>) configuration .get(serviceUserParentConfigName); if (serviceConfig == null) { serviceConfig = new HashMap<>(); } serviceConfig.put(serviceUserConfigName, serviceUser); configuration.put(serviceUserParentConfigName, serviceConfig); //for HDFS/HBASE we also need to change related field in xml files //Reference: http://docs.hortonworks.com/HDPDocuments/HDP1/HDP-1.3.3/bk_using_Ambari_book/content/ambari-chap3-7-1_2x.html switch (serviceUserConfig.getKey()) { case "HDFS": updateConfigInConfiguration(configuration, "hdfs-site", "dfs.permissions.superusergroup", serviceUser); //the administrators config need to have a whitespace in front of the service user updateConfigInConfiguration(configuration, "hdfs-site", "dfs.cluster.administrators", " " + serviceUser); break; case "HBASE": updateConfigInConfiguration(configuration, "", "dfs.block.local-path-access.user", serviceUser); break; } } } configuration.remove(UserMgmtConstants.SERVICE_USER_CONFIG_IN_SPEC_FILE); }
From source file:com.bigdata.dastor.tools.SSTableImport.java
/** * Add super columns to a column family. * //from ww w. j a va2 s .c o m * @param row the super columns associated with a row * @param cfamily the column family to add columns to */ private static void addToSuperCF(JSONObject row, ColumnFamily cfamily) { // Super columns for (Map.Entry<String, JSONObject> entry : (Set<Map.Entry<String, JSONObject>>) row.entrySet()) { byte[] superName = hexToBytes(entry.getKey()); long deletedAt = (Long) entry.getValue().get("deletedAt"); JSONArray subColumns = (JSONArray) entry.getValue().get("subColumns"); // Add sub-columns for (Object c : subColumns) { JsonColumn col = new JsonColumn(c); QueryPath path = new QueryPath(cfamily.name(), superName, hexToBytes(col.name)); cfamily.addColumn(path, hexToBytes(col.value), col.timestamp, col.isDeleted); } SuperColumn superColumn = (SuperColumn) cfamily.getColumn(superName); superColumn.markForDeleteAt((int) (System.currentTimeMillis() / 1000), deletedAt); } }
From source file:com.streamsets.pipeline.stage.util.http.HttpStageUtil.java
public static Object getFirstHeaderIgnoreCase(String name, MultivaluedMap<String, Object> headers) { for (final Map.Entry<String, List<Object>> headerEntry : headers.entrySet()) { if (name.equalsIgnoreCase(headerEntry.getKey())) { if (headerEntry.getValue() != null && headerEntry.getValue().size() > 0) { return headerEntry.getValue().get(0); }//from w w w . j a va 2 s. co m break; } } return null; }
From source file:org.openo.sdnhub.overlayvpndriver.translator.StaticRouteConvert.java
/** * Utility method to filter created unique static routes. <br/> * * @param ctrlUuid Controller uuid/* www . j a v a 2 s . com*/ * @param deviceId Device id * @param list List of static route * @since SDNHUB 0.5 */ public static void filterCreatedStaticRouteList(String ctrlUuid, String deviceId, List<ControllerNbiStaticRoute> list) { Map<String, List<ControllerNbiStaticRoute>> sameInfo2RouteMap = new HashMap<>(); Iterator<ControllerNbiStaticRoute> iterator = list.iterator(); while (iterator.hasNext()) { ControllerNbiStaticRoute route = iterator.next(); if (CheckIpV6Util.isValidIpV6(route.getIpv6Address())) { continue; } ControllerNbiStaticRoute sameRoute = getSameTunnelFromAc(list, route); if (null != sameRoute) { String key = sameRoute.getOutInterface(); if (CollectionUtils.isEmpty(sameInfo2RouteMap.get(key))) { sameInfo2RouteMap.put(key, new ArrayList<ControllerNbiStaticRoute>()); } sameInfo2RouteMap.get(key).add(sameRoute); } } if (MapUtils.isEmpty(sameInfo2RouteMap)) { return; } for (Map.Entry<String, List<ControllerNbiStaticRoute>> entry : sameInfo2RouteMap.entrySet()) { ControllerNbiStaticRoute temp = entry.getValue().get(0); List<ControllerNbiStaticRoute> ignoreList = new ArrayList<>(); for (ControllerNbiStaticRoute route : list) { String key = IpAddressUtil.calcSubnet(route.getIp(), IpUtils.maskToPrefix(route.getMask())) + route.getMask(); if (entry.getKey().equals(key)) { ignoreList.add(route); } } list.removeAll(ignoreList); list.add(temp); } }
From source file:com.addthis.hydra.query.web.HttpQueryHandler.java
private static void decodeParameters(QueryStringDecoder urlDecoder, KVPairs kv) { for (Map.Entry<String, List<String>> entry : urlDecoder.parameters().entrySet()) { String k = entry.getKey(); String v = entry.getValue().get(0); // ignore duplicates kv.add(k, v);/* w ww . jav a2 s.co m*/ } }