List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:Main.java
private static HashMap<String, String> toMap(String[] a) { HashMap<String, String> map = new HashMap<String, String>(); for (String s : a) { String[] kv = s.split("="); if (kv.length > 1) { map.put(kv[0], kv[1]); }/*from ww w .j a va2s.c o m*/ } return map; }
From source file:com.groupon.jenkins.testhelpers.TestHelpers.java
public static Map map(Object... keyValues) { HashMap out = new HashMap(); for (int i = 0; i < keyValues.length; i++) { if (i % 2 != 0) { out.put(keyValues[i - 1], keyValues[i]); }/*from w w w .j a va2 s . co m*/ } return out; }
From source file:com.hangum.tadpole.db.bander.cubrid.CubridExecutePlanUtils.java
/** * cubrid plan? text ? ? <??> ?. * /*from w w w. ja v a2 s .co m*/ * @param data * @return */ public static TadpoleResultSet getMakeData(String data) { List<Map<Integer, Object>> sourceDataList = new ArrayList<Map<Integer, Object>>(); HashMap<Integer, Object> tmpRs = new HashMap<Integer, Object>(); tmpRs.put(0, data); sourceDataList.add(tmpRs); TadpoleResultSet trs = new TadpoleResultSet(sourceDataList); return trs; }
From source file:com.dbmojo.Util.java
/** Given an error meesage return a JSONObject formatted appropriately. *//*from w ww . j a v a 2 s. c o m*/ public static HashMap getError(String message) { HashMap jObj = new HashMap(); try { jObj.put("status", "error"); jObj.put("message", message); jObj.put("rows", new ArrayList()); jObj.put("types", new ArrayList()); jObj.put("cols", new ArrayList()); } catch (Exception e) { System.out.println(e.toString()); } return jObj; }
From source file:com.hangum.tadpole.db.bander.cubrid.CubridExecutePlanUtils.java
/** * cubrid plan? text ? ? <?> ?. * //from w w w . j a v a 2s . c om * @return */ public static HashMap<Integer, String> getMapColumns() { HashMap<Integer, String> mapColumns = new HashMap<Integer, String>(); mapColumns.put(0, "Query Plan"); return mapColumns; }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static HashMap<?, ?> sortByValue(HashMap<?, ?> map, final int flag) { // flag = 0 decreasing order otherwise increasing List<Map.Entry<?, ?>> list = new LinkedList<Map.Entry<?, ?>>(map.entrySet()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { if (flag == 0) return ((Comparable) ((Map.Entry) (o2)).getValue()).compareTo(((Map.Entry) (o1)).getValue()); else//from www.ja va 2 s . co m return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); } }); HashMap result = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
@SuppressWarnings("unchecked") public static HashMap<?, ?> sortByValue(HashMap<?, ?> map, final int flag) { // flag = 0 decreasing order otherwise increasing List list = new LinkedList(map.entrySet()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { if (flag == 0) return ((Comparable) ((Map.Entry) (o2)).getValue()).compareTo(((Map.Entry) (o1)).getValue()); else//from ww w . ja v a 2 s. c om return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); } }); HashMap result = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:com.thoughtworks.go.apiv7.admin.pipelineconfig.representers.materials.MaterialsRepresenter.java
public static void toJSON(OutputWriter jsonWriter, MaterialConfig materialConfig) { if (!materialConfig.errors().isEmpty()) { jsonWriter.addChild("errors", errorWriter -> { HashMap<String, String> errorMapping = new HashMap<>(); errorMapping.put("materialName", "name"); errorMapping.put("folder", "destination"); errorMapping.put("autoUpdate", "auto_update"); errorMapping.put("filterAsString", "filter"); errorMapping.put("checkexternals", "check_externals"); errorMapping.put("serverAndPort", "port"); errorMapping.put("useTickets", "use_tickets"); errorMapping.put("pipelineName", "pipeline"); errorMapping.put("stageName", "stage"); errorMapping.put("pipelineStageName", "pipeline"); errorMapping.put("packageId", "ref"); errorMapping.put("scmId", "ref"); errorMapping.put("encryptedPassword", "encrypted_password"); new ErrorGetter(errorMapping).toJSON(errorWriter, materialConfig); });/*from w w w . j a v a 2 s . co m*/ } stream(Materials.values()).filter(material -> material.type == materialConfig.getClass()).findFirst() .ifPresent(material -> { jsonWriter.add("type", material.name().toLowerCase()); jsonWriter.addChild("attributes", attributeWriter -> material.representer.toJSON(attributeWriter, materialConfig)); }); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.utils.LocalNamespaceClassUtils.java
private static HashMap<String, String> convertToHash(List<String> namespaces) { HashMap<String, String> namespaceHash = new HashMap<String, String>(); for (String n : namespaces) { namespaceHash.put(n, "true"); }//w ww. j av a 2 s . c o m return namespaceHash; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> void removeDuplicate(List<T> dest, List<T> src) { if (dest == null) { return;/* ww w . 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)); }