List of usage examples for java.util LinkedHashMap entrySet
public Set<Map.Entry<K, V>> entrySet()
From source file:com.house365.build.util.CsvUtil.java
/** * ?./*from w ww . j a v a2s. c o m*/ * * @param csvContent * @throws IOException */ public static void printlnCsv(ArrayList<LinkedHashMap<String, String>> csvContent) throws IOException { TableBuilder tb = new TableBuilder(); ArrayList<String> headerNames = new ArrayList<>(); LinkedHashMap<String, String> linkedHashMap = csvContent.get(0); for (Map.Entry<String, String> entry : linkedHashMap.entrySet()) { headerNames.add(entry.getKey()); } String[] names = new String[headerNames.size()]; headerNames.toArray(names); tb.addRow(names); for (HashMap<String, String> mapRecord : csvContent) { names = new String[headerNames.size()]; mapRecord.values().toArray(names); tb.addRow(names); } tb.toString(); BufferedReader reader = new BufferedReader(new StringReader(tb.toString())); String line = reader.readLine(); System.out.println(AnsiColor.ANSI_YELLOW + line + AnsiColor.ANSI_RESET); for (line = reader.readLine(); line != null; line = reader.readLine()) { System.out.println(AnsiColor.ANSI_GREEN + line + AnsiColor.ANSI_RESET); } }
From source file:com.yahoo.sshd.tools.artifactory.Checksum.java
public static Checksum[] build(LinkedHashMap<String, String> checksums) { if (null == checksums) { return null; }/*from ww w. j a v a2 s .c o m*/ List<Checksum> list = new LinkedList<>(); for (Entry<String, String> e : checksums.entrySet()) { list.add(new Checksum(e.getKey(), e.getValue())); } return list.toArray(new Checksum[] {}); }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcMetastoreUtil.java
public static LinkedHashMap<String, JdbcTypeInfo> getDiff(LinkedHashMap<String, JdbcTypeInfo> oldState, LinkedHashMap<String, JdbcTypeInfo> newState) throws JdbcStageCheckedException { LinkedHashMap<String, JdbcTypeInfo> columnDiff = new LinkedHashMap<>(); for (Map.Entry<String, JdbcTypeInfo> entry : newState.entrySet()) { String columnName = entry.getKey(); JdbcTypeInfo columnTypeInfo = entry.getValue(); if (!oldState.containsKey(columnName)) { columnDiff.put(columnName, columnTypeInfo); } else if (!oldState.get(columnName).equals(columnTypeInfo)) { throw new JdbcStageCheckedException(JdbcErrors.JDBC_303, columnName, oldState.get(columnName).toString(), columnTypeInfo.toString()); }//from w w w. jav a 2 s . c om } return columnDiff; }
From source file:com.silverpeas.gallery.web.AlbumEntityMatcher.java
@SuppressWarnings("unchecked") public static AlbumEntity from(LinkedHashMap<String, Object> album) { AlbumEntity albumEntity = new AlbumEntity(); albumEntity.withURI(URI.create((String) album.get("uri"))); albumEntity.withParentURI(URI.create((String) album.get("parentURI"))); albumEntity.setId((String) album.get("id")); albumEntity.setTitle((String) album.get("title")); albumEntity.setDescription((String) album.get("description")); LinkedHashMap<String, LinkedHashMap<String, Object>> mediaList = (LinkedHashMap<String, LinkedHashMap<String, Object>>) album .get("mediaList"); for (Map.Entry<String, LinkedHashMap<String, Object>> mediaEntry : mediaList.entrySet()) { albumEntity.addMedia(MediaEntityMatcher.from(mediaEntry.getValue())); }/*from w ww . j a v a 2s. c o m*/ return albumEntity; }
From source file:org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities.java
/** * Substitute variable references inside an operator according to a variable map. * * @param op,/*from w ww . j av a2 s . co m*/ * the operator for variable substitution. * @param varMap, * a map that maps old variables to new variables. Note that we enforce * the map to be a LinkedHashMap so as to be able to perform recursive * variable substitution within one pass. The order of variable substitution * is the entry insertion order of the LinkedHashMap. Typically, the LinkedHashMap * is populated by recursively, bottom-up traversing of the query plan. * For example, if $1->$2 and $2->$3 are orderly inserted into the map, $1 will be * replaced by $3 in the outcome of this method call. * * @param ctx, * a typing context that keeps track of types of each variable. * @throws AlgebricksException */ public static void substituteVariables(ILogicalOperator op, LinkedHashMap<LogicalVariable, LogicalVariable> varMap, ITypingContext ctx) throws AlgebricksException { for (Map.Entry<LogicalVariable, LogicalVariable> entry : varMap.entrySet()) { VariableUtilities.substituteVariables(op, entry.getKey(), entry.getValue(), ctx); } }
From source file:Main.java
/** * For a list of Map find the entry that best matches the fieldsByPriority Ordered Map; null field values in a Map * in mapList match against any value but do not contribute to maximal match score, otherwise value for each field * in fieldsByPriority must match for it to be a candidate. *///from w ww .ja v a 2s .c om public static Map<String, Object> findMaximalMatch(List<Map<String, Object>> mapList, LinkedHashMap<String, Object> fieldsByPriority) { int numFields = fieldsByPriority.size(); String[] fieldNames = new String[numFields]; Object[] fieldValues = new Object[numFields]; int index = 0; for (Map.Entry<String, Object> entry : fieldsByPriority.entrySet()) { fieldNames[index] = entry.getKey(); fieldValues[index] = entry.getValue(); index++; } int highScore = -1; Map<String, Object> highMap = null; for (Map<String, Object> curMap : mapList) { int curScore = 0; boolean skipMap = false; for (int i = 0; i < numFields; i++) { String curField = fieldNames[i]; Object compareValue = fieldValues[i]; // if curMap value is null skip field (null value in Map means allow any match value Object curValue = curMap.get(curField); if (curValue == null) continue; // if not equal skip Map if (!curValue.equals(compareValue)) { skipMap = true; break; } // add to score based on index (lower index higher score), also add numFields so more fields matched weights higher curScore += (numFields - i) + numFields; } if (skipMap) continue; // have a higher score? if (curScore > highScore) { highScore = curScore; highMap = curMap; } } return highMap; }
From source file:Fasta.java
public static String[] parse(String path) { String seq1 = null;/*from w ww. j a va 2s .c om*/ String seq2 = null; String[] r = new String[2]; try { LinkedHashMap<String, DNASequence> f = FastaReaderHelper.readFastaDNASequence(new File(path)); List<String> dnaList = new ArrayList<>(1); for (Map.Entry<String, DNASequence> stringDNASequenceEntry : f.entrySet()) { dnaList.add(stringDNASequenceEntry.getValue().getSequenceAsString().toUpperCase()); dnaList.add(stringDNASequenceEntry.getValue().getReverseComplement().getSequenceAsString() .toUpperCase()); } seq1 = dnaList.get(0); seq2 = dnaList.get(1); r[0] = seq1; r[1] = seq2; } catch (java.lang.Exception e) { System.out.print(e); } return r; }
From source file:com.ikanow.aleph2.data_model.utils.JsonUtils.java
/** Takes a tuple expressed as LinkedHashMap<String, Object> (by convention the Objects are primitives, JsonNode, or POJO), and where one of the objects * is a JSON representation of the original object and creates an object by folding them all together * Note the other fields of the tuple take precedence over the JSON * @param in - the tuple//w ww . ja v a2s. c o m * @param mapper - the Jackson object mapper * @param json_field - optional fieldname of the string representation of the JSON - if not present then the last field is used (set to eg "" if there is no base object) * @return */ public static JsonNode foldTuple(final LinkedHashMap<String, Object> in, final ObjectMapper mapper, final Optional<String> json_field) { try { // (do this imperatively to handle the "last element can be the base object case" final Iterator<Map.Entry<String, Object>> it = in.entrySet().iterator(); ObjectNode acc = mapper.createObjectNode(); while (it.hasNext()) { final Map.Entry<String, Object> kv = it.next(); if ((json_field.isPresent() && kv.getKey().equals(json_field.get())) || !json_field.isPresent() && !it.hasNext()) { acc = (ObjectNode) ((ObjectNode) mapper.readTree(kv.getValue().toString())).setAll(acc); } else { final ObjectNode acc_tmp = acc; Patterns.match(kv.getValue()).andAct().when(String.class, s -> acc_tmp.put(kv.getKey(), s)) .when(Long.class, l -> acc_tmp.put(kv.getKey(), l)) .when(Integer.class, l -> acc_tmp.put(kv.getKey(), l)) .when(Boolean.class, b -> acc_tmp.put(kv.getKey(), b)) .when(Double.class, d -> acc_tmp.put(kv.getKey(), d)) .when(JsonNode.class, j -> acc_tmp.set(kv.getKey(), j)) .when(Float.class, f -> acc_tmp.put(kv.getKey(), f)) .when(BigDecimal.class, f -> acc_tmp.put(kv.getKey(), f)) .otherwise(x -> acc_tmp.set(kv.getKey(), BeanTemplateUtils.toJson(x))); } } return acc; } catch (Exception e) { throw new RuntimeException(e); } // (convert to unchecked exception) }
From source file:org.loklak.api.client.HelloClient.java
public static void propagate(final String[] hoststubs) { // get some configuration int httpport = (int) DAO.getConfig("port.http", 9000); int httpsport = (int) DAO.getConfig("port.https", 9443); String peername = (String) DAO.getConfig("peername", "anonymous"); // retrieve some simple statistics from the index final String backend = DAO.getConfig("backend", ""); final boolean backend_push = DAO.getConfig("backend.push.enabled", false); Map<String, Object> backend_status = null; Map<String, Object> backend_status_index_sizes = null; if (backend.length() > 0 && !backend_push) { try {//from w w w . j a v a2 s.c o m backend_status = StatusClient.status(backend); } catch (IOException e) { e.printStackTrace(); } backend_status_index_sizes = backend_status == null ? null : (Map<String, Object>) backend_status.get("index_sizes"); } long backend_messages = backend_status_index_sizes == null ? 0 : ((Number) backend_status_index_sizes.get("messages")).longValue(); long backend_users = backend_status_index_sizes == null ? 0 : ((Number) backend_status_index_sizes.get("users")).longValue(); long local_messages = DAO.countLocalMessages(-1); long local_users = DAO.countLocalUsers(); int timezoneOffset = DateParser.getTimezoneOffset(); // retrieve more complex data: date histogram LinkedHashMap<String, Long> fullDateHistogram = DAO.FullDateHistogram(timezoneOffset); // complex operation can take some time! String peakDay = ""; long peakCount = -1; String lastDay = ""; long lastCount = -1; for (Map.Entry<String, Long> day : fullDateHistogram.entrySet()) { lastDay = day.getKey(); lastCount = day.getValue(); if (lastCount > peakCount) { peakDay = lastDay; peakCount = lastCount; } } String firstDay = ""; long firstCount = -1; if (fullDateHistogram.size() > 0) { Map.Entry<String, Long> firstDayEntry = fullDateHistogram.entrySet().iterator().next(); firstDay = firstDayEntry.getKey(); firstCount = firstDayEntry.getValue(); } // send data to peers for (String hoststub : hoststubs) { if (hoststub.endsWith("/")) hoststub = hoststub.substring(0, hoststub.length() - 1); try { String urlstring = hoststub + "/api/hello.json?port.http=" + httpport + "&port.https=" + httpsport + "&peername=" + peername + "&time=" + System.currentTimeMillis() + "&timezoneOffset=" + timezoneOffset + "&local_messages=" + local_messages + "&local_users=" + local_users + "&backend_messages=" + backend_messages + "&backend_users=" + backend_users + "&peakDay=" + peakDay + "&peakCount=" + peakCount + "&firstDay=" + firstDay + "&firstCount=" + firstCount + "&lastDay=" + lastDay + "&lastCount=" + lastCount; byte[] jsonb = ClientConnection.download(urlstring); if (jsonb == null || jsonb.length == 0) throw new IOException("empty content from " + hoststub); String jsons = UTF8.String(jsonb); JSONObject json = new JSONObject(jsons); Log.getLog().info("Hello response: " + json.toString()); } catch (IOException e) { } } }
From source file:Main.java
public static <K, V> LinkedHashMap<K, V> headMap(LinkedHashMap<K, V> map, int endIndex, boolean inclusive) { int index = endIndex; if (inclusive) { index++;//from w ww. jav a 2 s. c om } if ((map == null) || (map.size() == 0) || (map.size() < index) || (endIndex < 0)) { return new LinkedHashMap<K, V>(0); } LinkedHashMap<K, V> subMap = new LinkedHashMap<K, V>(index + 1); int i = 0; for (Map.Entry<K, V> entry : map.entrySet()) { if (i < index) { subMap.put(entry.getKey(), entry.getValue()); } i++; } return subMap; }