use of java.util.LinkedHashMap in project camel by apache.
the class JSonSchemaHelper method parseJsonSchema.
/**
* Parses the json schema to split it into a list or rows, where each row contains key value pairs with the metadata
*
* @param group the group to parse from such as <tt>component</tt>, <tt>componentProperties</tt>, or <tt>properties</tt>.
* @param json the json
* @return a list of all the rows, where each row is a set of key value pairs with metadata
*/
public static List<Map<String, String>> parseJsonSchema(String group, String json, boolean parseProperties) {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
if (json == null) {
return answer;
}
boolean found = false;
// parse line by line
String[] lines = json.split("\n");
for (String line : lines) {
// we need to find the group first
if (!found) {
String s = line.trim();
found = s.startsWith("\"" + group + "\":") && s.endsWith("{");
continue;
}
// we should stop when we end the group
if (line.equals(" },") || line.equals(" }")) {
break;
}
// need to safe encode \" so we can parse the line
line = line.replaceAll("\"\\\\\"\"", '"' + QUOT + '"');
Map<String, String> row = new LinkedHashMap<String, String>();
Matcher matcher = PATTERN.matcher(line);
String key;
if (parseProperties) {
// when parsing properties the first key is given as name, so the first parsed token is the value of the name
key = "name";
} else {
key = null;
}
while (matcher.find()) {
if (key == null) {
key = matcher.group(1);
} else {
String value = matcher.group(1);
if (value != null) {
// its text based
value = value.trim();
// decode
value = value.replaceAll(QUOT, "\"");
value = decodeJson(value);
}
if (value == null) {
// not text then its maybe an enum?
value = matcher.group(2);
if (value != null) {
// its an enum so strip out " and trim spaces after comma
value = value.replaceAll("\"", "");
value = value.replaceAll(", ", ",");
value = value.trim();
}
}
if (value == null) {
// not text then its maybe a boolean?
value = matcher.group(3);
}
if (value == null) {
// not text then its maybe a integer?
value = matcher.group(4);
}
if (value != null) {
row.put(key, value);
}
// reset
key = null;
}
}
if (!row.isEmpty()) {
answer.add(row);
}
}
return answer;
}
use of java.util.LinkedHashMap in project camel by apache.
the class CamelControllerImpl method getCamelContexts.
public List<Map<String, String>> getCamelContexts() throws Exception {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
List<CamelContext> camelContexts = getLocalCamelContexts();
for (CamelContext camelContext : camelContexts) {
Map<String, String> row = new LinkedHashMap<String, String>();
row.put("name", camelContext.getName());
row.put("state", camelContext.getStatus().name());
row.put("uptime", camelContext.getUptime());
if (camelContext.getManagedCamelContext() != null) {
row.put("exchangesTotal", "" + camelContext.getManagedCamelContext().getExchangesTotal());
row.put("exchangesInflight", "" + camelContext.getManagedCamelContext().getExchangesInflight());
row.put("exchangesFailed", "" + camelContext.getManagedCamelContext().getExchangesFailed());
} else {
row.put("exchangesTotal", "0");
row.put("exchangesInflight", "0");
row.put("exchangesFailed", "0");
}
answer.add(row);
}
return answer;
}
use of java.util.LinkedHashMap in project jforum2 by rafaelsteil.
the class PostRepository method selectAllByTopicByLimit.
public static List selectAllByTopicByLimit(int topicId, int start, int count) {
String tid = Integer.toString(topicId);
List posts = (List) cache.get(FQN, tid);
if (posts == null || posts.size() == 0) {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
posts = pm.selectAllByTopic(topicId);
for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
PostCommon.preparePostForDisplay((Post) iter.next());
}
Map topics = (Map) cache.get(FQN);
if (topics == null || topics.size() == 0 || topics.size() < CACHE_SIZE) {
cache.add(FQN, tid, posts);
} else {
if (!(topics instanceof LinkedHashMap)) {
topics = new LinkedHashMap(topics) {
protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
return this.size() > CACHE_SIZE;
}
};
}
topics.put(tid, posts);
cache.add(FQN, topics);
}
}
int size = posts.size();
return posts.subList(start, (size < start + count) ? size : start + count);
}
use of java.util.LinkedHashMap in project rest.li by linkedin.
the class TestQueryParamsDataMap method testProcessProjections.
/**
* Creates MaskTrees and extracts the subsequent DataMap to verify that processProjections can correctly
* convert it correctly into a Map that can later be constructed and encoded into an URI
*/
@Test
public void testProcessProjections() {
//Construct a MaskTree from a series of PathSpecs. Extract the subsequent Datamap representation.
final MaskTree rootObjectsMask = MaskCreator.createPositiveMask(new PathSpec("foo", PathSpec.WILDCARD, "bar"));
final MaskTree metadataMask = MaskCreator.createPositiveMask(new PathSpec("foo", "bar"), new PathSpec("bar", "baz"), new PathSpec("qux"));
final MaskTree pagingMask = MaskCreator.createPositiveMask(new PathSpec("total"), new PathSpec("count"), new PathSpec("links", PathSpec.WILDCARD, "rel"));
//For each type of projection, plus one query string parameter
final DataMap resultMap = new DataMap(4);
resultMap.put(RestConstants.FIELDS_PARAM, rootObjectsMask.getDataMap());
resultMap.put(RestConstants.METADATA_FIELDS_PARAM, metadataMask.getDataMap());
resultMap.put(RestConstants.PAGING_FIELDS_PARAM, pagingMask.getDataMap());
resultMap.put("someQueryString", "someValue");
final Map<String, List<String>> processedProjections = new LinkedHashMap<String, List<String>>();
final DataMap processedDataMap = QueryParamsDataMap.processProjections(resultMap, processedProjections);
Assert.assertTrue(processedDataMap.size() == 1, "Processed datamap should only have one item left!");
final Map<String, Set<String>> expectedProcessedProjections = new LinkedHashMap<String, Set<String>>();
//"{fields=[foo:($*:(bar))], metadataFields=[foo:(bar),bar:(baz),qux], pagingFields=[total,count,links:($*:(rel))]}"
expectedProcessedProjections.put(RestConstants.FIELDS_PARAM, Collections.singleton("foo:($*:(bar))"));
expectedProcessedProjections.put(RestConstants.METADATA_FIELDS_PARAM, new HashSet<String>(Arrays.asList("foo:(bar)", "bar:(baz)", "qux")));
expectedProcessedProjections.put(RestConstants.PAGING_FIELDS_PARAM, new HashSet<String>(Arrays.asList("total", "count", "links:($*:(rel))")));
Assert.assertEquals(processedProjections.size(), expectedProcessedProjections.size(), "We must have the correct number of" + " expected projections!");
for (final Map.Entry<String, List<String>> entry : processedProjections.entrySet()) {
//Acceptable because these are always comma delimited
final Set<String> actualProjectionValueSet = new HashSet<String>(Arrays.asList(entry.getValue().get(0).split(",")));
Assert.assertEquals(actualProjectionValueSet, expectedProcessedProjections.get(entry.getKey()), "The individual projection " + "for " + entry.getKey() + " does not match what is expected!");
}
}
use of java.util.LinkedHashMap in project okhttp by square.
the class RequestBodyCompression method run.
public void run() throws Exception {
Map<String, String> requestBody = new LinkedHashMap<>();
requestBody.put("longUrl", "https://publicobject.com/2014/12/04/html-formatting-javadocs/");
RequestBody jsonRequestBody = RequestBody.create(MEDIA_TYPE_JSON, mapJsonAdapter.toJson(requestBody));
Request request = new Request.Builder().url("https://www.googleapis.com/urlshortener/v1/url?key=" + GOOGLE_API_KEY).post(jsonRequestBody).build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful())
throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
}
Aggregations