/** * Searches a map for a given key. The key can be a regular map key, or a * simple expression of the form: * * <ul> * <li>foo.bar (will lookup 'foo', and then 'bar' in a potential nested map) * </li> * <li>foo.bar[0].baz (will lookup 'foo', then 'bar' in a potential nested * map, then pick the first element in case it is a list/array and then pick * 'baz' from the potential map at that position). * </ul> * * @param map * the map to search in * @param key * the key to resolve * @return the object in the map with the given key/expression. Or null if * it does not exist. */ public static Object find(final Map<String, ?> map, final String key) { return CollectionUtils.find(map, key); }
/** * Searches a map for a given key. The key can be a regular map key, or a * simple expression of the form: * * <ul> * <li>foo.bar (will lookup 'foo', and then 'bar' in a potential nested map) * </li> * <li>foo.bar[0].baz (will lookup 'foo', then 'bar' in a potential nested * map, then pick the first element in case it is a list/array and then pick * 'baz' from the potential map at that position). * </ul> * * @param map * the map to search in * @param key * the key to resolve * @return the object in the map with the given key/expression. Or null if * it does not exist. */ public static Object find(Map<?, ?> map, String key) { if (map == null || key == null) { return null; } final Object result = map.get(key); if (result == null) { return find(map, key, 0); } return result; }
/** * Searches a map for a given key. The key can be a regular map key, or a * simple expression of the form: * * <ul> * <li>foo.bar (will lookup 'foo', and then 'bar' in a potential nested map) * </li> * <li>foo.bar[0].baz (will lookup 'foo', then 'bar' in a potential nested * map, then pick the first element in case it is a list/array and then pick * 'baz' from the potential map at that position). * </ul> * * @param map * the map to search in * @param key * the key to resolve * @return the object in the map with the given key/expression. Or null if * it does not exist. */ public static Object find(Map<?, ?> map, String key) { if (map == null || key == null) { return null; } final Object result = map.get(key); if (result == null) { return find(map, key, 0); } return result; }
protected Object get(Document document, String columnName) { final Map<String, ?> map = document.getValues(); final Object value = CollectionUtils.find(map, columnName); return value; }
@Override public Object evaluate(Row row, Object[] parameters, SelectItem operandItem) { if (parameters.length == 0) { throw new IllegalArgumentException("Expecting path parameter to MAP_VALUE function"); } final Object value = row.getValue(operandItem); if (value instanceof Map) { final Map<?, ?> map = (Map<?, ?>) value; return CollectionUtils.find(map, (String) parameters[0]); } return null; }
protected Object get(Document document, String columnName) { final Map<String, ?> map = document.getValues(); final Object value = CollectionUtils.find(map, columnName); return value; }
@Override public Object evaluate(Row row, Object[] parameters, SelectItem operandItem) { if (parameters.length == 0) { throw new IllegalArgumentException("Expecting path parameter to MAP_VALUE function"); } final Object value = row.getValue(operandItem); if (value instanceof Map) { final Map<?, ?> map = (Map<?, ?>) value; return CollectionUtils.find(map, (String) parameters[0]); } return null; }
final Object nestedObject = map.get(prefix); if (nestedObject == null) { return find(map, key, indexOfDot + 1); @SuppressWarnings("unchecked") final Map<String, ?> nestedMap = (Map<String, ?>) nestedObject; return find(nestedMap, remainingPart); final Object nestedObject = map.get(prefix); if (nestedObject == null) { return find(map, key, indexOfBracket + 1); @SuppressWarnings("unchecked") final Map<String, ?> nestedMap = (Map<String, ?>) valueAtIndex; return find(nestedMap, remainingPart); } else {
final Object nestedObject = map.get(prefix); if (nestedObject == null) { return find(map, key, indexOfDot + 1); @SuppressWarnings("unchecked") final Map<String, ?> nestedMap = (Map<String, ?>) nestedObject; return find(nestedMap, remainingPart); final Object nestedObject = map.get(prefix); if (nestedObject == null) { return find(map, key, indexOfBracket + 1); @SuppressWarnings("unchecked") final Map<String, ?> nestedMap = (Map<String, ?>) valueAtIndex; return find(nestedMap, remainingPart); } else {
@Override protected String doInBackground() throws Exception { final HttpUriRequest req = RequestBuilder.get(OpenDataCleanerWebsiteActionListener.createUrl("/meta/versions.json")).build(); final CloseableHttpClient client = HttpClients.custom() // because the HTTPS cert for datacleaner.github.io is registered for github.com, the hostname // verifier has to be more loose than default. .setSSLHostnameVerifier(new NaiveHostnameVerifier()).build(); try { try (CloseableHttpResponse resp = client.execute(req)) { final String body = EntityUtils.toString(resp.getEntity()); final Map<?, ?> bodyAsMap = new ObjectMapper().readValue(body, Map.class); final String latestVersion = (String) CollectionUtils.find(bodyAsMap, "latest.version"); return latestVersion; } } finally { client.close(); } }
/** * Converts {@link JsonNode} to MetaModel {@link Row}. * * @param node * {@link JsonNode} to convert. * @param selectItems * Column names for the values in the row. * @return MetaModel {@link Row} populated with values from {@link JsonNode} * . */ public static Row jsonNodeToMetaModelRow(JsonNode node, DataSetHeader header) { final Map<String, ?> map = jsonNodeToMap(node); final int size = header.size(); final Object[] values = new Object[size]; for (int i = 0; i < size; i++) { final String key = header.getSelectItem(i).getColumn().getName(); final Object value = CollectionUtils.find(map, key); values[i] = value; } final DefaultRow finalRow = new DefaultRow(header, values); return finalRow; }
/** * Converts a map into MetaModel. This map stores data of a MongoDB document. * * @param map * a map object storing data of a MongoDB document. * @param header * a header describing the columns of the data stored. * @return the MetaModel {@link Row} result object. */ public static Row toRow(Map<?,?> map, DataSetHeader header) { if (map == null) { return null; } final int size = header.size(); final Object[] values = new Object[size]; for (int i = 0; i < values.length; i++) { final SelectItem selectItem = header.getSelectItem(i); final String key = selectItem.getColumn().getName(); final Object value = CollectionUtils.find(map, key); values[i] = toValue(selectItem.getColumn(), value); } return new DefaultRow(header, values); }
/** * Converts a map into MetaModel. This map stores data of a MongoDB document. * * @param map * a map object storing data of a MongoDB document. * @param header * a header describing the columns of the data stored. * @return the MetaModel {@link Row} result object. */ public static Row toRow(Map<?,?> map, DataSetHeader header) { if (map == null) { return null; } final int size = header.size(); final Object[] values = new Object[size]; for (int i = 0; i < values.length; i++) { final SelectItem selectItem = header.getSelectItem(i); final String key = selectItem.getColumn().getName(); final Object value = CollectionUtils.find(map, key); values[i] = toValue(selectItem.getColumn(), value); } return new DefaultRow(header, values); }