List of usage examples for java.util List containsAll
boolean containsAll(Collection<?> c);
From source file:kr.co.bitnine.octopus.sql.OctopusSqlTest.java
private static <E> Matcher<List<E>> listEqualTo(final List<E> expected) { return new TypeSafeMatcher<List<E>>() { @Override// ww w . j a v a2s . c om protected boolean matchesSafely(List<E> actual) { if (expected == actual) return true; if (expected == null) return false; if (expected.size() != actual.size()) return false; if (!expected.containsAll(actual)) return false; return true; } @Override public void describeTo(Description description) { description.appendText(expected.toString()); } }; }
From source file:org.kuali.rice.krad.uif.util.ExpressionFunctions.java
/** * Check to see if the list contains the values passed in. * * <p>In the SpringEL call values can be single item or array due to the way the EL converts values. * The values can be string or numeric and should match * the content type being stored in the list. If the list is String and the values passed in are not string, * toString() conversion will be used. Returns true if the values are in the list and both lists are non-empty, * false otherwise./*from w ww .j av a 2 s.c o m*/ * </p> * * @param list the list to be evaluated * @param values the values to be to check for in the list * @return true if all values exist in the list and both values and list are non-null/not-empty, false otherwise */ public static boolean listContains(List<?> list, Object[] values) { if (list != null && values != null && values.length > 0 && !list.isEmpty()) { //conversion for if the values are non-string but the list is string (special case) if (list.get(0) instanceof String && !(values[0] instanceof String)) { String[] stringValues = new String[values.length]; for (int i = 0; i < values.length; i++) { stringValues[i] = values[i].toString(); } return list.containsAll(Arrays.asList(stringValues)); } else if (list.get(0) instanceof Date && values[0] instanceof String) { //TODO date conversion return false; } else if (!(list.get(0) instanceof String) && values[0] instanceof String) { //values passed in are string but the list is of objects, use object's toString method List<String> stringList = new ArrayList<String>(); for (Object value : list) { stringList.add(value.toString()); } return stringList.containsAll(Arrays.asList(values)); } else { //no conversion for if neither list is String, assume matching types (numeric case) return list.containsAll(Arrays.asList(values)); } } //no cases satisfied, return false return false; }
From source file:org.apache.nifi.registry.security.util.CertificateUtils.java
/** * Returns true if the two provided DNs are equivalent, regardless of the order of the elements. Returns false if one or both are invalid DNs. * * Example://from ww w.j ava 2s . c o m * * CN=test1, O=testOrg, C=US compared to CN=test1, O=testOrg, C=US -> true * CN=test1, O=testOrg, C=US compared to O=testOrg, CN=test1, C=US -> true * CN=test1, O=testOrg, C=US compared to CN=test2, O=testOrg, C=US -> false * CN=test1, O=testOrg, C=US compared to O=testOrg, CN=test2, C=US -> false * CN=test1, O=testOrg, C=US compared to -> false * compared to -> true * * @param dn1 the first DN to compare * @param dn2 the second DN to compare * @return true if the DNs are equivalent, false otherwise */ public static boolean compareDNs(String dn1, String dn2) { if (dn1 == null) { dn1 = ""; } if (dn2 == null) { dn2 = ""; } if (StringUtils.isEmpty(dn1) || StringUtils.isEmpty(dn2)) { return dn1.equals(dn2); } try { List<Rdn> rdn1 = new LdapName(dn1).getRdns(); List<Rdn> rdn2 = new LdapName(dn2).getRdns(); return rdn1.size() == rdn2.size() && rdn1.containsAll(rdn2); } catch (InvalidNameException e) { logger.warn("Cannot compare DNs: {} and {} because one or both is not a valid DN", dn1, dn2); return false; } }
From source file:org.wso2.extension.siddhi.store.mongodb.util.MongoTableUtils.java
/** * Utility method which can be used to check if the existing indices contain the expected indices * defined by the annotation 'PrimaryKey' and 'IndexBy' and log a warning when indices differs. * * @param existingIndices List of indices that the collection contains. * @param expectedIndices List of indices that are defined by the annotations. *///from www . ja va 2 s . c o m public static void checkExistingIndices(List<IndexModel> expectedIndices, MongoCursor<Document> existingIndices) { Map<String, Object> indexOptionsMap = new HashMap<>(); List<Document> expectedIndexDocuments = expectedIndices.stream().map(expectedIndex -> { IndexOptions expectedIndexOptions = expectedIndex.getOptions(); indexOptionsMap.put("key", expectedIndex.getKeys()); // Default value for name of the index if (expectedIndexOptions.getName() == null) { StringBuilder indexName = new StringBuilder(); ((Document) expectedIndex.getKeys()) .forEach((key, value) -> indexName.append("_").append(key).append("_").append(value)); indexName.deleteCharAt(0); indexOptionsMap.put("name", indexName.toString()); } else { indexOptionsMap.put("name", expectedIndexOptions.getName()); } // Default value for the version if (expectedIndexOptions.getVersion() == null) { indexOptionsMap.put("v", 2); } else { indexOptionsMap.put("v", expectedIndexOptions.getVersion()); } indexOptionsMap.put("unique", expectedIndexOptions.isUnique()); indexOptionsMap.put("background", expectedIndexOptions.isBackground()); indexOptionsMap.put("sparse", expectedIndexOptions.isSparse()); indexOptionsMap.put("expireAfterSeconds", expectedIndexOptions.getExpireAfter(TimeUnit.SECONDS)); indexOptionsMap.put("weights", expectedIndexOptions.getWeights()); indexOptionsMap.put("languageOverride", expectedIndexOptions.getLanguageOverride()); indexOptionsMap.put("defaultLanguage", expectedIndexOptions.getDefaultLanguage()); indexOptionsMap.put("textVersion", expectedIndexOptions.getTextVersion()); indexOptionsMap.put("sphereVersion", expectedIndexOptions.getSphereVersion()); indexOptionsMap.put("textVersion", expectedIndexOptions.getTextVersion()); indexOptionsMap.put("bits", expectedIndexOptions.getBits()); indexOptionsMap.put("min", expectedIndexOptions.getMin()); indexOptionsMap.put("max", expectedIndexOptions.getMax()); indexOptionsMap.put("bucketSize", expectedIndexOptions.getBucketSize()); indexOptionsMap.put("partialFilterExpression", expectedIndexOptions.getPartialFilterExpression()); indexOptionsMap.put("collation", expectedIndexOptions.getCollation()); indexOptionsMap.put("storageEngine", expectedIndexOptions.getStorageEngine()); //Remove if Default Values - these would not be in the existingIndexDocument. indexOptionsMap.values().removeIf(Objects::isNull); indexOptionsMap.remove("unique", false); indexOptionsMap.remove("background", false); indexOptionsMap.remove("sparse", false); return new Document(indexOptionsMap); }).collect(Collectors.toList()); List<Document> existingIndexDocuments = new ArrayList<>(); existingIndices.forEachRemaining(existingIndex -> { existingIndex.remove("ns"); existingIndexDocuments.add(existingIndex); }); if (!existingIndexDocuments.containsAll(expectedIndexDocuments)) { log.warn("Existing indices differs from the expected indices defined by the Annotations 'PrimaryKey' " + "and 'IndexBy'.\nExisting Indices '" + existingIndexDocuments.toString() + "'.\n" + "Expected Indices '" + expectedIndexDocuments.toString() + "'"); } }
From source file:org.carrot2.workbench.editors.factory.EditorFactory.java
/** * Return a list of {@link TypeEditorWrapper} compatible with an {@link AttributeDescriptor}. */// w w w. ja v a 2 s.c o m private static List<TypeEditorWrapper> getCompatibleTypeEditors(final AttributeDescriptor attribute) { final List<String> annotationNames = Lists.newArrayList(); for (Annotation ann : attribute.constraints) { annotationNames.add(ann.annotationType().getName()); } return AttributeEditorLoader.INSTANCE.filterTypeEditors(new Predicate<TypeEditorWrapper>() { public boolean apply(TypeEditorWrapper editor) { boolean result = isCompatible(attribute.type, editor.attributeClass); /* * For editors with constraints, check allConstraintsRequired condition. */ if (result && !editor.constraints.isEmpty() && editor.allConstraintsRequired) { result = annotationNames.containsAll(editor.constraints); } return result; } }); }
From source file:amie.keys.CSAKey.java
private static List<List<String>> simplifyNonKeysSet(List<List<String>> nonKeySet) { List<List<String>> newnonKeySet = new ArrayList<List<String>>(); newnonKeySet.addAll(nonKeySet);//from w w w . ja v a2 s. c o m for (List<String> set : nonKeySet) { for (List<String> set2 : nonKeySet) { if (set2 != set && set2.containsAll(set)) { newnonKeySet.remove(set); break; } } } return newnonKeySet; }
From source file:biz.netcentric.cq.tools.actool.configuration.CqActionsMapping.java
/** * method that converts jcr:privileges to cq actions * /*from www . ja v a 2 s .co m*/ * @param jcrPrivilegesString * comma separated String containing jcr:privileges * @return comma separated String containing the assigned cq actions * @throws RepositoryException * @throws AccessControlException */ public static String getCqActions(final String jcrPrivilegesString, AccessControlManager aclManager) throws AccessControlException, RepositoryException { List<String> jcrPrivileges = new ArrayList<String>(Arrays.asList(jcrPrivilegesString.split(","))); // go through all aggregates to extend the list with all non-aggregate privileges for (String jcrPrivilege : jcrPrivilegesString.split(",")) { Privilege privilege = aclManager.privilegeFromName(jcrPrivilege); for (Privilege aggregatedPrivileges : privilege.getAggregatePrivileges()) { jcrPrivileges.add(aggregatedPrivileges.getName()); } } // loop through keySet of cqActions. Remove successively all privileges // which are associated to a cq action from jcrPrivileges string // and add this actions name to actions string Set<String> cqActions = ACTIONS_MAP.keySet(); String actionsString = ""; for (String action : cqActions) { List<String> jcrPrivilegesFromMap = ACTIONS_MAP.get(action); if (jcrPrivileges.containsAll(jcrPrivilegesFromMap)) { jcrPrivileges.removeAll(jcrPrivilegesFromMap); actionsString = actionsString + action + ","; } } // remove last comma from actions string actionsString = StringUtils.chop(actionsString); if (actionsString.isEmpty()) { actionsString = ""; } return actionsString; }
From source file:edu.uci.ics.jung.algorithms.layout.CircleLayout.java
/** * Sets the order of the vertices in the layout according to the ordering * of {@code vertex_list}./*w ww . ja va2 s.c o m*/ */ public void setVertexOrder(List<V> vertex_list) { if (!vertex_list.containsAll(getGraph().getVertices())) throw new IllegalArgumentException("Supplied list must include " + "all vertices of the graph"); this.vertex_ordered_list = vertex_list; }
From source file:com.sat.vcse.automation.utils.http.HttpClient.java
/** * Verify the given list of Cipher Suites is supported * @param cipherSuitesToUse/* w w w . j a v a2 s. c o m*/ * Array of strings representing the Cipher Suites that will be * presented to the HTTPS server during the SSL/TLS handshake * @return True if the given cipher suites are supported */ public static boolean verifyCipherSuite(String[] cipherSuitesToUse) { final String METHOD_NAME = "verifyCipherSuite(cipherSuitesToUse): "; final List<String> supportedCipherSuites = getSupportedCipherSuites(); if (cipherSuitesToUse == null || cipherSuitesToUse.length == 0) { throw new CoreRuntimeException(CLASS_NAME + METHOD_NAME + "Given cipher suite list is empty!"); } return supportedCipherSuites.containsAll(Arrays.asList(cipherSuitesToUse)); }
From source file:org.apache.hyracks.algebricks.rewriter.util.JoinUtils.java
private static BroadcastSide getBroadcastJoinSide(ILogicalExpression e, List<LogicalVariable> varsLeft, List<LogicalVariable> varsRight) { if (e.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return null; }//from w ww. j a va2 s. com AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) e; IExpressionAnnotation ann = fexp.getAnnotations() .get(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY); if (ann == null) { return null; } BroadcastSide side = (BroadcastSide) ann.getObject(); if (side == null) { return null; } int i; switch (side) { case LEFT: i = 0; break; case RIGHT: i = 1; break; default: return null; } ArrayList<LogicalVariable> vars = new ArrayList<>(); fexp.getArguments().get(i).getValue().getUsedVariables(vars); if (varsLeft.containsAll(vars)) { return BroadcastSide.LEFT; } else if (varsRight.containsAll(vars)) { return BroadcastSide.RIGHT; } else { return null; } }