List of usage examples for java.util LinkedHashMap put
V put(K key, V value);
From source file:com.benasmussen.maven.plugin.i18n.io.JsonResourceWriter.java
@Override public void writeEntry(KeyEntry keyEntry) { Set<String> locales = keyEntry.getLocaleValues().keySet(); for (String locale : locales) { LinkedHashMap<String, String> jsonMap = output.get(locale); String value = keyEntry.getLocaleValues().get(locale); jsonMap.put(keyEntry.getKey(), value); }/*from w ww . j a v a 2 s . c o m*/ }
From source file:data_gen.Data_gen.java
public static LinkedHashMap<String, Object> Parse_Document_fields(String config) throws FileNotFoundException, IOException { LinkedHashMap<String, Object> fields = new LinkedHashMap<>(); File file = new File(config); FileReader fr = null;//from w w w . j ava2s .c o m BufferedReader br = null; try { fr = new FileReader(file); br = new BufferedReader(fr); while (br.ready()) { String temp = br.readLine(); if (temp.startsWith("\"")) { String[] t = temp.split("="); String trim = t[0].substring(1, t[0].length() - 1).trim(); fields.put(trim, t[1].trim()); } } br.close(); } catch (FileNotFoundException e) { //e.printStackTrace(); System.out.println("The file could not be found."); } catch (IOException e) { // e.printStackTrace(); System.out.println("There was an error reading the file."); } return fields; }
From source file:com.spotify.hamcrest.jackson.IsJsonObject.java
public IsJsonObject where(String key, Matcher<? super JsonNode> valueMatcher) { final LinkedHashMap<String, Matcher<? super JsonNode>> newMap = new LinkedHashMap<>(entryMatchers); newMap.put(key, valueMatcher); return new IsJsonObject(newMap); }
From source file:com.epam.ta.reportportal.ws.converter.TestItemResourceAssembler.java
/** * Get names of test items via their IDs * * @param ids/*from w ww. j a va 2s . com*/ * @return */ private Map<String, String> getItemName(List<String> ids) { Map<String, String> result = testItemRepository.findPathNames(ids); LinkedHashMap<String, String> orderedResult = new LinkedHashMap<>(); for (String id : ids) { orderedResult.put(id, result.get(id)); } return orderedResult; }
From source file:Executable.LinkImputeR.java
private static Position makeNewPosition(Position original, byte[] newGeno, double[][] newProbs) throws VCFNoDataException { StringBuilder newFormat = new StringBuilder(); for (String f : original.meta().getFormat()) { newFormat.append(f);/* w w w .j a va 2 s . co m*/ newFormat.append(":"); } newFormat.append("UG"); newFormat.append(":"); newFormat.append("IP"); LinkedHashMap<String, String> genotypes = new LinkedHashMap<>(); Genotype[] o = original.genotypeStream().toArray((IntFunction<Genotype[]>) Genotype[]::new); for (int i = 0; i < o.length; i++) { genotypes.put(o[i].getSampleName(), makeNewGenotype(o[i], newGeno[i], newProbs[i])); } String[] pm = new String[9]; pm[0] = original.meta().getChrom(); pm[1] = original.meta().getPosition(); pm[2] = original.meta().getID(); pm[3] = original.meta().getRef(); StringBuilder alt = new StringBuilder(); for (String a : original.meta().getAlt()) { alt.append(a); alt.append(","); } pm[4] = alt.substring(0, alt.length() - 1); pm[5] = original.meta().getQual(); pm[6] = original.meta().getFilter(); pm[7] = original.meta().getInfo(); pm[8] = newFormat.toString(); return new Position(new PositionMeta(pm), genotypes); }
From source file:com.ikanow.aleph2.data_model.utils.TestJsonUtils.java
@Test public void test_foldTuple() { final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); LinkedHashMap<String, Object> test1 = new LinkedHashMap<String, Object>(); test1.put("long", 10L); test1.put("double", 1.1); test1.put("string", "val"); test1.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); final JsonNode j1 = JsonUtils.foldTuple(test1, mapper, Optional.empty()); assertEquals("{\"misc\":true,\"long\":10,\"string\":\"val\",\"double\":1.1}", j1.toString()); LinkedHashMap<String, Object> test2 = new LinkedHashMap<String, Object>(); test2.put("misc", false); test2.put("long", 10L); test2.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); test2.put("double", 1.1); test2.put("string", "val"); final JsonNode j2 = JsonUtils.foldTuple(test2, mapper, Optional.of("json")); assertEquals("{\"misc\":false,\"long\":10,\"string\":\"val\",\"double\":1.1}", j2.toString()); LinkedHashMap<String, Object> test3 = new LinkedHashMap<String, Object>(); test3.put("long", mapper.createObjectNode()); test3.put("double", mapper.createArrayNode()); test3.put("string", BeanTemplateUtils.build(TestBean.class).with("test1", 4).done().get()); test3.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); final JsonNode j3 = JsonUtils.foldTuple(test3, mapper, Optional.of("json")); assertEquals("{\"misc\":true,\"long\":{},\"string\":{\"test1\":4},\"double\":[]}", j3.toString()); LinkedHashMap<String, Object> test4 = new LinkedHashMap<String, Object>(); test4.put("misc", BigDecimal.ONE); test4.put("long", (int) 10); test4.put("double", (float) 1.1); test4.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); test4.put("string", "val"); final JsonNode j4 = JsonUtils.foldTuple(test4, mapper, Optional.of("json")); assertEquals("{\"misc\":1,\"long\":10,\"string\":\"val\",\"double\":1.1}", j4.toString().replaceFirst("1[.]1[0]{6,}[0-9]+", "1.1")); try {/* w w w . j av a2 s . c o m*/ test4.put("json", "{\"misc\":true,\"long\":1, string\":\"\"}"); // (Added json error) JsonUtils.foldTuple(test4, mapper, Optional.of("json")); fail("Should have thrown JSON exception"); } catch (Exception e) { } // json error, check new JsonUtils(); // (just for coverage) }
From source file:com.streamsets.pipeline.stage.destination.hive.EventCreationIT.java
public List<Record> runNewTableRecord() throws Exception { HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); TargetRunner runner = new TargetRunner.Builder(HiveMetastoreTarget.class, hiveTarget) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();//from ww w. j av a 2s.c o m LinkedHashMap<String, HiveTypeInfo> columns = new LinkedHashMap<>(); columns.put("name", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING")); columns.put("surname", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING")); LinkedHashMap<String, HiveTypeInfo> partitions = new LinkedHashMap<>(); partitions.put("dt", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING")); Field newTableField = HiveMetastoreUtil.newSchemaMetadataFieldBuilder("default", "tbl", columns, partitions, true, BaseHiveIT.getDefaultWareHouseDir(), HiveMetastoreUtil.generateAvroSchema(columns, "tbl")); Record record = RecordCreator.create(); record.set(newTableField); Assert.assertTrue(HiveMetastoreUtil.isSchemaChangeRecord(record)); runner.runWrite(ImmutableList.of(record)); assertTableStructure("default.tbl", new ImmutablePair("tbl.name", Types.VARCHAR), new ImmutablePair("tbl.surname", Types.VARCHAR), new ImmutablePair("tbl.dt", Types.VARCHAR)); try { return runner.getEventRecords(); } finally { runner.runDestroy(); } }
From source file:uk.ac.kcl.itemProcessors.GateDocumentItemProcessor.java
@Override public Document process(final Document doc) throws Exception { LOG.debug("starting " + this.getClass().getSimpleName() + " on doc " + doc.getDocName()); long startTime = System.currentTimeMillis(); int contentLength = doc.getAssociativeArray().keySet().stream() .filter(k -> fieldsToGate.contains(k.toLowerCase())) .mapToInt(k -> ((String) doc.getAssociativeArray().get(k)).length()).sum(); HashMap<String, Object> newMap = new HashMap<>(); newMap.putAll(doc.getAssociativeArray()); List<String> failedFieldsList = new ArrayList<String>(fieldsToGate); newMap.put(fieldName, new HashMap<String, Object>()); doc.getAssociativeArray().forEach((k, v) -> { if (fieldsToGate.contains(k.toLowerCase())) { gate.Document gateDoc = null; try { gateDoc = Factory.newDocument((String) v); LOG.info("Going to process key: {} in document PK: {}, content length: {}", k, doc.getPrimaryKeyFieldValue(), ((String) v).length()); gateService.processDoc(gateDoc); ((HashMap<String, Object>) newMap.get(fieldName)).put(k, gateService.convertDocToJSON(gateDoc)); // Remove the key from the list if GATE is successful failedFieldsList.remove(k.toLowerCase()); } catch (Exception e) { LOG.warn("gate failed on doc {} (PK: {}): {}", doc.getDocName(), doc.getPrimaryKeyFieldValue(), e);//from ww w . j a va 2 s . c o m ArrayList<LinkedHashMap<Object, Object>> al = new ArrayList<LinkedHashMap<Object, Object>>(); LinkedHashMap<Object, Object> hm = new LinkedHashMap<Object, Object>(); hm.put("error", "see logs"); al.add(hm); ((HashMap<String, Object>) newMap.get(fieldName)).put(k, hm); } finally { Factory.deleteResource(gateDoc); } } }); if (failedFieldsList.size() == 0) { newMap.put("X-TL-GATE", "Success"); } else { newMap.put("X-TL-GATE", "Failed fields: " + String.join(", ", failedFieldsList)); } doc.getAssociativeArray().clear(); doc.getAssociativeArray().putAll(newMap); long endTime = System.currentTimeMillis(); LOG.info("{};Primary-Key:{};Total-Content-Length:{};Time:{} ms", this.getClass().getSimpleName(), doc.getPrimaryKeyFieldValue(), contentLength, endTime - startTime); LOG.debug("finished " + this.getClass().getSimpleName() + " on doc " + doc.getDocName()); return doc; }
From source file:org.kitodo.data.index.elasticsearch.type.TemplateType.java
@SuppressWarnings("unchecked") @Override/* ww w . jav a 2 s.c o m*/ public HttpEntity createDocument(Template template) { LinkedHashMap<String, String> orderedTemplateMap = new LinkedHashMap<>(); String process = template.getProcess() != null ? template.getProcess().getId().toString() : "null"; orderedTemplateMap.put("process", process); JSONObject processObject = new JSONObject(orderedTemplateMap); JSONArray properties = new JSONArray(); List<TemplateProperty> templateProperties = template.getProperties(); for (TemplateProperty property : templateProperties) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); properties.add(propertyObject); } processObject.put("properties", properties); return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON); }