List of usage examples for java.util Map remove
V remove(Object key);
From source file:com.omertron.rottentomatoesapi.tools.ApiBuilder.java
/** * Get and process the URL from the properties map * * @param properties//from w w w . j a va 2 s .c om * @return The processed URL * @throws RottenTomatoesException */ private static String getUrlFromProps(Map<String, String> properties) throws RottenTomatoesException { if (properties.containsKey(PROPERTY_URL) && StringUtils.isNotBlank(properties.get(PROPERTY_URL))) { String url = properties.get(PROPERTY_URL); // If we have the ID, then we need to replace the "{movie-id}" in the URL if (properties.containsKey(PROPERTY_ID) && StringUtils.isNotBlank(properties.get(PROPERTY_ID))) { url = url.replace(MOVIE_ID, String.valueOf(properties.get(PROPERTY_ID))); // We don't need this property anymore properties.remove(PROPERTY_ID); } // We don't need this property anymore properties.remove(PROPERTY_URL); return url; } else { throw new RottenTomatoesException(ApiExceptionType.INVALID_URL, "No URL specified"); } }
From source file:net.sf.jabref.exporter.FileActions.java
private static void writeString(Writer fw, BibtexString bs, Map<String, BibtexString> remaining, int maxKeyLength) throws IOException { // First remove this from the "remaining" list so it can't cause problem with circular refs: remaining.remove(bs.getName()); //if the string has not been modified, write it back as it was if (!bs.hasChanged()) { fw.write(bs.getParsedSerialization()); return;//from w w w . j a v a 2 s . co m } // Then we go through the string looking for references to other strings. If we find references // to strings that we will write, but still haven't, we write those before proceeding. This ensures // that the string order will be acceptable for BibTeX. String content = bs.getContent(); Matcher m; while ((m = FileActions.REFERENCE_PATTERN.matcher(content)).find()) { String foundLabel = m.group(1); int restIndex = content.indexOf(foundLabel) + foundLabel.length(); content = content.substring(restIndex); Object referred = remaining.get(foundLabel.substring(1, foundLabel.length() - 1)); // If the label we found exists as a key in the "remaining" Map, we go on and write it now: if (referred != null) { FileActions.writeString(fw, (BibtexString) referred, remaining, maxKeyLength); } } if (FileActions.previousStringType != bs.getType()) { fw.write(Globals.NEWLINE); FileActions.previousStringType = bs.getType(); } StringBuilder suffixSB = new StringBuilder(); for (int i = maxKeyLength - bs.getName().length(); i > 0; i--) { suffixSB.append(' '); } String suffix = suffixSB.toString(); fw.write("@String { " + bs.getName() + suffix + " = "); if (!bs.getContent().isEmpty()) { try { String formatted = new LatexFieldFormatter().format(bs.getContent(), LatexFieldFormatter.BIBTEX_STRING); fw.write(formatted); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException( "The # character is not allowed in BibTeX strings unless escaped as in '\\#'.\n" + "Before saving, please edit any strings containing the # character."); } } else { fw.write("{}"); } fw.write(" }" + Globals.NEWLINE); }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static Path takeFsPath(DirectDataSourceProfile profile, Map<String, String> attributes, Configuration conf) {/*ww w . j ava2s .co m*/ assert conf != null; assert attributes != null; String fsPathString = attributes.remove(KEY_PATH); if (fsPathString != null) { return new Path(fsPathString); } return null; }
From source file:de.escidoc.core.aa.business.cache.PoliciesCache.java
/** * Removes all data stored in the cache for the role identified by the provided role id from the cache.<br> Has to * be called whenever the role changes or has been deleted. * * @param roleId The id of the role to remove from the cache. * @throws SystemException e/*from ww w.java 2 s. c om*/ */ public static void clearRole(final String roleId) throws SystemException { try { getRolePoliciesCache().remove(new URI(roleId)); } catch (final URISyntaxException e) { throw new SystemException(e); } // FIXME: roles may be cached by name, not id. As a quick fix, the // cache is completely cleared. This should be optimized getRolesCache().removeAll(); // The user policies cache still holds policies for the removed role. // To avoid usage of invalidated roles, the caches are cleared. getUserPoliciesCache().removeAll(); // iterate over all maps stored in roleIsGrantedCache to remove the ones // relevant for the provided role id. final List roleIsGrantedKeys = getRoleIsGrantedCache().getKeys(); final List<Map<String, Map<String, EvaluationResult>>> roleIsGrantedValues = new ArrayList<Map<String, Map<String, EvaluationResult>>>(); for (final Object key : roleIsGrantedKeys) { final Element element = getRoleIsGrantedCache().get(key); if (element != null) { roleIsGrantedValues.add((Map<String, Map<String, EvaluationResult>>) element.getObjectValue()); } } for (final Map<String, Map<String, EvaluationResult>> userCache : roleIsGrantedValues) { userCache.remove(roleId); } }
From source file:com.onehippo.gogreen.login.HstConcurrentLoginFilter.java
static void unregisterUserSession(HttpSession session) { String username = (String) session.getAttribute(USERNAME_ATTR); log.debug("HstConcurrentLoginFilter will unregister session for {}", username); if (username == null) { return;//w ww .ja va 2 s . c om } ServletContext servletContext = session.getServletContext(); @SuppressWarnings("unchecked") Map<String, HttpSessionWrapper> map = (Map<String, HttpSessionWrapper>) servletContext .getAttribute(USERNAME_SESSIONID_MAP_ATTR); if (map != null) { HttpSessionWrapper oldHttpSessionWrapper = null; synchronized (map) { oldHttpSessionWrapper = map.get(username); if (oldHttpSessionWrapper != null) { if (oldHttpSessionWrapper.equalsTo(session)) { map.remove(username); log.debug("HstConcurrentLoginFilter kicked out session ({}) for {}.", oldHttpSessionWrapper.getId(), username); } else { log.debug( "HstConcurrentLoginFilter didn't kick out session ({}) for {} because it's logged on by other http session.", oldHttpSessionWrapper.getId(), username); } } } } else { log.error("HstConcurrentLoginFilter is in invalid state. The session ids map is not found."); } session.removeAttribute(USERNAME_ATTR); log.debug("HstConcurrentLoginFilter removed user name session attribute: {}", username); }
From source file:com.splicemachine.db.impl.ast.PlanPrinter.java
public static Map prune(Map m) { List<Object> toPrune = new LinkedList<>(); for (Map.Entry e : (Set<Map.Entry<Object, Object>>) m.entrySet()) { Object val = e.getValue(); if (val == null || (val instanceof List && ((List) val).size() == 0)) { toPrune.add(e.getKey());//from w w w . j a v a 2 s. com } } for (Object k : toPrune) { m.remove(k); } return m; }
From source file:net.sourceforge.jaulp.lang.ObjectUtils.java
/** * Compares the given object over the given property quietly. * /*from w w w . ja v a 2 s .c om*/ * @param sourceOjbect * the source ojbect * @param objectToCompare * the object to compare * @param property * the property * @return the int */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static int compareToQuietly(Object sourceOjbect, Object objectToCompare, String property) { Map<?, ?> beanDescription = null; try { beanDescription = BeanUtils.describe(sourceOjbect); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { logger.error("BeanUtils.describe(sourceOjbect) throws an exception...", e); return 0; } beanDescription.remove("class"); Map<?, ?> clonedBeanDescription = null; try { clonedBeanDescription = BeanUtils.describe(objectToCompare); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { logger.error("BeanUtils.describe(objectToCompare) throws an exception...", e); return 0; } clonedBeanDescription.remove("class"); Object sourceAttribute = beanDescription.get(property); Object changedAttribute = clonedBeanDescription.get(property); if (sourceAttribute == null && changedAttribute == null) { return 0; } if (sourceAttribute != null && changedAttribute == null) { return 1; } else if (sourceAttribute == null && changedAttribute != null) { return -1; } return new BeanComparator(property).compare(sourceOjbect, objectToCompare); }
From source file:AntColonyPDP.Environment.java
private static void performanceAssessment(final Simulator simulator, final RoadModel roadModel) { if ((simulator.getCurrentTime() % (3600000 * 20)) == 0 && simulator.getCurrentTime() > 0) { System.out.println(/*from ww w . j av a2 s. com*/ "expired food sources: " + getExpiredSourceCount() + ", elements: " + getExpiredElementCount()); System.out.println("succesfulDeliveries: " + getDeliveryCount()); double antCount = ((double) getDeliveryCount()) / ((double) NUM_ANTS); System.out.println("ant efficiency: " + antCount); System.out.println("per simulation minute: " + antCount / (simulator.getCurrentTime() / 3600000)); Map<RoadUser, Point> debug = roadModel.getObjectsAndPositions(); for (RoadUser ru : new HashSet<RoadUser>(debug.keySet())) { if (ru instanceof Ant) debug.remove(ru); else if (ru instanceof Colony) debug.remove(ru); else if (ru instanceof FoodElement && (simulator.getModelProvider().getModel(DefaultPDPModel.class) .getParcelState((FoodElement) ru)).equals(ParcelState.DELIVERED)) debug.remove(ru); // else System.out.print(((FoodSource) ru).getPickupLocation()); } } }
From source file:com.screenslicer.webapp.ScreenSlicerClient.java
@Path("configure") @POST/*from www . ja va2 s .c om*/ @Produces("application/json") @Consumes("application/json") public static final Response configure(String reqString) { try { if (reqString != null) { final String reqDecoded = Crypto.decode(reqString, CommonUtil.ip()); if (reqDecoded != null) { final Map<String, Object> args = CommonUtil.gson.fromJson(reqDecoded, CommonUtil.objectType); final Request request = CommonUtil.gson.fromJson(reqDecoded, Request.class); Field[] fields = request.getClass().getFields(); for (Field field : fields) { args.remove(field.getName()); } Map<String, Object> conf = customApp.configure(request, args); if (conf != null) { return Response.ok( Crypto.encode(CommonUtil.gson.toJson(conf, CommonUtil.objectType), CommonUtil.ip())) .build(); } } } } catch (Exception e) { Log.exception(e); } return null; }
From source file:de.alpharogroup.lang.ObjectExtensions.java
/** * Compares the given object over the given property quietly. * * @param sourceOjbect/*from w w w. ja v a 2 s. c o m*/ * the source ojbect * @param objectToCompare * the object to compare * @param property * the property * @return the int */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static int compareToQuietly(final Object sourceOjbect, final Object objectToCompare, final String property) { Map<?, ?> beanDescription = null; try { beanDescription = BeanUtils.describe(sourceOjbect); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { logger.error("BeanUtils.describe(sourceOjbect) throws an exception...", e); return 0; } beanDescription.remove("class"); Map<?, ?> clonedBeanDescription = null; try { clonedBeanDescription = BeanUtils.describe(objectToCompare); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { logger.error("BeanUtils.describe(objectToCompare) throws an exception...", e); return 0; } clonedBeanDescription.remove("class"); final Object sourceAttribute = beanDescription.get(property); final Object changedAttribute = clonedBeanDescription.get(property); if (sourceAttribute == null && changedAttribute == null) { return 0; } if (sourceAttribute != null && changedAttribute == null) { return 1; } else if (sourceAttribute == null && changedAttribute != null) { return -1; } return new BeanComparator(property).compare(sourceOjbect, objectToCompare); }