List of usage examples for java.util ArrayList containsAll
boolean containsAll(Collection<?> c);
From source file:org.apache.rave.util.CollectionUtilsTest.java
@Test public void reconcileObjectCollections_addSingleNewObject_removeFlagFalse() { TestObject newObject = new TestObject("newName1", "newValue1"); ArrayList<TestObject> existingObjects = new ArrayList<TestObject>(existingObjectsMap.values()); ArrayList<TestObject> updatedObjects = new ArrayList<TestObject>(); updatedObjects.add(newObject);//from ww w . j a va 2s . com CollectionUtils.reconcileObjectCollections(existingObjects, updatedObjects, reconciliationHelper, false); assertTrue(existingObjects.containsAll(existingObjectsMap.values())); assertTrue(existingObjects.contains(newObject)); }
From source file:org.ebayopensource.turmeric.tools.codegen.AbstractServiceGeneratorTestCase.java
protected boolean compareTwoFiles(File file1, File file2) throws IOException { @SuppressWarnings("unchecked") List<String> firstFile = FileUtils.readLines(file1); ArrayList<String> trimmedList1 = new ArrayList<String>(); ArrayList<String> trimmedList2 = new ArrayList<String>(); @SuppressWarnings("unchecked") List<String> secondFile = FileUtils.readLines(file2); while (firstFile.remove("")) ;//from w w w . j ava 2 s. co m while (secondFile.remove("")) ; for (String s : firstFile) { trimmedList1.add(s.trim()); } for (String s : secondFile) { trimmedList2.add(s.trim()); } if (trimmedList2.containsAll(trimmedList1)) { for (String ln : trimmedList1) { System.out.println(ln); } for (String ln1 : trimmedList2) { System.out.println(ln1); } return true; } else { for (String ln : trimmedList1) { System.out.println(ln); } for (String ln1 : trimmedList2) { System.out.println(ln1); } Iterator<String> i = trimmedList2.iterator(); while (i.hasNext()) { String line = i.next(); if (!trimmedList1.contains(line)) { Assert.assertTrue(line + " is not found in " + file1.getAbsolutePath(), false); } } } return false; }
From source file:org.opencyc.constraintsolver.ForwardCheckingSearcher.java
/** * Returns the number of constraint rules applicable to variable and one or more * of the other variables.// www. j ava2s .c om * * @param variable the variable which must be used in the counted constraint rules * @param variables the counted constraint rules must use only these variables and no others. * @return the number of constraint rules applicable to variable and one or more * of the other variables */ protected int constraintDegree(CycVariable variable, ArrayList variables) { int degree = 0; ArrayList ruleVariables = null; for (int i = 0; i < constraintProblem.constraintRules.size(); i++) { ConstraintRule rule = (ConstraintRule) constraintProblem.constraintRules.get(i); ruleVariables = rule.getVariables(); if (ruleVariables.contains(variable) && variables.containsAll(ruleVariables)) { degree++; if (verbosity > 8) { ArrayList candidateVariables = (ArrayList) variables.clone(); candidateVariables.remove(variable); System.out.println("ConstraintRule " + rule.cyclify() + "\n between " + variable + " and candidate variables " + candidateVariables); } } } if (verbosity > 8) System.out.println("Constraint degree for " + variable + " is " + degree); return degree; }
From source file:org.openmrs.module.emrapi.adt.AdtServiceImpl.java
public boolean areConsecutiveVisits(List<Integer> visits, Patient patient) { if (patient != null && visits != null && (visits.size() > 0)) { List<Visit> patientVisits = visitService.getVisitsByPatient(patient, true, false); if ((patientVisits != null) && (patientVisits.size() > 0)) { ArrayList<Integer> allVisits = new ArrayList<Integer>(); int j = 0; for (Visit visit : patientVisits) { allVisits.add(j++, visit.getId()); }/*from ww w. j a v a 2 s. c o m*/ if (allVisits.containsAll(visits)) { //find the index of the first candidate for a consecutive visit int i = allVisits.indexOf(visits.get(0)); //make sure there are still more elements in the list than the the number of candidate consecutives if ((allVisits.size() - i) >= visits.size()) { for (Integer candidateVisit : visits) { if (allVisits.get(i).compareTo(candidateVisit) == 0) { i++; } else { return false; } } return true; } } } } return false; }
From source file:org.ebayopensource.turmeric.eclipse.test.util.ProjectArtifactValidator.java
private boolean compareTwoFiles(File file1, File file2) throws IOException { @SuppressWarnings("unchecked") List<String> firstFile = FileUtils.readLines(file1); ArrayList<String> trimmedList1 = new ArrayList<String>(); ArrayList<String> trimmedList2 = new ArrayList<String>(); @SuppressWarnings("unchecked") List<String> secondFile = FileUtils.readLines(file2); while (firstFile.remove("")) ;//from www .j a va 2 s .com while (secondFile.remove("")) ; for (String s : firstFile) { trimmedList1.add(s.trim()); } for (String s : secondFile) { trimmedList2.add(s.trim()); } ArrayList<String> commentRemoved1 = new ArrayList<String>(); ArrayList<String> commentRemoved2 = new ArrayList<String>(); commentRemoved1.addAll(trimmedList1); Iterator<String> it = trimmedList1.iterator(); String s = null; while (it.hasNext()) { s = it.next(); if (Pattern.matches(CommentDetector.COMMENT_DETECTOR_REGEX, s)) commentRemoved1.remove(s); } commentRemoved2.addAll(trimmedList2); it = trimmedList2.iterator(); while (it.hasNext()) { s = it.next(); if (Pattern.matches(CommentDetector.COMMENT_DETECTOR_REGEX, s)) commentRemoved2.remove(s); } if (commentRemoved1.size() == commentRemoved2.size()) { if (commentRemoved1.containsAll(commentRemoved2)) return true; else { Iterator<String> itr = commentRemoved1.iterator(); Iterator<String> itr2 = commentRemoved2.iterator(); while (itr.hasNext() && itr2.hasNext()) { String line1 = itr.next(); String line2 = itr2.next(); if (!line1.equals(line2)) { System.out.println(line1 + " is not matching " + line2); } } System.out.println(commentRemoved1); System.out.println(commentRemoved2); return false; } } else { System.out.println("Number of lines in first file " + commentRemoved1.size()); System.out.println("Number of lines in second file " + commentRemoved2.size()); return false; } }
From source file:org.ebayopensource.turmeric.tools.codegen.AbstractServiceGeneratorTestCase.java
protected boolean compareFiles(File file1, File file2) throws IOException { @SuppressWarnings("unchecked") List<String> firstFile = FileUtils.readLines(file1); ArrayList<String> trimmedList1 = new ArrayList<String>(); ArrayList<String> trimmedList2 = new ArrayList<String>(); @SuppressWarnings("unchecked") List<String> secondFile = FileUtils.readLines(file2); while (firstFile.remove("")) ;/* w w w .j a v a 2 s.c om*/ while (secondFile.remove("")) ; for (String s : firstFile) { trimmedList1.add(s.trim()); } for (String s : secondFile) { trimmedList2.add(s.trim()); } ArrayList<String> commentRemoved1 = new ArrayList<String>(); ArrayList<String> commentRemoved2 = new ArrayList<String>(); commentRemoved1.addAll(trimmedList1); Iterator<String> it = trimmedList1.iterator(); String s = null; while (it.hasNext()) { s = it.next(); if (Pattern.matches(CommentDetector.COMMENT_DETECTOR_REGEX, s)) commentRemoved1.remove(s); } commentRemoved2.addAll(trimmedList2); it = trimmedList2.iterator(); while (it.hasNext()) { s = it.next(); if (Pattern.matches(CommentDetector.COMMENT_DETECTOR_REGEX, s)) commentRemoved2.remove(s); } if (commentRemoved1.size() == commentRemoved2.size()) { if (commentRemoved1.containsAll(commentRemoved2)) return true; else { Iterator<String> i = trimmedList2.iterator(); while (i.hasNext()) { String line = i.next(); if (!trimmedList1.contains(line)) { Assert.assertTrue(line + " is not found in " + file1.getAbsolutePath(), false); } } } } else return false; return false; }
From source file:com.openkm.module.jcr.JcrSearchModule.java
@Override public Map<String, Integer> getKeywordMap(String token, List<String> filter) throws RepositoryException, DatabaseException { log.debug("getKeywordMap({}, {})", token, filter); String statement = "/jcr:root//*[@jcr:primaryType eq 'okm:document' or @jcr:primaryType eq 'okm:mail' or @jcr:primaryType eq 'okm:folder']"; HashMap<String, Integer> cloud = new HashMap<String, Integer>(); Session session = null;//from w w w.j av a 2 s . c o m try { if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.XPATH); javax.jcr.query.QueryResult qResult = query.execute(); for (NodeIterator nit = qResult.getNodes(); nit.hasNext();) { Node doc = nit.nextNode(); Value[] keywordsValue = doc.getProperty(com.openkm.bean.Property.KEYWORDS).getValues(); ArrayList<String> keywordCollection = new ArrayList<String>(); for (int i = 0; i < keywordsValue.length; i++) { keywordCollection.add(keywordsValue[i].getString()); } if (filter != null && keywordCollection.containsAll(filter)) { for (Iterator<String> it = keywordCollection.iterator(); it.hasNext();) { String keyword = it.next(); if (!filter.contains(keyword)) { Integer occurs = cloud.get(keyword) != null ? cloud.get(keyword) : 0; cloud.put(keyword, occurs + 1); } } } } } catch (javax.jcr.RepositoryException e) { log.error(e.getMessage(), e); throw new RepositoryException(e.getMessage(), e); } finally { if (token == null) { JCRUtils.logout(session); } } log.debug("getKeywordMap: {}", cloud); return cloud; }
From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenServices.java
@Override public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest request) throws AuthenticationException { if (null == refreshTokenValue) { throw new InvalidTokenException("Invalid refresh token (empty token)"); }/* w w w. j a va 2 s . com*/ if (!"refresh_token".equals(request.getRequestParameters().get("grant_type"))) { throw new InvalidGrantException( "Invalid grant type: " + request.getRequestParameters().get("grant_type")); } Map<String, Object> claims = getClaimsForToken(refreshTokenValue); // TODO: Should reuse the access token you get after the first // successful authentication. // You will get an invalid_grant error if your previous token has not // expired yet. // OAuth2RefreshToken refreshToken = // tokenStore.readRefreshToken(refreshTokenValue); // if (refreshToken == null) { // throw new InvalidGrantException("Invalid refresh token: " + // refreshTokenValue); // } String clientId = (String) claims.get(CID); if (clientId == null || !clientId.equals(request.getClientId())) { throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue); } String userid = (String) claims.get(USER_ID); // TODO: Need to add a lookup by id so that the refresh token does not // need to contain a name UaaUser user = userDatabase.retrieveUserById(userid); Integer refreshTokenIssuedAt = (Integer) claims.get(IAT); long refreshTokenIssueDate = refreshTokenIssuedAt.longValue() * 1000l; // If the user changed their password, expire the refresh token if (user.getModified().after(new Date(refreshTokenIssueDate))) { logger.debug("User was last modified at " + user.getModified() + " refresh token was issued at " + new Date(refreshTokenIssueDate)); throw new InvalidTokenException("Invalid refresh token (password changed): " + refreshTokenValue); } Integer refreshTokenExpiry = (Integer) claims.get(EXP); long refreshTokenExpireDate = refreshTokenExpiry.longValue() * 1000l; if (new Date(refreshTokenExpireDate).before(new Date())) { throw new InvalidTokenException("Invalid refresh token (expired): " + refreshTokenValue + " expired at " + new Date(refreshTokenExpireDate)); } @SuppressWarnings("unchecked") ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE); // default request scopes to what is in the refresh token Set<String> requestedScopes = request.getScope(); if (requestedScopes.isEmpty()) { requestedScopes = new HashSet<String>(tokenScopes); } // The user may not request scopes that were not part of the refresh // token if (tokenScopes.isEmpty() || !tokenScopes.containsAll(requestedScopes)) { throw new InvalidScopeException( "Unable to narrow the scope of the client authentication to " + requestedScopes + ".", new HashSet<String>(tokenScopes)); } // from this point on, we only care about the scopes requested, not what // is in the refresh token // ensure all requested scopes are approved: either automatically or // explicitly by the user ClientDetails client = clientDetailsService.loadClientByClientId(clientId); String grantType = claims.get(GRANT_TYPE).toString(); checkForApproval(userid, clientId, requestedScopes, getAutoApprovedScopes(grantType, tokenScopes, client), new Date(refreshTokenIssueDate)); // if we have reached so far, issue an access token Integer validity = client.getAccessTokenValiditySeconds(); @SuppressWarnings("unchecked") Map<String, String> additionalAuthorizationInfo = (Map<String, String>) claims.get(ADDITIONAL_AZ_ATTR); Set<String> audience = new HashSet<>((ArrayList<String>) claims.get(AUD)); OAuth2AccessToken accessToken = createAccessToken(user.getId(), user.getUsername(), user.getEmail(), validity != null ? validity.intValue() : accessTokenValiditySeconds, null, requestedScopes, clientId, audience /*request.createOAuth2Request(client).getResourceIds()*/, grantType, refreshTokenValue, additionalAuthorizationInfo, new HashSet<String>()); //TODO populate response types return accessToken; }
From source file:com.ikon.module.jcr.JcrSearchModule.java
/** * Get keyword map/*from w ww . ja va 2 s . c om*/ */ private Map<String, Integer> getKeywordMapLive(String token, List<String> filter) throws RepositoryException, DatabaseException { log.debug("getKeywordMapLive({}, {})", token, filter); String statement = "/jcr:root//*[@jcr:primaryType eq 'openkm:document' or @jcr:primaryType eq 'openkm:mail' or @jcr:primaryType eq 'openkm:folder']"; HashMap<String, Integer> cloud = new HashMap<String, Integer>(); Session session = null; try { if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.XPATH); javax.jcr.query.QueryResult qResult = query.execute(); for (NodeIterator nit = qResult.getNodes(); nit.hasNext();) { Node doc = nit.nextNode(); Value[] keywordsValue = doc.getProperty(com.ikon.bean.Property.KEYWORDS).getValues(); ArrayList<String> keywordCollection = new ArrayList<String>(); for (int i = 0; i < keywordsValue.length; i++) { keywordCollection.add(keywordsValue[i].getString()); } if (filter != null && keywordCollection.containsAll(filter)) { for (Iterator<String> it = keywordCollection.iterator(); it.hasNext();) { String keyword = it.next(); if (!filter.contains(keyword)) { Integer occurs = cloud.get(keyword) != null ? cloud.get(keyword) : 0; cloud.put(keyword, occurs + 1); } } } } } catch (javax.jcr.RepositoryException e) { log.error(e.getMessage(), e); throw new RepositoryException(e.getMessage(), e); } finally { if (token == null) JCRUtils.logout(session); } log.debug("getKeywordMapLive: {}", cloud); return cloud; }
From source file:petascope.util.ras.TypeResolverUtil.java
/** * Guesses the collection type. If no type is found, a new one is created. * * @param numberOfDimensions/*from w w w .j a v a 2 s. c o m*/ * @param gdalBandTypes * @return */ private static String guessCollectionType(Integer numberOfDimensions, ArrayList<String> gdalBandTypes, ArrayList<String> nullValues) throws PetascopeException { String result = ""; //get the type registry TypeRegistry typeRegistry = TypeRegistry.getInstance(); for (Map.Entry<String, TypeRegistryEntry> i : typeRegistry.getTypeRegistry().entrySet()) { //filter by dimensionality String domainType = i.getValue().getDomainType(); if (domainType.contains(numberOfDimensions.toString())) { //get the structured base type String baseType; if (domainType.contains("struct")) { //more bands, check for each of them String baseTypeArr = domainType.split("}")[0]; baseType = baseTypeArr.split("\\{")[1]; //we are left with something like char red, char green, char blue String[] baseTypeByBand = baseType.split(","); //filter by number of bands if (baseTypeByBand.length == gdalBandTypes.size()) { Boolean allBandsMatch = true; //compare band by band for (Integer j = 0; j < baseTypeByBand.length; j++) { //fix rasdaman type bug, where ushort and ulong are printed by rasdl, but not accepted as input. // Instead rasdl wants "unsigned short" or "unsigned long" if (baseTypeByBand[j].contains("ushort")) { baseTypeByBand[j] = "unsigned short"; } if (baseTypeByBand[j].contains("ulong")) { baseTypeByBand[j] = "unsigned long"; } if (!baseTypeByBand[j].contains(GDAL_TYPES_TO_RAS_TYPES.get(gdalBandTypes.get(j)))) { allBandsMatch = false; } } //if all good check for nils if (allBandsMatch) { if (nullValues.containsAll(i.getValue().getNullValues()) && i.getValue().getNullValues().containsAll(nullValues)) { return i.getKey(); } } } } else { //1 band baseType = i.getValue().getBaseType(); if (gdalBandTypes.size() == 1 && baseType.equals(GDAL_TYPES_TO_RAS_TYPES.get(gdalBandTypes.get(0)))) { if (nullValues.containsAll(i.getValue().getNullValues()) && i.getValue().getNullValues().containsAll(nullValues)) { return i.getKey(); } } } } } //nothing has been found, so the type must be created result = typeRegistry.createNewType(numberOfDimensions, translateTypes(gdalBandTypes), nullValues); return result; }