List of usage examples for java.util LinkedHashMap LinkedHashMap
public LinkedHashMap()
From source file:com.github.jcustenborder.kafka.connect.spooldir.JsonSchemaGenerator.java
@Override protected Map<String, Schema.Type> determineFieldTypes(InputStream inputStream) throws IOException { Map<String, Schema.Type> typeMap = new LinkedHashMap<>(); JsonFactory factory = new JsonFactory(); try (JsonParser parser = factory.createParser(inputStream)) { Iterator<JsonNode> iterator = ObjectMapperFactory.INSTANCE.readValues(parser, JsonNode.class); while (iterator.hasNext()) { JsonNode node = iterator.next(); if (node.isObject()) { Iterator<String> fieldNames = node.fieldNames(); while (fieldNames.hasNext()) { typeMap.put(fieldNames.next(), Schema.Type.STRING); }/*from www. j a v a2 s .c o m*/ break; } } } return typeMap; }
From source file:org.opentides.web.controller.AuditLogController.java
@ModelAttribute("actionsList") public Map<String, Object> getActionsList() { Map<String, Object> actions = new LinkedHashMap<>(); actions.put("", "Select Action"); actions.put("logged-in", "Logged In"); actions.put("logged-out", "Logged Out"); actions.put("added", "Added Record"); actions.put("changed", "Updated Record"); actions.put("deleted", "Deleted Record"); return actions; }
From source file:ch.ralscha.extdirectspring.bean.MetaData.java
public void setSortInfo(String field, SortDirection direction) { Map<String, String> sortInfo = new LinkedHashMap<String, String>(); sortInfo.put("field", field); sortInfo.put("direction", direction.getName()); metaData.put("sortInfo", sortInfo); }
From source file:edu.stanford.muse.graph.GroupsGraph.java
public GroupsGraph() { allNodes = new LinkedHashMap<SimilarGroup<T>, Node<SimilarGroup<T>>>(); elementToNodes = new LinkedHashMap<T, Set<Node<SimilarGroup<T>>>>(); }
From source file:com.haulmont.cuba.gui.xml.layout.loaders.BulkEditorLoader.java
protected void loadValidators(BulkEditor component, Element element) { List<Element> validatorElements = Dom4j.elements(element, "validator"); if (!validatorElements.isEmpty()) { List<Field.Validator> modelValidators = new ArrayList<>(); Map<String, Field.Validator> fieldValidators = new LinkedHashMap<>(); for (Element validatorElement : validatorElements) { Field.Validator validator = loadValidator(validatorElement); String field = validatorElement.attributeValue("field"); if (StringUtils.isNotBlank(field)) { fieldValidators.put(field, validator); } else { modelValidators.add(validator); }/*w ww. j av a 2s.c o m*/ } if (!fieldValidators.isEmpty()) { component.setFieldValidators(fieldValidators); } if (!modelValidators.isEmpty()) { component.setModelValidators(modelValidators); } } }
From source file:enmasse.controller.api.v3.amqp.AmqpFlavorsApiTest.java
@Before public void setup() { flavorManager = new FlavorManager(); flavorsService = new FlavorsService(flavorManager); Map<String, Flavor> flavorMap = new LinkedHashMap<>(); flavorMap.put("flavor1", new Flavor.Builder("flavor1", "template1").type("queue").description("Simple queue").build()); flavorMap.put("flavor2", new Flavor.Builder("flavor2", "template2").type("topic").description("Simple topic").build()); flavorManager.flavorsUpdated(flavorMap); }
From source file:org.opencb.commons.datastore.core.ObjectMap.java
public ObjectMap() { objectMap = new LinkedHashMap<>(); }
From source file:com.sugaronrest.restapicalls.methodcalls.UpdateEntry.java
/** * Updates entry [SugarCRM REST method - set_entry]. * * @param url REST API Url./*www .j ava 2 s . com*/ * @param sessionId Session identifier. * @param moduleName SugarCRM module name. * @param entity The entity object to update. * @param selectFields Selected field list. * @return ReadEntryResponse object. */ public static UpdateEntryResponse run(String url, String sessionId, String moduleName, Object entity, List<String> selectFields) { UpdateEntryResponse updateEntryResponse = null; ErrorResponse errorResponse = null; String jsonRequest = new String(); String jsonResponse = new String(); ObjectMapper mapper = JsonObjectMapper.getMapper(); try { Map<String, Object> requestData = new LinkedHashMap<String, Object>(); requestData.put("session", sessionId); requestData.put("module_name", moduleName); requestData.put("name_value_list", EntityToNameValueList(entity, selectFields)); String jsonRequestData = mapper.writeValueAsString(requestData); Map<String, Object> request = new LinkedHashMap<String, Object>(); request.put("method", "set_entry"); request.put("input_type", "json"); request.put("response_type", "json"); request.put("rest_data", requestData); jsonRequest = mapper.writeValueAsString(request); request.put("rest_data", jsonRequestData); HttpResponse response = Unirest.post(url).fields(request).asString(); if (response == null) { updateEntryResponse = new UpdateEntryResponse(); errorResponse = ErrorResponse.format("An error has occurred!", "No data returned."); updateEntryResponse.setStatusCode(HttpStatus.SC_BAD_REQUEST); updateEntryResponse.setError(errorResponse); } else { jsonResponse = response.getBody().toString(); if (StringUtils.isNotBlank(jsonResponse)) { // First check if we have an error errorResponse = ErrorResponse.fromJson(jsonResponse); if (errorResponse == null) { updateEntryResponse = mapper.readValue(jsonResponse, UpdateEntryResponse.class); } } if (updateEntryResponse == null) { updateEntryResponse = new UpdateEntryResponse(); updateEntryResponse.setError(errorResponse); updateEntryResponse.setStatusCode(HttpStatus.SC_OK); if (errorResponse != null) { updateEntryResponse.setStatusCode(errorResponse.getStatusCode()); } } else { updateEntryResponse.setStatusCode(HttpStatus.SC_OK); } } } catch (Exception exception) { updateEntryResponse = new UpdateEntryResponse(); errorResponse = ErrorResponse.format(exception, exception.getMessage()); updateEntryResponse.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); errorResponse.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); updateEntryResponse.setError(errorResponse); } updateEntryResponse.setJsonRawRequest(jsonRequest); updateEntryResponse.setJsonRawResponse(jsonResponse); return updateEntryResponse; }
From source file:com.sugaronrest.restapicalls.methodcalls.InsertEntry.java
/** * Insert entry [SugarCRM REST method - set_entry]. * * @param url REST API Url.//from w w w . j a v a 2s . c om * @param sessionId Session identifier. * @param moduleName SugarCRM module name. * @param entity The entity object to create. * @param selectFields Selected field list. * @return InsertEntryResponse object. */ public static InsertEntryResponse run(String url, String sessionId, String moduleName, Object entity, List<String> selectFields) { InsertEntryResponse insertEntryResponse = null; ErrorResponse errorResponse = null; String jsonRequest = new String(); String jsonResponse = new String(); ObjectMapper mapper = JsonObjectMapper.getMapper(); try { Map<String, Object> requestData = new LinkedHashMap<String, Object>(); requestData.put("session", sessionId); requestData.put("module_name", moduleName); requestData.put("name_value_list", EntityToNameValueList(entity, selectFields)); String jsonRequestData = mapper.writeValueAsString(requestData); Map<String, Object> request = new LinkedHashMap<String, Object>(); request.put("method", "set_entry"); request.put("input_type", "json"); request.put("response_type", "json"); request.put("rest_data", requestData); jsonRequest = mapper.writeValueAsString(request); request.put("rest_data", jsonRequestData); HttpResponse response = Unirest.post(url).fields(request).asString(); if (response == null) { insertEntryResponse = new InsertEntryResponse(); errorResponse = ErrorResponse.format("An error has occurred!", "No data returned."); insertEntryResponse.setStatusCode(HttpStatus.SC_BAD_REQUEST); insertEntryResponse.setError(errorResponse); } else { jsonResponse = response.getBody().toString(); if (StringUtils.isNotBlank(jsonResponse)) { // First check if we have an error errorResponse = ErrorResponse.fromJson(jsonResponse); if (errorResponse == null) { insertEntryResponse = mapper.readValue(jsonResponse, InsertEntryResponse.class); } } if (insertEntryResponse == null) { insertEntryResponse = new InsertEntryResponse(); insertEntryResponse.setError(errorResponse); insertEntryResponse.setStatusCode(HttpStatus.SC_OK); if (errorResponse != null) { insertEntryResponse.setStatusCode(errorResponse.getStatusCode()); } } else { insertEntryResponse.setStatusCode(HttpStatus.SC_OK); } } } catch (Exception exception) { insertEntryResponse = new InsertEntryResponse(); errorResponse = ErrorResponse.format(exception, exception.getMessage()); insertEntryResponse.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); errorResponse.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); insertEntryResponse.setError(errorResponse); } insertEntryResponse.setJsonRawRequest(jsonRequest); insertEntryResponse.setJsonRawResponse(jsonResponse); return insertEntryResponse; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.IOHelper.java
/** * Sorts map by value (http://stackoverflow.com/a/2581754) * * @param map map//from w w w.jav a2 s. c o m * @param <K> key * @param <V> value * @return sorted map by value */ public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map, final boolean asc) { List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { @Override public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { if (asc) { return (o1.getValue()).compareTo(o2.getValue()); } else { return (o2.getValue()).compareTo(o1.getValue()); } } }); LinkedHashMap<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; }