List of usage examples for java.util HashMap get
public V get(Object key)
From source file:eu.lod2.ConfigurationTab.java
private static List<String> parse_graph_api_result(String result) throws Exception { ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { };/*from www . ja v a2s . c o m*/ HashMap<String, Object> userData = mapper.readValue(result, typeRef); List<String> graphs = null; if (userData.containsKey("graphs")) { Object ographs = userData.get("graphs"); try { HashMap<String, Object> oographs = (HashMap<String, Object>) ographs; if (oographs.containsKey("resultList")) { Object graphsList = oographs.get("resultList"); graphs = (List<String>) graphsList; } ; } catch (Exception e) { System.err.println(e.getMessage()); } ; } ; return graphs; }
From source file:edu.vt.vbi.patric.dao.HibernateHelper.java
public static Session currentSession(String key) throws HibernateException { HashMap<String, Session> sessionMaps = sessionMapsThreadLocal.get(); if (sessionMaps == null) { sessionMaps = new HashMap<String, Session>(); sessionMapsThreadLocal.set(sessionMaps); }/*from w ww . j a va 2 s . c o m*/ // Open a new Session, if this Thread has none yet Session s = sessionMaps.get(key); if (s == null) { s = sessionFactoryMap.get(key).openSession(); sessionMaps.put(key, s); } return s; }
From source file:Main.java
private static Document documentFromSoapBody(SOAPBodyElement element, HashMap<String, String> namespaceDeclarations) throws ParserConfigurationException { Document document = dbf.newDocumentBuilder().newDocument(); Node node = document.importNode(element, true); document.appendChild(node);/*from ww w . j av a 2s . c o m*/ for (String prefix : namespaceDeclarations.keySet()) { String uri = namespaceDeclarations.get(prefix); if (node.lookupNamespaceURI(prefix) == null) { document.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, uri); } } return document; }
From source file:Main.java
public static <T, K> ArrayList<T> buildTree(Collection<T> list, Function<T, K> keyMapper, Function<T, K> parentKeyMapper, Function<T, Collection<T>> childMapper) { HashMap<K, T> map = toHashMap(list, keyMapper); ArrayList<T> root = new ArrayList<T>(); for (T t : list) { K key = keyMapper.apply(t);//www .ja v a 2s .c o m K parentKey = parentKeyMapper.apply(t); if (parentKey == null || key.equals(parentKey)) root.add(t); else childMapper.apply(map.get(parentKey)).add(t); } return root; }
From source file:afest.math.MyMath.java
/** * Return the object that has majority (# of occurrences) in the collection. T must implement equals. * @param <T> Type of object to get the majority. * @param collection collection to extract the object that is majoritary from. * @return the object that occurs the most often in the collection. *//* w w w. j a v a2 s . co m*/ public static <T> T majority(Collection<T> collection) { HashMap<T, Integer> counts = new HashMap<T, Integer>(); for (T aT : collection) { Integer count = counts.get(aT); if (count == null) { counts.put(aT, 0); count = counts.get(aT); } counts.put(aT, count + 1); } T majority = null; int maxCount = -1; for (T aT : counts.keySet()) { if (majority == null) { majority = aT; maxCount = counts.get(aT); } int count = counts.get(aT); if (maxCount < count) { majority = aT; maxCount = count; } } return majority; }
From source file:StringUtilities.java
/** * Processes directive/value pairs from the digest-challenge and * fill out the provided map./*w w w . java 2 s. com*/ * * @param key A non-null String challenge token name. * @param value A non-null String token value. * @throws SaslException if either the key or the value is null or * if the key already has a value. */ private static void extractDirective(HashMap<String, String> map, String key, String value) throws SaslException { if (map.get(key) != null) { throw new SaslException("Peer sent more than one " + key + " directive"); } map.put(key, value); }
From source file:net.doubledoordev.backend.webserver_old.methods.Post.java
/** * Handle post requests from the newServer page *///w w w .ja v a 2 s. co m private static void handleNewServer(HashMap<String, Object> dataObject, NanoHTTPD.HTTPSession session, Map<String, String> map) throws Exception { User user = (User) dataObject.get("user"); if (user == null) throw new Exception("Not logged in."); if (user.getMaxServers() != -1 && user.getServerCount() >= user.getMaxServers()) throw new Exception("Max server count reached."); ServerData data = new ServerData(); if (user.getGroup() == Group.ADMIN && map.containsKey("owner")) data.owner = map.get("owner"); else data.owner = user.getUsername(); data.ID = data.owner + "_" + map.get("ID"); if (Settings.getServerByName(data.ID) != null) throw new Exception("Duplicate server ID"); data.ramMin = Integer.parseInt(map.get("RAMmin")); data.ramMax = Integer.parseInt(map.get("RAMmax")); if (data.ramMax < data.ramMin) { int temp = data.ramMax; data.ramMax = data.ramMin; data.ramMin = temp; } if (user.getMaxRam() != -1 && user.getMaxRamLeft() < data.ramMax) throw new Exception("You are over your max RAM."); if (data.ramMax < 2 || data.ramMin < 2) throw new Exception("RAM settings invalid."); data.permGen = Integer.parseInt(map.get("PermGen")); if (data.permGen < 2) throw new Exception("PermGen settings invalid."); if (map.get("extraJavaParameters").trim().length() != 0) data.extraJavaParameters = Arrays.asList(map.get("extraJavaParameters").trim().split("\n")); if (map.get("extraMCParameters").trim().length() != 0) data.extraMCParameters = Arrays.asList(map.get("extraMCParameters").trim().split("\n")); if (map.get("admins").trim().length() != 0) data.admins = Arrays.asList(map.get("admins").trim().split("\n")); if (map.get("coOwners").trim().length() != 0) data.coOwners = Arrays.asList(map.get("coOwners").trim().split("\n")); data.jarName = map.get("jarname"); data.rconPswd = map.get("rconpass"); data.serverPort = Settings.SETTINGS.fixedPorts ? Settings.SETTINGS.portRange.getNextAvailablePort() : Integer.parseInt(map.get("serverport")); data.rconPort = Settings.SETTINGS.fixedPorts ? Settings.SETTINGS.portRange.getNextAvailablePort(data.serverPort) : Integer.parseInt(map.get("rconport")); data.ip = map.get("ip"); data.autoStart = map.containsKey("autostart") && map.get("autostart").equals("on"); Server server = new Server(data, true); Settings.SETTINGS.servers.put(data.ID, server); Settings.save(); dataObject.put("step2", true); dataObject.put("server", server); FileUtils.writeStringToFile(new File(server.getFolder(), "eula.txt"), "#The server owner indicated to agree with the EULA when submitting the from that produced this server instance.\n" + "#That means that there is no need for extra halting of the server startup sequence with this stupid file.\n" + "#" + new Date().toString() + "\n" + "eula=true\n"); }
From source file:StringUtilities.java
/** * Copy the directive to the {@link StringBuilder} if not null. * (A directive is a parameter of the digest authentication process.) * //from w ww . j a va 2s . co m * @param directives the directives map * @param sb the output buffer * @param directive the directive name to look for */ public static void copyDirective(HashMap<String, String> directives, StringBuilder sb, String directive) { String directiveValue = directives.get(directive); if (directiveValue != null) { sb.append(directive).append(" = \"").append(directiveValue).append("\", "); } }
From source file:edu.indiana.lib.twinpeaks.util.StatusUtils.java
/** * Get the status entry for a specified target database * @param sessionContext Active SessionContext * @param target Database name/*www . j ava 2 s . c om*/ * @return Status Map for this target (null if none) */ public static HashMap getStatusMapForTarget(SessionContext sessionContext, String target) { HashMap statusMap = (HashMap) sessionContext.get("searchStatus"); return (statusMap == null) ? null : (HashMap) statusMap.get(target); }
From source file:StringUtilities.java
/** * Copy the directive from the source map to the destination map, if it's * value isn't null./*ww w. j a v a2 s.c o m*/ * (A directive is a parameter of the digest authentication process.) * * @param src the source map * @param dst the destination map * @param directive the directive name * @return the value of the copied directive */ public static String copyDirective(HashMap<String, String> src, HashMap<String, String> dst, String directive) { String directiveValue = src.get(directive); if (directiveValue != null) { dst.put(directive, directiveValue); } return directiveValue; }