List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:org.opendatakit.common.android.data.ColumnDefinition.java
/** * Covert the ColumnDefinition map into a JSON schema. * * Add elements to this schema to match the dataTableModel produced by XLSXConverter * * @param orderedDefns/*from ww w . j a va2 s. c o m*/ * @return */ static TreeMap<String, Object> getDataModel(List<ColumnDefinition> orderedDefns) { TreeMap<String, Object> model = new TreeMap<String, Object>(); for (ColumnDefinition c : orderedDefns) { if (c.getParent() == null) { TreeMap<String, Object> jsonSchema = new TreeMap<String, Object>(); model.put(c.getElementName(), jsonSchema); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, c.getElementName()); getDataModelHelper(jsonSchema, c, false); } } return model; }
From source file:com.pindroid.client.PinboardApi.java
/** * Retrieves the entire list of bookmarks for a user from Pinboard. * /*w w w . j a v a 2s . c om*/ * @param tagname If specified, will only retrieve bookmarks with a specific tag. * @param start Bookmark number to start from. * @param count Number of results to retrieve. * @param account The account being synced. * @param context The current application context. * @return A list of bookmarks received from the server. * @throws IOException If a server error was encountered. * @throws AuthenticationException If an authentication error was encountered. * @throws TooManyRequestsException * @throws PinboardException */ public static ArrayList<Bookmark> getAllBookmarks(String tagName, int start, int count, Account account, Context context) throws IOException, AuthenticationException, TooManyRequestsException, PinboardException { ArrayList<Bookmark> bookmarkList = new ArrayList<Bookmark>(); InputStream responseStream = null; TreeMap<String, String> params = new TreeMap<String, String>(); String url = FETCH_BOOKMARKS_URI; if (tagName != null && tagName != "") { params.put("tag", tagName); } if (start != 0) { params.put("start", Integer.toString(start)); } if (count != 0) { params.put("results", Integer.toString(count)); } params.put("meta", "yes"); responseStream = PinboardApiCall(url, params, account, context); SaxBookmarkParser parser = new SaxBookmarkParser(responseStream); try { bookmarkList = parser.parse(); } catch (ParseException e) { Log.e(TAG, "Server error in fetching bookmark list"); throw new IOException(); } responseStream.close(); return bookmarkList; }
From source file:com.heliosapm.tsdblite.metric.MetricCache.java
/** * Returns the long hash code for the passed metric JSON node * @param metricNode a metric JSON node/*from ww w .jav a 2s . c om*/ * @return the long hash code */ public static long hashCode(final JsonNode metricNode) { if (metricNode == null) throw new IllegalArgumentException("The passed node was null"); try { final TreeMap<String, String> cleanedTags = new TreeMap<String, String>(ROOT_COLLATOR); final JsonNode tags = metricNode.get("tags"); for (final Iterator<String> keyIter = tags.fieldNames(); keyIter.hasNext();) { final String key = keyIter.next(); cleanedTags.put(key, tags.get(key).textValue()); } return hashCode(metricNode.get("metric").textValue(), cleanedTags); } catch (Exception ex) { throw new RuntimeException("Failed to calc hash for metric node [" + metricNode + "]", ex); } }
From source file:com.qwazr.cluster.manager.ClusterManager.java
private static TreeMap<String, StatusEnum> getStatusMap(HashMap<String, ClusterNodeSet> nodeMap) { TreeMap<String, StatusEnum> statusMap = new TreeMap<String, StatusEnum>(); if (nodeMap == null) return statusMap; for (Map.Entry<String, ClusterNodeSet> entry : nodeMap.entrySet()) { Cache cache = entry.getValue().getCache(); StatusEnum status = ClusterServiceStatusJson.findStatus(cache.activeArray.length, cache.inactiveArray.length); statusMap.put(entry.getKey(), status); }//w ww . jav a 2 s . co m return statusMap; }
From source file:org.opendatakit.common.android.data.ColumnDefinition.java
/** * Covert the ColumnDefinition map into a JSON schema. and augment it with * the schema for the administrative columns. * * The structure of this schema matches the dataTableModel produced by XLSXConverter * * @param orderedDefns/*from w w w .j a va 2s .co m*/ * @return */ static TreeMap<String, Object> getExtendedDataModel(List<ColumnDefinition> orderedDefns) { TreeMap<String, Object> model = getDataModel(orderedDefns); TreeMap<String, Object> jsonSchema; // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.ID, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_IS_NOT_NULLABLE, Boolean.TRUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.ID); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.ID); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.ID); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.ROW_ETAG, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.ROW_ETAG); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.ROW_ETAG); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.ROW_ETAG); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.SYNC_STATE, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_IS_NOT_NULLABLE, Boolean.TRUE); // don't force a default value -- the database layer handles sync state initialization itself. jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.SYNC_STATE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.SYNC_STATE); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.SYNC_STATE); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.CONFLICT_TYPE, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.integer.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.CONFLICT_TYPE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.CONFLICT_TYPE); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.CONFLICT_TYPE); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.FILTER_TYPE, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.FILTER_TYPE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.FILTER_TYPE); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.FILTER_TYPE); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.FILTER_VALUE, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.FILTER_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.FILTER_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.FILTER_VALUE); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.FORM_ID, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.FORM_ID); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.FORM_ID); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.FORM_ID); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.LOCALE, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.LOCALE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.LOCALE); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.LOCALE); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.SAVEPOINT_TYPE, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.SAVEPOINT_TYPE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.SAVEPOINT_TYPE); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.SAVEPOINT_TYPE); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.SAVEPOINT_TIMESTAMP, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.SAVEPOINT_TIMESTAMP); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.SAVEPOINT_TIMESTAMP); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.SAVEPOINT_TIMESTAMP); // jsonSchema = new TreeMap<String, Object>(); model.put(DataTableColumns.SAVEPOINT_CREATOR, jsonSchema); jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_METADATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, DataTableColumns.SAVEPOINT_CREATOR); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, DataTableColumns.SAVEPOINT_CREATOR); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, DataTableColumns.SAVEPOINT_CREATOR); return model; }
From source file:module.entities.NameFinder.DB.java
public static TreeMap<Integer, String> getClusterDocuments(int clid) throws SQLException { TreeMap<Integer, String> all = new TreeMap<Integer, String>(); String selectSQL = "SELECT palo_id,raw_text FROM texts_herc where text_id=" + clid + ";"; ResultSet rs = connection.createStatement().executeQuery(selectSQL); while (rs.next()) { int tid = rs.getInt(1); String s = rs.getString(2); all.put(tid, s); }//w w w. ja v a 2s .c o m return all; }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java
@SuppressWarnings("squid:S3776") private static void outputProperty(Property property, ChecksumGeneratorOptions opts, JsonWriter out) throws RepositoryException, IOException { Set<String> sortValues = opts.getSortedProperties(); if (property.isMultiple()) { out.name(property.getName());/*from w w w .ja v a2 s. c o m*/ // create an array for multi value output out.beginArray(); boolean isSortedValues = sortValues.contains(property.getName()); Value[] values = property.getValues(); TreeMap<String, Value> sortedValueMap = new TreeMap<String, Value>(); for (Value v : values) { int type = v.getType(); if (type == PropertyType.BINARY) { if (isSortedValues) { try { java.io.InputStream stream = v.getBinary().getStream(); String ckSum = DigestUtils.shaHex(stream); stream.close(); sortedValueMap.put(ckSum, v); } catch (IOException e) { sortedValueMap.put("ERROR: generating hash for binary of " + property.getPath() + " : " + e.getMessage(), v); } } else { outputPropertyValue(property, v, out); } } else { String val = v.getString(); if (isSortedValues) { sortedValueMap.put(val, v); } else { outputPropertyValue(property, v, out); } } } if (isSortedValues) { for (Value v : sortedValueMap.values()) { outputPropertyValue(property, v, out); } } out.endArray(); // end multi value property output } else { out.name(property.getName()); outputPropertyValue(property, property.getValue(), out); } }
From source file:org.opendatakit.database.data.ColumnDefinition.java
/** * Covert the ColumnDefinition map into a JSON schema. * <p>/*from w w w . j a v a 2 s. co m*/ * Add elements to this schema to match the dataTableModel produced by XLSXConverter * * @param orderedDefns a list of column definitions * @return the JSON schema for those columns */ static TreeMap<String, Object> getDataModel(List<ColumnDefinition> orderedDefns) { TreeMap<String, Object> model = new TreeMap<>(); for (ColumnDefinition c : orderedDefns) { if (c.getParent() == null) { TreeMap<String, Object> jsonSchema = new TreeMap<>(); model.put(c.getElementName(), jsonSchema); jsonSchema.put(JSON_SCHEMA_ELEMENT_PATH, c.getElementName()); getDataModelHelper(jsonSchema, c, false); if (!c.isUnitOfRetention()) { jsonSchema.put(JSON_SCHEMA_NOT_UNIT_OF_RETENTION, Boolean.TRUE); } } } return model; }
From source file:anslab2.AnsLab2.java
public static DefaultTableModel generateTable(boolean fdt, boolean rft, int dataType, ArrayList labels, String label) {/*w ww .ja v a 2s . co m*/ //DefaultTableModel model = new DefaultTableModel(); HashMap<String, Integer> map = new HashMap<String, Integer>(); for (Object temp : labels) { Integer count = map.get(String.valueOf(temp)); map.put(String.valueOf(temp), (count == null) ? 1 : count + 1); } Vector _label = new Vector(); Vector _freq = new Vector(); Vector _rel_freq = new Vector(); if (dataType == 1 || dataType == 3) { for (Map.Entry<String, Integer> entry : map.entrySet()) { _label.add(entry.getKey()); _freq.add(entry.getValue()); _rel_freq.add(((double) entry.getValue() / labels.size()) * (100)); } string_maps = map; model.addColumn(label, _label); } else if (dataType == 2) { TreeMap<Double, Integer> num_map = new TreeMap<Double, Integer>(); for (Map.Entry<String, Integer> entry : map.entrySet()) { num_map.put(Double.valueOf(entry.getKey()), entry.getValue()); } for (Map.Entry<Double, Integer> entry1 : num_map.entrySet()) { _label.add(entry1.getKey()); _freq.add(entry1.getValue()); _rel_freq.add(round(((double) entry1.getValue() / labels.size()) * (100), 2)); } double_maps = num_map; model.addColumn(label, _label); } if (fdt == true) { model.addColumn("Frequency", _freq); } if (rft == true) { model.addColumn("Relative Frequency", _rel_freq); } return model; }
From source file:org.opendatakit.common.android.data.ColumnDefinition.java
private static void getDataModelHelper(TreeMap<String, Object> jsonSchema, ColumnDefinition c, boolean nestedInsideUnitOfRetention) { ElementType type = c.getType(); ElementDataType dataType = type.getDataType(); // this is a user-defined field jsonSchema.put(JSON_SCHEMA_ELEMENT_SET, JSON_SCHEMA_INSTANCE_DATA_VALUE); jsonSchema.put(JSON_SCHEMA_ELEMENT_NAME, c.getElementName()); jsonSchema.put(JSON_SCHEMA_ELEMENT_KEY, c.getElementKey()); if (nestedInsideUnitOfRetention) { jsonSchema.put(JSON_SCHEMA_NOT_UNIT_OF_RETENTION, Boolean.TRUE); }/*from w w w . ja v a 2 s. c o m*/ if (dataType == ElementDataType.array) { jsonSchema.put(JSON_SCHEMA_TYPE, dataType.name()); if (!c.getElementType().equals(dataType.name())) { jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } ColumnDefinition ch = c.getChildren().get(0); TreeMap<String, Object> itemSchema = new TreeMap<String, Object>(); jsonSchema.put(JSON_SCHEMA_ITEMS, itemSchema); itemSchema.put(JSON_SCHEMA_ELEMENT_PATH, ((String) jsonSchema.get(JSON_SCHEMA_ELEMENT_PATH)) + '.' + ch.getElementName()); // if it isn't already nested within a unit of retention, // an array is always itself a unit of retention getDataModelHelper(itemSchema, ch, true); // recursion... } else if (dataType == ElementDataType.bool) { jsonSchema.put(JSON_SCHEMA_TYPE, dataType.name()); if (!c.getElementType().equals(dataType.name())) { jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } } else if (dataType == ElementDataType.configpath) { jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } else if (dataType == ElementDataType.integer) { jsonSchema.put(JSON_SCHEMA_TYPE, dataType.name()); if (!c.getElementType().equals(dataType.name())) { jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } } else if (dataType == ElementDataType.number) { jsonSchema.put(JSON_SCHEMA_TYPE, dataType.name()); if (!c.getElementType().equals(dataType.name())) { jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } } else if (dataType == ElementDataType.object) { jsonSchema.put(JSON_SCHEMA_TYPE, dataType.name()); if (!c.getElementType().equals(dataType.name())) { jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } TreeMap<String, Object> propertiesSchema = new TreeMap<String, Object>(); jsonSchema.put(JSON_SCHEMA_PROPERTIES, propertiesSchema); for (ColumnDefinition ch : c.getChildren()) { TreeMap<String, Object> itemSchema = new TreeMap<String, Object>(); propertiesSchema.put(ch.getElementName(), itemSchema); itemSchema.put(JSON_SCHEMA_ELEMENT_PATH, ((String) jsonSchema.get(JSON_SCHEMA_ELEMENT_PATH)) + '.' + ch.getElementName()); // objects are not units of retention -- propagate retention status. getDataModelHelper(itemSchema, ch, nestedInsideUnitOfRetention); // recursion... } } else if (dataType == ElementDataType.rowpath) { jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, ElementDataType.rowpath.name()); } else if (dataType == ElementDataType.string) { jsonSchema.put(JSON_SCHEMA_TYPE, ElementDataType.string.name()); if (!c.getElementType().equals(dataType.name())) { jsonSchema.put(JSON_SCHEMA_ELEMENT_TYPE, c.getElementType()); } } else { throw new IllegalStateException("unexpected alternative ElementDataType"); } }