List of usage examples for java.util Map size
int size();
From source file:Main.java
public static String join(Map<?, ?> map, char separator, char valueStartChar, char valueEndChar) { if (map == null) { return null; }/*from w w w . j a v a 2s.c om*/ if (map.size() == 0) { return EMPTY; } StringBuilder buf = new StringBuilder(256); boolean isFirst = true; for (Entry<?, ?> entry : map.entrySet()) { if (isFirst) { buf.append(entry.getKey()); buf.append(valueStartChar); buf.append(entry.getValue()); buf.append(valueEndChar); isFirst = false; } else { buf.append(separator); buf.append(entry.getKey()); buf.append(valueStartChar); buf.append(entry.getValue()); buf.append(valueEndChar); } } return buf.toString(); }
From source file:Main.java
/** * Copies the entries from <code>source</code> to <code>dest1</code> until * <code>dest1</code> has reached size <code>dest1Capacity</code>. The * remaining entries are saved in <code>overflow</code>. The order of * insertion depends on the iterator of the underlying map. Note that as * <code>dest1</code> is a map, inserting an entry with a key that already * exists in the map does not increase its size (if the insertion is * permitted)./* w w w. ja va2 s . c o m*/ * * @param <T> * the key type. * @param <U> * the entry/value type. * @param source * the mappings to be copied. * @param dest1 * the first destination for the entries, to be filled until its * size reaches dest1Capacity. * @param overflow * destination for the remaining entries. * @param dest1Capacity * maximum allowed size for dest1. */ public static <T, U> void copyUntilFull(final Map<? extends T, ? extends U> source, final Map<? super T, ? super U> dest1, Map<T, U> overflow, final int dest1Capacity) { for (final Map.Entry<? extends T, ? extends U> srcEntry : source.entrySet()) { if (dest1.size() < dest1Capacity) { dest1.put(srcEntry.getKey(), srcEntry.getValue()); } else { overflow.put(srcEntry.getKey(), srcEntry.getValue()); } } }
From source file:Main.java
public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; }/*w w w. j a v a 2 s . c om*/ List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; }
From source file:com.alibaba.dragoon.patrol.kv.PassiveSender.java
/** * ?????// ww w .ja v a 2 s .co m * * @param kvMap */ private static boolean hasExceedDataSize(Map<String, Object> data) { if (data.size() > ALLOW_DATA_SIZE_MAX) { return true; } return false; }
From source file:Main.java
public static List<String> join(final Map<String, String> map, final String separator) { if (map == null) { return null; }/*w w w . j a va2 s.co m*/ final List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (final Map.Entry<String, String> entry : map.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; }
From source file:com.espertech.esper.epl.join.assemble.AssemblyStrategyTreeBuilder.java
/** * Builds a tree of {@link BaseAssemblyNode} from join strategy information. * @param rootStream - the root stream supplying the event to evaluate * @param streamsJoinedPerStream - a map in which the key is the stream number to supply an event, * and the value is an array of streams to find events in for the given event * @param isRequiredPerStream - indicates which streams are required join streams versus optional streams * @return root assembly node//from w w w . j a v a2 s. c o m */ public static BaseAssemblyNode build(int rootStream, Map<Integer, int[]> streamsJoinedPerStream, boolean isRequiredPerStream[]) { if (streamsJoinedPerStream.size() < 3) { throw new IllegalArgumentException("Not a 3-way join"); } if ((rootStream < 0) || (rootStream >= streamsJoinedPerStream.size())) { throw new IllegalArgumentException("Invalid root stream"); } if (isRequiredPerStream.length != streamsJoinedPerStream.size()) { throw new IllegalArgumentException("Arrays not matching up"); } NStreamOuterQueryPlanBuilder.verifyJoinedPerStream(rootStream, streamsJoinedPerStream); if (log.isDebugEnabled()) { log.debug(".build Building node for root stream " + rootStream + " streamsJoinedPerStream=" + NStreamOuterQueryPlanBuilder.print(streamsJoinedPerStream) + " isRequiredPerStream=" + Arrays.toString(isRequiredPerStream)); } BaseAssemblyNode topNode = createNode(true, rootStream, streamsJoinedPerStream.size(), streamsJoinedPerStream.get(rootStream), isRequiredPerStream); recursiveBuild(rootStream, topNode, streamsJoinedPerStream, isRequiredPerStream); if (log.isDebugEnabled()) { StringWriter buf = new StringWriter(); PrintWriter print = new PrintWriter(buf); IndentWriter indentWriter = new IndentWriter(print, 0, 2); topNode.printDescendends(indentWriter); log.debug(".build Dumping root node for stream " + rootStream + ": \n" + buf.toString()); } return topNode; }
From source file:net.metanotion.web.html.Tag.java
public static Iterator<Object> writeTag(String tagName, Map<String, Object> attributes, boolean selfClose) { final ArrayList<Object> t = new ArrayList<>((attributes.size() * 5) + 2); t.add("<" + tagName); for (final Map.Entry<String, Object> e : attributes.entrySet()) { t.add(" "); t.add(e.getKey());/* w w w .j a va 2 s . com*/ final Object val = e.getValue(); if (val != null) { t.add("=\""); t.add(StringEscapeUtils.escapeHtml4(val.toString())); t.add("\""); } } t.add(selfClose ? "/>" : ">"); return t.iterator(); }
From source file:org.ambraproject.wombat.controller.ArticleAssetController.java
/** * Handle a file request where the supplied file type could not be matched to any files for an existing item. If * possible, resolve to another file to serve instead. Else, throw an appropriate exception. */// w w w . ja v a 2 s . co m private static Map<String, ?> handleUnmatchedFileType(RequestedDoiVersion id, String itemType, String fileType, Map<String, ?> files) { if (files.size() == 1 && ITEM_TYPES_TO_TOLERATE.containsEntry(itemType, fileType)) { Map.Entry<String, ?> onlyEntry = Iterables.getOnlyElement(files.entrySet()); log.warn(String.format("On %s (%s), received request for %s; only available file is %s", id, itemType, fileType, onlyEntry.getKey())); return (Map<String, ?>) onlyEntry.getValue(); } String message = String.format("Unrecognized file type (\"%s\") for id: %s", fileType, id); throw new NotFoundException(message); }
From source file:Main.java
/** * join the string tuple with the separator char sequence. * if the value of map is null ,just store the key. * @param map/*w ww .ja v a 2 s . c o m*/ * the key,value tuple. * @param separator * the join string * @return * the joined string list. */ public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; } List<String> result = new ArrayList<String>(); if (map == null || map.size() == 0) { return result; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { result.add(key); } else { result.add(key + separator + value); } } return result; }
From source file:com.oplay.nohelper.volley.toolbox.JsonRequest.java
public static String getParamsString(Map<String, String> params) { try {/*from w w w .j a va 2 s .c om*/ if (params == null || params.size() == 0) { return ""; } final Iterator<String> keySet = params.keySet().iterator(); final StringBuilder sb = new StringBuilder(); while (keySet.hasNext()) { final String key = keySet.next(); final String val = params.get(key); if (val != null) { sb.append(key).append("=").append(URLEncoder.encode(val, HTTP.UTF_8)); if (keySet.hasNext()) { sb.append("&"); } } } return sb.toString(); } catch (Throwable e) { } return ""; }