List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:gate.termraider.util.Utilities.java
public static void setScoreTermValue(Map<ScoreType, Map<Term, Number>> map, ScoreType type, Term term, Number value) {//from w ww .jav a 2 s . c om Map<Term, Number> submap; if (map.containsKey(type)) { submap = map.get(type); } else { submap = new HashMap<Term, Number>(); } submap.put(term, value); map.put(type, submap); }
From source file:com.github.dynamo.torrent.parser.TorrentProcessor.java
/** * Given a Map, retrieve all useful information and represent it as a TorrentFile object * @param m Map/*w w w . j a va 2 s . c om*/ * @return TorrentFile */ private static TorrentFile getTorrentFile(Map m) { if (m == null) return null; TorrentFile torrent = new TorrentFile(); if (m.containsKey("announce")) // mandatory key torrent.announceURL = new String((byte[]) m.get("announce")); else return null; if (m.containsKey("comment")) // optional key torrent.comment = new String((byte[]) m.get("comment")); if (m.containsKey("created by")) // optional key torrent.createdBy = new String((byte[]) m.get("created by")); if (m.containsKey("creation date")) // optional key torrent.creationDate = (Long) m.get("creation date"); if (m.containsKey("encoding")) // optional key torrent.encoding = new String((byte[]) m.get("encoding")); //Store the info field data if (!m.containsKey("info")) { return null; } Map info = (Map) m.get("info"); try { torrent.info_hash_as_binary = TorrentUtils.hash(BEncoder.encode(info)); torrent.info_hash_as_hex = TorrentUtils.byteArrayToByteString(torrent.info_hash_as_binary); torrent.info_hash_as_url = TorrentUtils.byteArrayToURLString(torrent.info_hash_as_binary); } catch (IOException ioe) { return null; } if (info.containsKey("name")) torrent.saveAs = new String((byte[]) info.get("name")); if (info.containsKey("piece length")) torrent.pieceLength = ((Long) info.get("piece length")).intValue(); else return null; if (info.containsKey("pieces")) { byte[] piecesHash2 = (byte[]) info.get("pieces"); if (piecesHash2.length % 20 != 0) return null; for (int i = 0; i < piecesHash2.length / 20; i++) { byte[] temp = TorrentUtils.subArray(piecesHash2, i * 20, 20); torrent.piece_hash_values_as_binary.add(temp); torrent.piece_hash_values_as_hex.add(TorrentUtils.byteArrayToByteString(temp)); torrent.piece_hash_values_as_url.add(TorrentUtils.byteArrayToURLString(temp)); } } else return null; if (info.containsKey("files")) { List<Map> multFiles = (List<Map>) info.get("files"); torrent.total_length = 0; for (int i = 0; i < multFiles.size(); i++) { Map currentFile = multFiles.get(i); Long length = (Long) currentFile.get("length"); torrent.length.add(length); torrent.total_length += length.intValue(); List path = (List) currentFile.get("path"); String filePath = ""; for (int j = 0; j < path.size(); j++) { if (StringUtils.isNotEmpty(filePath)) { filePath += "/"; } filePath += new String((byte[]) path.get(j)); } torrent.fileNames.add(filePath); } } else { torrent.length.add((Long) info.get("length")); torrent.total_length = (Long) info.get("length"); torrent.fileNames.add(new String((byte[]) info.get("name"))); } return torrent; }
From source file:com.sun.faces.renderkit.html_basic.FormRenderer.java
/** * <p>Remember that we will need a new hidden field.</p> *///from www.j a v a 2s. c o m public static void addNeededHiddenField(FacesContext context, String clientId) { Map map = getHiddenFieldMap(context, true); if (!map.containsKey(clientId)) { map.put(clientId, Boolean.TRUE); } }
From source file:com.blackbear.flatworm.Util.java
/** * Conversion-Option now stored in class, more than a simple Hashmap lookup * /*from w w w.j a v a 2 s . c o m*/ * @param options * The conversion-option values for the field * @param key * The key to lookup appropriate ConversionOption * * @return The string that contains value of the ConversionOption */ public static String getValue(Map<String, ConversionOption> options, String key) { if (options.containsKey(key)) { return options.get(key).getValue(); } else { return null; } }
From source file:com.thoughtworks.go.http.mocks.HttpRequestBuilder.java
private static Map<String, List<String>> splitQuery(URIBuilder builder) { Map<String, List<String>> params = new LinkedHashMap<>(); for (NameValuePair nameValuePair : builder.getQueryParams()) { if (!params.containsKey(nameValuePair.getName())) { params.put(nameValuePair.getName(), new ArrayList<>()); }//from w ww . j a va2s .c om params.get(nameValuePair.getName()).add(nameValuePair.getValue()); } return params; }
From source file:com.kuba.skateagramclient.domain.Link.java
/** * Factory method to easily create {@link Link} instances from RFC-5988 compatible {@link String} representations of a * link. Will return {@literal null} if an empty or {@literal null} {@link String} is given. * * @param element an RFC-5899 compatible representation of a link. * @throws IllegalArgumentException if a non-empty {@link String} was given that does not adhere to RFC-5899. * @throws IllegalArgumentException if no {@code rel} attribute could be found. * @return/*from w w w . j a v a 2s .c o m*/ */ public static Link valueOf(String element) { if (!StringUtils.hasText(element)) { return null; } Pattern uriAndAttributes = Pattern.compile("<(.*)>;(.*)"); Matcher matcher = uriAndAttributes.matcher(element); if (matcher.find()) { Map<String, String> attributes = getAttributeMap(matcher.group(2)); if (!attributes.containsKey("rel")) { throw new IllegalArgumentException("Link does not provide a rel attribute!"); } return new Link(matcher.group(1), attributes.get("rel")); } else { throw new IllegalArgumentException( String.format("Given link header %s is not RFC5988 compliant!", element)); } }
From source file:org.calrissian.restdoclet.writer.swagger.SwaggerWriter.java
private static Map<String, Collection<Endpoint>> groupPaths(Collection<Endpoint> endpoints) { Map<String, Collection<Endpoint>> paths = new LinkedHashMap<String, Collection<Endpoint>>(); for (Endpoint endpoint : endpoints) { if (paths.containsKey(endpoint.getPath())) { paths.get(endpoint.getPath()).add(endpoint); } else {/*from www. java 2 s.com*/ Collection<Endpoint> tmp = new ArrayList<Endpoint>(); tmp.add(endpoint); paths.put(endpoint.getPath(), tmp); } } return paths; }
From source file:grails.plugin.searchable.internal.compass.support.SearchableMethodUtils.java
/** * Get the options Map from the given argument array * @param args the given array of arguments, may not be null, may be empty * @param defaultOptions the default options, to be merged with user options, may be null * @param overrideWithDefaultsIfNull an array of keys which if null in the given options * are overriden with defaults// w w w .j ava 2 s .co m * @return a Map of options, never null */ public static Map getOptionsArgument(Object[] args, Map defaultOptions, String[] overrideWithDefaultsIfNull) { Map options = getOptionsArgument(args, defaultOptions); if (overrideWithDefaultsIfNull != null) { for (int i = 0; i < overrideWithDefaultsIfNull.length; i++) { String key = overrideWithDefaultsIfNull[i]; if (options.containsKey(key) && options.get(key) == null) { options.put(key, defaultOptions.get(key)); } } } return options; }
From source file:com.link_intersystems.util.UtilFacade.java
/** * Takes a collection of objects and builds a map that maps object's keys to * objects. The object keys are calculated via a * {@link ParameterizedObjectFactory}. The * {@link ParameterizedObjectFactory} must ensure that a distinct key for * every object instance in the collection is generated. If there are two * instances that have the same key (in order to the key calculation * algorithm) a {@link KeyCollisionException} is thrown. * * @param <K>/*w w w.j av a 2 s . c o m*/ * the key's type * @param <V> * the value's type * @param objects * the {@link Collection} of objects the key map should be * generated of. * @param keyObjectFactory * the {@link ParameterizedObjectFactory} to use for creating the * keys. * @return a map that maps the keys generated by the * {@link ParameterizedObjectFactory} to the objects of the original * collection. * @throws KeyCollisionException * if the collection contains two objects that are equal in * their key which is generated by the * {@link ParameterizedObjectFactory}. * @since 1.0.0.0 */ public static <KEY, VALUE> Map<KEY, VALUE> keyMap(Collection<VALUE> objects, ParameterizedObjectFactory<KEY, VALUE> keyObjectFactory) throws KeyCollisionException { Map<KEY, VALUE> map = new HashMap<KEY, VALUE>((int) (objects.size() * HASH_MAP_LOAD_FACTOR)); for (VALUE v : objects) { KEY k = keyObjectFactory.getObject(v); if (map.containsKey(k)) { throw new KeyCollisionException(k); } else { map.put(k, v); } } return map; }
From source file:com.streamsets.pipeline.lib.io.LiveFile.java
/** * Deserializes a string representation of a <code>LiveFile</code>. * <p>/*from w ww. j a va 2 s . c o m*/ * * @param str the string representation of a <code>LiveFile</code>. * @return the deserialized <code>LiveFile</code> * @throws IOException thrown if the string con not be deserialized into a <code>LiveFile</code>. */ public static LiveFile deserialize(String str) throws IOException { Utils.checkNotNull(str, "str"); try { Map map = OBJECT_MAPPER.readValue(str, Map.class); Path path = Paths.get((String) map.get("path")); String headHash = (map.containsKey("headHash")) ? (String) map.get("headHash") : ""; int headLen = (map.containsKey("headLen")) ? (int) map.get("headLen") : 0; String inode = (String) map.get("inode"); return new LiveFile(path, inode, headHash, headLen); } catch (RuntimeException | JsonParseException ex) { throw new IllegalArgumentException( Utils.format("Invalid LiveFile serialized string '{}': {}", str, ex.toString()), ex); } }