List of usage examples for java.util HashMap get
public V get(Object key)
From source file:com.dtolabs.rundeck.core.common.NodeEntryFactory.java
/** * Create NodeEntryImpl from map data. It will convert "tags" of type String as a comma separated list of tags, or * "tags" a collection of strings into a set. It will remove properties excluded from allowed import. * * @param map input map data/*from ww w.j a va2s . c om*/ * * @return * * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") public static NodeEntryImpl createFromMap(final Map<String, Object> map) throws IllegalArgumentException { final NodeEntryImpl nodeEntry = new NodeEntryImpl(); final HashMap<String, Object> newmap = new HashMap<String, Object>(map); for (final String excludeProp : excludeProps) { newmap.remove(excludeProp); } if (null != newmap.get("tags") && newmap.get("tags") instanceof String) { String tags = (String) newmap.get("tags"); String[] data; if ("".equals(tags.trim())) { data = new String[0]; } else { data = tags.split(","); } final HashSet set = new HashSet(); for (final String s : data) { if (null != s && !"".equals(s.trim())) { set.add(s.trim()); } } newmap.put("tags", set); } else if (null != newmap.get("tags") && newmap.get("tags") instanceof Collection) { Collection tags = (Collection) newmap.get("tags"); HashSet data = new HashSet(); for (final Object tag : tags) { if (null != tag && !"".equals(tag.toString().trim())) { data.add(tag.toString().trim()); } } newmap.put("tags", data); } else if (null != newmap.get("tags")) { Object o = newmap.get("tags"); newmap.put("tags", new HashSet(Arrays.asList(o.toString().trim()))); } try { BeanUtils.populate(nodeEntry, newmap); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } if (null == nodeEntry.getNodename()) { throw new IllegalArgumentException("Required property 'nodename' was not specified"); } if (null == nodeEntry.getHostname()) { throw new IllegalArgumentException("Required property 'hostname' was not specified"); } if (null == nodeEntry.getAttributes()) { nodeEntry.setAttributes(new HashMap<String, String>()); } //populate attributes with any keys outside of nodeprops for (final Map.Entry<String, Object> entry : newmap.entrySet()) { if (!ResourceXMLConstants.allPropSet.contains(entry.getKey())) { nodeEntry.setAttribute(entry.getKey(), (String) entry.getValue()); } } return nodeEntry; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> void removeDuplicate(List<T> dest, List<T> src) { if (dest == null) { return;/*w ww .j a va 2 s. c o m*/ } if (src == null || src.isEmpty()) { return; } int capacity = dest.size() > src.size() ? dest.size() : src.size(); HashMap<T, Integer> map = new HashMap<T, Integer>(capacity); for (int i = 0; i < dest.size(); i++) { map.put(dest.get(i), i); } T[] oldData = (T[]) dest.toArray(); int length = oldData.length; for (T t : src) { Integer index = map.get(t); if (index != null) { oldData[index] = null; length--; } } T[] removedDuplicate = (T[]) new Object[length]; int index = 0; for (int i = 0; i < oldData.length; i++) { if (oldData[i] != null) { removedDuplicate[index++] = oldData[i]; } } dest.clear(); dest.addAll(Arrays.asList(removedDuplicate)); }
From source file:Main.java
/** * Processes the POST request from the client instructing the server to process * a serverStart or serverProxy. Returns the fields in this request as a HashMap for * easy handling.//from w w w . ja v a2 s . c om * * @param xmlStream the InputStream obtained from an HttpServletRequest object. This contains the desired pipeline from the client. * @param search a HashMap with arbitrary names as keys and XPath Strings as values, the results of which are assigned as values to the names in the returned HashMap. * @return */ public static HashMap<String, String> procPipelineReq(InputStream xmlStream, HashMap<String, String> search) { HashMap<String, String> returnHash = new HashMap<String, String>(); try { for (String item : search.keySet()) { Document xmlDoc = parse(xmlStream); XPath xpath = xpathFactory.newXPath(); returnHash.put(item, xpath.evaluate(search.get(item), xmlDoc)); } } catch (Exception e) { e.printStackTrace(); } return returnHash; }
From source file:Main.java
public static ArrayList<Integer> getRandomNumbers(int range, int count, Random rnd) { if (count > range) { return null; }// w ww .j a v a 2 s.c o m if (count < 0 || range < 0) { return null; } HashMap<Integer, Integer> used = new HashMap<Integer, Integer>(); ArrayList<Integer> indices = new ArrayList<Integer>(); int n = range; while (indices.size() < count) { Integer r = Integer.valueOf(rnd.nextInt(n)); if (used.containsKey(r)) { indices.add(used.get(r)); } else { indices.add(r); } addToUsed(used, r, n - 1); n--; } return indices; }
From source file:edu.coeia.charts.LineChartPanel.java
private static HashMap<String, Integer> getDateMap(ArrayList<Message> data, String first, String second) throws ParseException { HashMap<String, Integer> map = new HashMap<String, Integer>(); for (Message msg : data) { if (msg.getReceiverName().equalsIgnoreCase(first) && msg.getSenderName().equalsIgnoreCase(second)) { if (map.get(getMonthName(msg.getDate())) == null) { map.put(getMonthName(msg.getDate()), 1); } else { map.put(getMonthName(msg.getDate()), map.get(getMonthName(msg.getDate())) + 1); }//from w w w . ja v a 2s . co m } } return (map); }
From source file:com.glluch.ecf2xmlmaven.Writer.java
protected static String terms2xml(String field_name, HashMap<String, Integer> terms) { String text = ""; Set pterms = terms.keySet();//from w w w.j a va2s . c om for (Object t : pterms) { text += "<field name=\"" + field_name + "\" " + " boost=\"" + terms.get(t) + "\"" + ">" + t + "</field>" + System.lineSeparator(); } return text; }
From source file:com.jaredrummler.android.devices.Main.java
private static void createDeviceJsonFiles(List<String[]> devices) throws IOException { File baseDir = new File(OUTPUT_DIR, "devices"); if (baseDir.exists()) { FileUtils.deleteDirectory(baseDir); }/*w w w .j ava 2s . c om*/ baseDir.mkdirs(); // group all devices with the same codename together HashMap<String, List<DeviceInfo>> map = new HashMap<>(); for (String[] arr : devices) { String key = arr[2]; List<DeviceInfo> list = map.get(key); if (list == null) { list = new ArrayList<>(); } list.add(new DeviceInfo(arr[0], arr[1], arr[2], arr[3])); map.put(key, list); } for (Map.Entry<String, List<DeviceInfo>> entry : map.entrySet()) { File file = new File(baseDir, entry.getKey() + ".json"); FileUtils.write(file, PRETTY_GSON.toJson(entry.getValue())); } }
From source file:com.hangum.tadpole.commons.sql.util.SQLUtil.java
/** * INSERT ? ?./*from w w w . j a va2 s.c o m*/ * * @param tableName * @param rs * @return * @throws Exception */ public static String makeInsertStatment(String tableName, ResultSet rs) throws Exception { StringBuffer result = new StringBuffer("INSERT INTO " + tableName + "("); HashMap<Integer, String> mapTable = mataDataToMap(rs); for (int i = 0; i < mapTable.size(); i++) { if (i != (mapTable.size() - 1)) result.append(mapTable.get(i) + ","); else result.append(mapTable.get(i)); } result.append(") VALUES("); for (int i = 0; i < mapTable.size(); i++) { if (i != (mapTable.size() - 1)) result.append("?,"); else result.append('?'); } result.append(')'); if (logger.isDebugEnabled()) logger.debug("[make insert statment is " + result.toString()); return result.toString(); }
From source file:com.sencko.basketball.stats.advanced.FIBAJsonParser.java
static void analyzeGame(Game game) { HashSet[] playersInGameTeam = { new HashSet<String>(5), new HashSet<String>(5) }; HashSet[] playersInRest = { new HashSet<String>(5), new HashSet<String>(5) }; HashMap[][] plusMinusPlayers = { { new HashMap<String, Integer>(), new HashMap<String, Integer>() }, { new HashMap<String, Integer>(), new HashMap<String, Integer>() } }; for (int i = game.getPbp().size() - 1; i >= 0; i--) { Event event = game.getPbp().get(i); if (EventType.sub.equals(event.getTyp())) { HashSet<String> teamSet = playersInGameTeam[event.getTno() - 1]; HashSet<String> restSet = playersInRest[event.getTno() - 1]; String actor = event.getActor().toString(); if (teamSet.contains(actor)) { teamSet.remove(actor);/*from w ww . j av a 2 s.c om*/ restSet.add(actor); } else { teamSet.add(actor); if (restSet.contains(actor)) { restSet.remove(actor); } else { //add plus minus on bench HashMap<String, Integer> bench = plusMinusPlayers[event.getTno() - 1][1]; int change = (event.getTno() == 1) ? (event.getS1() - event.getS2()) : (event.getS2() - event.getS1()); bench.put(actor, change); } } // System.out.println(Arrays.toString(playersInGameTeam)); } else if (i != game.getPbp().size() - 1) { Event previousEvent = game.getPbp().get(i + 1); int change = 0; if (previousEvent.getS1() != event.getS1()) { change += event.getS1() - previousEvent.getS1(); } if (previousEvent.getS2() != event.getS2()) { change -= event.getS2() - previousEvent.getS2(); } for (int j = 0; j < 2; j++) { HashSet<String> teamSet = playersInGameTeam[j]; for (String player : teamSet) { HashMap<String, Integer> prev = plusMinusPlayers[j][0]; Integer previous = prev.get(player); if (previous == null) { previous = 0; } previous = previous + change; prev.put(player, previous); } HashSet<String> restSet = playersInRest[j]; for (String player : restSet) { HashMap<String, Integer> prev = plusMinusPlayers[j][1]; Integer previous = prev.get(player); if (previous == null) { previous = 0; } previous = previous + change; prev.put(player, previous); } change = -change; } } } // System.out.println(Arrays.deepToString(plusMinusPlayers)); for (int i = 0; i < 2; i++) { HashMap<String, Integer> board = plusMinusPlayers[i][0]; HashMap<String, Integer> bench = plusMinusPlayers[i][1]; int checkSum = 0; for (String name : board.keySet()) { int plusS = board.get(name); int plusB = bench.get(name); int total = plusS - plusB; System.out.printf("%20s\t%4d\t%4d\t%4d\n", name, plusS, plusB, total); checkSum += total; } System.out.println(checkSum + "----------------------------------------"); } }
From source file:com.microsoft.alm.plugin.idea.common.ui.workitem.WorkItemHelper.java
public static String getFieldValue(@NotNull final WorkItem item, @NotNull final String fieldName) { final HashMap<String, Object> fieldMap = item.getFields(); if (fieldMap != null) { // Try a case sensitive search using the Map, // but if that doesn't work, loop through all the fields if (fieldMap.containsKey(fieldName)) { Object value = fieldMap.get(fieldName); if (value != null) { return value.toString(); }/*from w w w. ja v a 2 s. c o m*/ } else { for (final Map.Entry<String, Object> entry : fieldMap.entrySet()) { if (fieldName.equalsIgnoreCase(entry.getKey())) { if (entry.getValue() != null) { return entry.getValue().toString(); } } } } } return StringUtils.EMPTY; }