List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:io.kloudwork.util.MultipartFormHandler.java
public static MultipartParamHolder handle(Request request) throws IOException, FileUploadException { if (!ServletFileUpload.isMultipartContent(request.raw())) { return parseContent(request); }/*from www . j a v a 2s. c om*/ ServletFileUpload servletFileUpload = new ServletFileUpload(); FileItemIterator iterator = servletFileUpload.getItemIterator(request.raw()); Map<String, String> postParameters = new HashMap<>(); Map<String, FileItemStream> files = new HashMap<>(); while (iterator.hasNext()) { FileItemStream fileItem = iterator.next(); if (fileItem.isFormField()) { try (InputStream is = fileItem.openStream()) { postParameters.put(fileItem.getFieldName(), Streams.asString(is)); } } else { files.put(fileItem.getFieldName(), fileItem); } } if (files.isEmpty()) { return new MultipartParamHolder(postParameters); } return new MultipartParamHolder(postParameters, files); }
From source file:com.espertech.esper.event.util.JSONRendererImpl.java
private static void recursiveRender(EventBean theEvent, StringBuilder buf, int level, RendererMeta meta, RendererMetaOptions rendererOptions) { String delimiter = ""; // simple properties GetterPair[] simpleProps = meta.getSimpleProperties(); if (rendererOptions.getRenderer() == null) { for (GetterPair simpleProp : simpleProps) { Object value = simpleProp.getGetter().get(theEvent); writeDelimitedIndentedProp(buf, delimiter, level, simpleProp.getName()); simpleProp.getOutput().render(value, buf); delimiter = COMMA_DELIMITER_NEWLINE; }// w ww. j ava 2s . c o m } else { EventPropertyRendererContext context = rendererOptions.getRendererContext(); context.setStringBuilderAndReset(buf); for (GetterPair simpleProp : simpleProps) { Object value = simpleProp.getGetter().get(theEvent); writeDelimitedIndentedProp(buf, delimiter, level, simpleProp.getName()); context.setDefaultRenderer(simpleProp.getOutput()); context.setPropertyName(simpleProp.getName()); context.setPropertyValue(value); rendererOptions.getRenderer().render(context); delimiter = COMMA_DELIMITER_NEWLINE; } } GetterPair[] indexProps = meta.getIndexProperties(); for (GetterPair indexProp : indexProps) { Object value = indexProp.getGetter().get(theEvent); writeDelimitedIndentedProp(buf, delimiter, level, indexProp.getName()); if (value == null) { buf.append("null"); } else { if (!value.getClass().isArray()) { buf.append("[]"); } else { buf.append('['); String arrayDelimiter = ""; if (rendererOptions.getRenderer() == null) { for (int i = 0; i < Array.getLength(value); i++) { Object arrayItem = Array.get(value, i); buf.append(arrayDelimiter); indexProp.getOutput().render(arrayItem, buf); arrayDelimiter = ", "; } } else { EventPropertyRendererContext context = rendererOptions.getRendererContext(); context.setStringBuilderAndReset(buf); for (int i = 0; i < Array.getLength(value); i++) { Object arrayItem = Array.get(value, i); buf.append(arrayDelimiter); context.setPropertyName(indexProp.getName()); context.setPropertyValue(arrayItem); context.setIndexedPropertyIndex(i); context.setDefaultRenderer(indexProp.getOutput()); rendererOptions.getRenderer().render(context); arrayDelimiter = ", "; } } buf.append(']'); } } delimiter = COMMA_DELIMITER_NEWLINE; } GetterPair[] mappedProps = meta.getMappedProperties(); for (GetterPair mappedProp : mappedProps) { Object value = mappedProp.getGetter().get(theEvent); if ((value != null) && (!(value instanceof Map))) { log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead"); continue; } writeDelimitedIndentedProp(buf, delimiter, level, mappedProp.getName()); if (value == null) { buf.append("null"); buf.append(NEWLINE); } else { Map<String, Object> map = (Map<String, Object>) value; if (map.isEmpty()) { buf.append("{}"); buf.append(NEWLINE); } else { buf.append('{'); buf.append(NEWLINE); String localDelimiter = ""; Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); for (; it.hasNext();) { Map.Entry<String, Object> entry = it.next(); if (entry.getKey() == null) { continue; } buf.append(localDelimiter); ident(buf, level + 1); buf.append('\"'); buf.append(entry.getKey()); buf.append("\": "); if (entry.getValue() == null) { buf.append("null"); } else { OutputValueRenderer outRenderer = OutputValueRendererFactory .getOutputValueRenderer(entry.getValue().getClass(), rendererOptions); if (rendererOptions.getRenderer() == null) { outRenderer.render(entry.getValue(), buf); } else { EventPropertyRendererContext context = rendererOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(mappedProp.getName()); context.setPropertyValue(entry.getValue()); context.setMappedPropertyKey(entry.getKey()); context.setDefaultRenderer(outRenderer); rendererOptions.getRenderer().render(context); } } localDelimiter = COMMA_DELIMITER_NEWLINE; } buf.append(NEWLINE); ident(buf, level); buf.append('}'); } } delimiter = COMMA_DELIMITER_NEWLINE; } NestedGetterPair[] nestedProps = meta.getNestedProperties(); for (NestedGetterPair nestedProp : nestedProps) { Object value = nestedProp.getGetter().getFragment(theEvent); writeDelimitedIndentedProp(buf, delimiter, level, nestedProp.getName()); if (value == null) { buf.append("null"); } else if (!nestedProp.isArray()) { if (!(value instanceof EventBean)) { log.warn("Property '" + nestedProp.getName() + "' expected to return EventBean and returned " + value.getClass() + " instead"); buf.append("null"); continue; } EventBean nestedEventBean = (EventBean) value; buf.append('{'); buf.append(NEWLINE); recursiveRender(nestedEventBean, buf, level + 1, nestedProp.getMetadata(), rendererOptions); ident(buf, level); buf.append('}'); } else { if (!(value instanceof EventBean[])) { log.warn("Property '" + nestedProp.getName() + "' expected to return EventBean[] and returned " + value.getClass() + " instead"); buf.append("null"); continue; } StringBuilder arrayDelimiterBuf = new StringBuilder(); arrayDelimiterBuf.append(','); arrayDelimiterBuf.append(NEWLINE); ident(arrayDelimiterBuf, level + 1); EventBean[] nestedEventArray = (EventBean[]) value; String arrayDelimiter = ""; buf.append('['); for (int i = 0; i < nestedEventArray.length; i++) { EventBean arrayItem = nestedEventArray[i]; buf.append(arrayDelimiter); arrayDelimiter = arrayDelimiterBuf.toString(); buf.append('{'); buf.append(NEWLINE); recursiveRender(arrayItem, buf, level + 2, nestedProp.getMetadata(), rendererOptions); ident(buf, level + 1); buf.append('}'); } buf.append(']'); } delimiter = COMMA_DELIMITER_NEWLINE; } buf.append(NEWLINE); }
From source file:frequencyanalysis.FrequencyAnalysis.java
public static List<Item> sortByValue(Map map) { List sortedList = new ArrayList<Item>(); while (!map.isEmpty()) { int Highest = 0; Object HighestKey = null; Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); if ((Integer) entry.getValue() > Highest) { Highest = (Integer) entry.getValue(); HighestKey = entry.getKey(); }/* ww w.j av a 2 s.co m*/ } if (HighestKey != null) { sortedList.add(new Item(HighestKey, Highest)); map.remove(HighestKey); } } return sortedList; }
From source file:de.feanor.yeoldemensa.data.MensaFactory.java
/** * WARNING: THIS WORKS ONLY WHEN THE MENSAS ARE RETURNED FROM THE SERVERIN * ASCENDING ID, STARTING BY 1!//from w w w .j av a2 s . c o m * * Returns all available Mensa names and their IDs * * @param context * Required for the sqlite db * @return Map in the format (ID, mensaName) * @throws IOException * @throws JSONException * @throws ParseException */ public static Map<Integer, String> getMensaList() throws JSONException, IOException, ParseException { MensaSQLiteHelper sqlHelper = new MensaSQLiteHelper(getContext()); Map<Integer, String> mensas = sqlHelper.getMensaList(); // We always use the mensa list in the database. Only if it is empty // (should only happen on first run of the app) refresh it from the web // server if (mensas.isEmpty()) { updateMensaList(); mensas = sqlHelper.getMensaList(); } return mensas; }
From source file:AIR.Common.Web.taglib.JsfHelpers.java
public static void setValueExpressions(UIComponent component, Map<String, String> valueExpressions, FacesContext context) {//from www . j ava 2 s . co m if (valueExpressions == null || valueExpressions.size() == 0) return; if (context == null) { context = FacesContext.getCurrentInstance(); } Application application = context.getApplication(); // http://stackoverflow.com/a/16058002/1961102 if (valueExpressions != null && !valueExpressions.isEmpty()) { ExpressionFactory factory = application.getExpressionFactory(); ELContext ctx = context.getELContext(); for (Map.Entry<String, String> entry : valueExpressions.entrySet()) { ValueExpression expr = factory.createValueExpression(ctx, entry.getValue(), Object.class); component.setValueExpression(entry.getKey(), expr); } } }
From source file:com.alibaba.dragoon.patrol.kv.PassiveSender.java
/** * ?submit(Map<String, Object> data, String miName) ??KV? * /* www .j av a 2 s. c om*/ * @param dataKey ?keymonitor???? * @param data ? * @param miName ?? * @return */ @SuppressWarnings("unchecked") @Deprecated public static boolean submit(String dataKey, Object data, String miName) { client = DragoonClient.getInstance(); if (client == null) { throw new IllegalArgumentException("client is null. can't send passive message."); } if (dataKey == null) { throw new IllegalArgumentException("dataKey is null."); } if (data == null) { throw new IllegalArgumentException("data is null."); } if (miName == null) { throw new IllegalArgumentException(" The name of monitor item is null."); } Map<String, Object> kvData = null; if (data instanceof Map<?, ?>) { try { kvData = (Map<String, Object>) data; } catch (Exception e) { throw new IllegalArgumentException("data must be Map<String, Object> ."); } if (kvData == null || kvData.isEmpty()) { throw new IllegalArgumentException("kvMap is empty."); } if (hasExceedDataSize(kvData)) { abandonDataSize += kvData.size(); abandonCount++; throw new DragoonException(" data size of map could not great than " + ALLOW_DATA_SIZE_MAX + ", Current size:" + kvData.size()); } isVaildClassType(kvData); } if (isContinual()) { continualSubmitCount++; throw new DragoonException("The operation of submiting is frequent. must be great than " + SUBMIT_FREQUENCY_MIN_MILLS + " mills"); } Passive msg = getPassiveMessage(dataKey, data, miName); client.sendNotification(msg); successSubmitCount++; return true; }
From source file:at.molindo.dbcopy.Database.java
private static Map<String, Table> readTables(Connection connection) throws SQLException { Map<String, Table> tables = new HashMap<String, Table>(); DatabaseMetaData meta = connection.getMetaData(); String catalog = connection.getCatalog(); // for each table in current catalog ResultSet rs = meta.getTables(catalog, null, null, null); try {/*from www. j av a2s.co m*/ while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); Table.Builder table = Table.builder(tableName); // columns String columnsQuery = "select COLUMN_NAME,COLLATION_NAME from information_schema.COLUMNS where TABLE_SCHEMA=? and TABLE_NAME=? order by ORDINAL_POSITION"; Map<String, Column> columns = Utils.executePrepared(connection, columnsQuery, new ColumnHandler(), catalog, tableName); if (columns.isEmpty()) { throw new IllegalStateException("table (" + tableName + ") without columns?"); } table.addColumns(columns.values()); // unique keys String uniqueKeysQuery = "show keys from `" + tableName + "` in `" + catalog + "` where `Non_unique` = 0 and `Null` = ''"; List<Map<String, Object>> uniqueKeyColumns = Utils.executePrepared(connection, uniqueKeysQuery, new MapListHandler()); ListMap<String, Column> uniqeKeys = new ListMap<String, Column>(); for (Map<String, Object> keyColumn : uniqueKeyColumns) { String name = (String) keyColumn.get("INDEX_NAME"); String columnName = (String) keyColumn.get("COLUMN_NAME"); if (name == null) { throw new IllegalStateException("KEY_NAME must not be null"); } if (columnName == null) { throw new IllegalStateException("COLUMN_NAME must not be null"); } Column column = columns.get(columnName); if (column == null) { throw new IllegalStateException("COLUMN_NAME unknown: " + columnName); } uniqeKeys.add(name, column); } for (Map.Entry<String, List<Column>> e : uniqeKeys.entrySet()) { table.addUniqueKey(e.getKey(), e.getValue()); } if (uniqeKeys.isEmpty()) { log.warn("table without primary key not supported: " + tableName); } else { tables.put(tableName, table.build()); } } } finally { Utils.close(rs); } return tables; }
From source file:net.paissad.minus.utils.HttpClientUtils.java
private static List<NameValuePair> getHttpParamsFromMap(final Map<String, String> parametersBody) { List<NameValuePair> params = new ArrayList<NameValuePair>(); if (parametersBody != null && !parametersBody.isEmpty()) { Iterator<Entry<String, String>> iter = parametersBody.entrySet().iterator(); while (iter.hasNext()) { Entry<String, String> o = iter.next(); params.add(new BasicNameValuePair(o.getKey(), o.getValue())); }/*from w w w . j a va2s . com*/ } return params; }
From source file:com.erudika.para.core.ParaObjectUtils.java
/** * Populates an object with an array of query parameters (dangerous!). * <b>This method might be deprecated in the future.</b> * * @param <P> the object type/*from ww w . j a va 2 s . c o m*/ * @param transObject an object * @param paramMap a query parameters map */ public static <P extends ParaObject> void populate(P transObject, Map<String, String[]> paramMap) { if (transObject == null || paramMap == null || paramMap.isEmpty()) { return; } Class<Locked> locked = (paramMap.containsKey(Config._ID)) ? Locked.class : null; Map<String, Object> fields = getAnnotatedFields(transObject, locked); Map<String, Object> data = new HashMap<String, Object>(); // populate an object with converted param values from param map. try { for (Map.Entry<String, String[]> ks : paramMap.entrySet()) { String param = ks.getKey(); String[] values = ks.getValue(); String value = (values.length > 1) ? getJsonWriter().writeValueAsString(values) : values[0]; if (fields.containsKey(param)) { data.put(param, value); } } setAnnotatedFields(transObject, data, locked); } catch (Exception ex) { logger.error(null, ex); } }
From source file:com.googlecode.jtiger.modules.ecside.util.ECSideUtils.java
public static String getDefaultSortSQL(Map map) { StringBuffer rs = new StringBuffer(); if (map != null && !map.isEmpty()) { for (Iterator itor = map.keySet().iterator(); itor.hasNext();) { Object field = (String) itor.next(); String ord = (String) map.get(field); rs.append(" ORDER BY ").append(field).append(" ").append(ord); break; }// w w w.j av a 2 s .c om } return rs.toString(); }