List of usage examples for java.util Map remove
V remove(Object key);
From source file:expansionBlocks.ProcessCommunities.java
public static Pair<Map<Entity, Double>, Map<Entity, Double>> execute(Configuration configuration, Query query) throws Exception { Map<Set<Long>, Map<Entity, Double>> mapPathCommunities = query.getCommunities(); HashSet<Map<Entity, Double>> initialCommunities = new HashSet<>(mapPathCommunities.values()); Set<Map<Entity, Double>> scaledCommunities = new HashSet<>(); AbstractCommunityScalator as = configuration.getAbstractCommunityScalator(); for (Map<Entity, Double> community : initialCommunities) { Map<Entity, Double> scaledCommunity = as.scaledEmphasisArticlesInCommunity(configuration, query, community);//from w ww . ja va 2 s .c o m scaledCommunities.add(scaledCommunity); } Set<Map<Entity, Double>> communitiesFusioned = getCommunitiesFromCommunitiesBasedOnSimilarity( scaledCommunities, configuration.getFusionThreshold()); if (configuration.DEBUG_INFO) { println("Fusion communities based on similarity communities: "); for (Map<Entity, Double> community : communitiesFusioned) { println(community); } } println(initialCommunities.size() + " communities have been fusioned into " + communitiesFusioned.size()); println("[[WARNING]] - Select best community algorithm seems to differ from select best path. You may want to double ckeck it."); Set<Map<Entity, Double>> selectBestCommunities = selectBestCommunities(configuration, communitiesFusioned, query.getTokenNames()); if (configuration.DEBUG_INFO) { println("Selected best communities: "); for (Map<Entity, Double> community : selectBestCommunities) { println(StringUtilsQueryExpansion.MapDoubleValueToString(community)); } } Map<Entity, Double> result = agregateCommunities(selectBestCommunities); if (configuration.DEBUG_INFO) { println("Agragated community(size: " + result.size() + "): "); println(StringUtilsQueryExpansion.MapDoubleValueToString(result)); } Set<Entity> entitiesToRemove = new HashSet<>(); /*for (Map.Entry<Entity, Double> e : result.entrySet()) { Set<Category> categories = e.getKey().getCategories(); println("Categories of \"" + e.getKey() + "\": " + categories); if (categories.isEmpty()) entitiesToRemove.add(e.getKey()); }*/ entitiesToRemove.addAll(removableAccordingToCategories(result)); Map<Entity, Double> filteredCommunity = new HashMap<>(result); for (Entity e : entitiesToRemove) { filteredCommunity.remove(e); } println("Based on category analisy I would suggest to remove: " + entitiesToRemove); println("New Community in case of category based filtering" + StringUtilsQueryExpansion.MapDoubleValueToString(filteredCommunity)); query.setCommunityAfterRemoval(filteredCommunity); query.setCommunity(result); return new Pair<>(result, filteredCommunity); }
From source file:com.example.soaplegacy.XmlUtils.java
public static String removeUnneccessaryNamespaces(String xml) { if (StringUtils.isBlank(xml)) { return xml; }//from ww w . ja va 2 s . c om XmlObject xmlObject = null; XmlCursor cursor = null; try { xmlObject = XmlObject.Factory.parse(xml); cursor = xmlObject.newCursor(); while (cursor.currentTokenType() != XmlCursor.TokenType.START && cursor.currentTokenType() != XmlCursor.TokenType.ENDDOC) { cursor.toNextToken(); } if (cursor.currentTokenType() == XmlCursor.TokenType.START) { Map<?, ?> nsMap = new HashMap<Object, Object>(); cursor.getAllNamespaces(nsMap); nsMap.remove(cursor.getDomNode().getPrefix()); NamedNodeMap attributes = cursor.getDomNode().getAttributes(); for (int c = 0; attributes != null && c < attributes.getLength(); c++) { nsMap.remove(attributes.item(c).getPrefix()); } if (cursor.toFirstChild()) { while (cursor.getDomNode() != xmlObject.getDomNode()) { attributes = cursor.getDomNode().getAttributes(); for (int c = 0; attributes != null && c < attributes.getLength(); c++) { nsMap.remove(attributes.item(c).getPrefix()); } nsMap.remove(cursor.getDomNode().getPrefix()); cursor.toNextToken(); } } xml = xmlObject.xmlText( new XmlOptions().setSaveOuter().setSavePrettyPrint().setSaveImplicitNamespaces(nsMap)); } } catch (XmlException e) { } finally { if (cursor != null) cursor.dispose(); } return xml; }
From source file:com.ctriposs.r2.transport.http.client.HttpClientFactory.java
private static <T> T coerceAndRemoveFromMap(String key, Map<String, ?> props, Class<T> valueClass) { return coerce(key, props.remove(key), valueClass); }
From source file:org.opencb.commons.datastore.mongodb.GenericDocumentComplexConverter.java
/** * For each element in the document, applies a mapper {@link Function} to the key. * * Goes over all the elements in the document recursively. * * @param object Object to modify * @param keyMapper Key mapper//from w w w .ja v a 2 s .c o m * @param toReplace String to be replaced * @param <T> Type of the input object. * @return The modified object. */ protected static <T> T modifyKeys(T object, Function<String, String> keyMapper, String toReplace) { if (object instanceof Map) { Map<String, Object> document = (Map<String, Object>) object; List<String> keysWithDots = new LinkedList<>(); for (Map.Entry<String, Object> entry : document.entrySet()) { if (entry.getKey().contains(toReplace)) { keysWithDots.add(entry.getKey()); } modifyKeys(entry.getValue(), keyMapper, toReplace); } for (String key : keysWithDots) { Object o = document.remove(key); document.put(keyMapper.apply(key), o); } } else if (object instanceof Collection) { Collection collection = (Collection) object; for (Object o : collection) { modifyKeys(o, keyMapper, toReplace); } } return object; }
From source file:com.silverpeas.util.MapUtil.java
public static <K, V> boolean equals(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) { Map<K, V> onlyOnRight = new HashMap<K, V>(right); for (Map.Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey();//from w w w. j av a 2 s . c o m V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (!ObjectUtils.equals(leftValue, rightValue)) { return false; } } else { return false; } } return onlyOnRight.isEmpty(); }
From source file:com.centurylink.mdw.services.util.AuthUtils.java
public static boolean authenticate(String authMethod, Map<String, String> headers, String payload) { // avoid any fishiness -- only we should populate this header headers.remove(Listener.AUTHENTICATED_USER_HEADER); if (authMethod.equals(AUTHORIZATION_HEADER_AUTHENTICATION)) { return authenticateAuthorizationHeader(headers); } else if (authMethod.equals(GIT_HUB_SECRET_KEY)) { return authenticateGitHubSecretKey(headers, payload); } else if (authMethod.equals(SLACK_TOKEN)) { return authenticateSlackToken(headers, payload); } else if (authMethod.equals(MDW_APP_TOKEN)) { return authenticateMdwAppToken(headers, payload); } else {// ww w . j a v a 2 s . c om throw new IllegalArgumentException("Unsupported authentication method: " + authMethod); } }
From source file:com.alibaba.jstorm.ui.UIUtils.java
public static ColumnData getConnectionColumnData(Map<String, String> paramMap, String connectionName) { ColumnData columnData = new ColumnData(); LinkData linkData = new LinkData(); columnData.addLinkData(linkData);/*from w w w . ja v a 2 s . c om*/ linkData.setUrl(UIDef.LINK_WINDOW_TABLE); linkData.setText(connectionName); Map<String, String> linkDataParam = new HashMap<String, String>(); linkData.setParamMap(linkDataParam); linkDataParam.putAll(paramMap); linkDataParam.remove(UIDef.POS); try { int pos = connectionName.indexOf(":"); if (pos > 0) { String source = connectionName.substring(0, pos); linkDataParam.put(UIDef.HOST, source); } } catch (Exception e) { } return columnData; }
From source file:Main.java
/** * Removes the value from the set of values mapped by key. If this value was the last value in the set of values * mapped by key, the complete key/values entry is removed. * /*from www . j a v a2s .c o m*/ * @param key * The key for which to remove a value. * @param value * The value for which to remove the key. * @param map * The object that maps the key to a set of values, on which the operation should occur. */ public static <K, V> void deleteAndRemove(final K key, final V value, final Map<K, Set<V>> map) { if (key == null) { throw new IllegalArgumentException("Argument 'key' cannot be null."); } if (value == null) { throw new IllegalArgumentException("Argument 'value' cannot be null."); } if (map == null) { throw new IllegalArgumentException("Argument 'map' cannot be null."); } if (map.isEmpty() || !map.containsKey(key)) { return; } final Set<V> values = map.get(key); values.remove(value); if (values.isEmpty()) { map.remove(key); } }
From source file:com.espertech.esper.core.start.EPStatementStartMethodCreateTable.java
private static EventType validateExpressionGetEventType(String msgprefix, List<AnnotationDesc> annotations, EventAdapterService eventAdapterService) throws ExprValidationException { Map<String, List<AnnotationDesc>> annos = AnnotationUtil.mapByNameLowerCase(annotations); // check annotations used List<AnnotationDesc> typeAnnos = annos.remove("type"); if (!annos.isEmpty()) { throw new ExprValidationException( msgprefix + " unrecognized annotation '" + annos.keySet().iterator().next() + "'"); }/*from ww w .java 2 s .c o m*/ // type determination EventType optionalType = null; if (typeAnnos != null) { String typeName = AnnotationUtil.getExpectSingleStringValue(msgprefix, typeAnnos); optionalType = eventAdapterService.getExistsTypeByName(typeName); if (optionalType == null) { throw new ExprValidationException(msgprefix + " failed to find event type '" + typeName + "'"); } } return optionalType; }
From source file:com.espertech.esper.epl.parse.ASTContextHelper.java
private static ContextDetailCondition getContextCondition(Tree parent, Map<Tree, ExprNode> astExprNodeMap, Map<Tree, EvalFactoryNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec, boolean immediate) { if (parent.getType() == EsperEPL2Ast.CRONTAB_LIMIT_EXPR_PARAM) { List<ExprNode> crontab = ASTExprHelper.getRemoveAllChildExpr(parent, astExprNodeMap); return new ContextDetailConditionCrontab(crontab, immediate); } else if (parent.getType() == EsperEPL2Ast.CREATE_CTX_PATTERN) { EvalFactoryNode evalNode = astPatternNodeMap.remove(parent.getChild(0).getChild(0)); boolean inclusive = false; if (parent.getChildCount() > 1) { String ident = parent.getChild(1).getText(); if (ident != null && !ident.toLowerCase().equals("inclusive")) { throw new ASTWalkException( "Expected 'inclusive' keyword after '@', found '" + ident + "' instead"); }/* w w w. j a v a 2 s .c o m*/ inclusive = true; } return new ContextDetailConditionPattern(evalNode, inclusive, immediate); } else if (parent.getType() == EsperEPL2Ast.STREAM_EXPR) { FilterSpecRaw filterSpecRaw = ASTExprHelper.walkFilterSpec(parent.getChild(0), propertyEvalSpec, astExprNodeMap); String asName = parent.getChildCount() > 1 ? parent.getChild(1).getText() : null; if (immediate) { throw new ASTWalkException( "Invalid use of 'now' with initiated-by stream, this combination is not supported"); } return new ContextDetailConditionFilter(filterSpecRaw, asName); } else if (parent.getType() == EsperEPL2Ast.AFTER) { ExprTimePeriod timePeriod = (ExprTimePeriod) astExprNodeMap.remove(parent.getChild(0)); return new ContextDetailConditionTimePeriod(timePeriod, immediate); } else { throw new IllegalStateException("Unrecognized child type " + parent.getType()); } }