List of usage examples for org.apache.commons.collections SetUtils isEqualSet
public static boolean isEqualSet(final Collection set1, final Collection set2)
equals()
contract in java.util.Set#equals(java.lang.Object) . From source file:com.hortonworks.registries.schemaregistry.avro.SchemaBranchLifeCycleTest.java
@Test public void getAllBranches() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException { SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE); SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc"); SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId()); SchemaIdVersion masterSchemaIdVersion2 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device-incompat.avsc"); SchemaBranch schemaBranch2 = addSchemaBranch("BRANCH2", schemaMetadata, masterSchemaIdVersion2.getSchemaVersionId()); Set<String> actualSchemaBranches = schemaRegistryClient.getSchemaBranches(schemaMetadata.getName()).stream() .map(branch -> branch.getName()).collect(Collectors.toSet()); Set<String> expectedSchemaBranches = new HashSet<>( Lists.newArrayList("MASTER", schemaBranch1.getName(), schemaBranch2.getName())); Assert.assertTrue(SetUtils.isEqualSet(actualSchemaBranches, expectedSchemaBranches)); }
From source file:fr.gael.dhus.sync.impl.ODataUserSynchronizer.java
@Override public boolean synchronize() throws InterruptedException { int created = 0, updated = 0; try {// w ww . j av a 2s . co m // Makes query parameters Map<String, String> query_param = new HashMap<>(); if (skip != 0) { query_param.put("$skip", String.valueOf(skip)); } query_param.put("$top", String.valueOf(pageSize)); log(Level.DEBUG, "Querying users from " + skip + " to " + skip + pageSize); ODataFeed userfeed = readFeedLogPerf("/Users", query_param); // For each entry, creates a DataBase Object for (ODataEntry pdt : userfeed.getEntries()) { String username = null; try { Map<String, Object> props = pdt.getProperties(); username = (String) props.get(UserEntitySet.USERNAME); String email = (String) props.get(UserEntitySet.EMAIL); String firstname = (String) props.get(UserEntitySet.FIRSTNAME); String lastname = (String) props.get(UserEntitySet.LASTNAME); String country = (String) props.get(UserEntitySet.COUNTRY); String domain = (String) props.get(UserEntitySet.DOMAIN); String subdomain = (String) props.get(UserEntitySet.SUBDOMAIN); String usage = (String) props.get(UserEntitySet.USAGE); String subusage = (String) props.get(UserEntitySet.SUBUSAGE); String phone = (String) props.get(UserEntitySet.PHONE); String address = (String) props.get(UserEntitySet.ADDRESS); String hash = (String) props.get(UserEntitySet.HASH); String password = (String) props.get(UserEntitySet.PASSWORD); Date creation = ((GregorianCalendar) props.get(UserEntitySet.CREATED)).getTime(); // Uses the Scheme encoder as it is the most restrictives, it only allows // '+' (forbidden char in usernames, so it's ok) // '-' (forbidden char in usernames, so it's ok) // '.' (allowed char in usernames, not problematic) // the alphanumeric character class (a-z A-Z 0-9) String encoded_username = UriUtils.encodeScheme(username, "UTF-8"); // Retrieves Roles String roleq = String.format("/Users('%s')/SystemRoles", encoded_username); ODataFeed userrole = readFeedLogPerf(roleq, null); List<ODataEntry> roles = userrole.getEntries(); List<Role> new_roles = new ArrayList<>(); for (ODataEntry role : roles) { String rolename = (String) role.getProperties().get(SystemRoleEntitySet.NAME); new_roles.add(Role.valueOf(rolename)); } // Has restriction? String restricq = String.format("/Users('%s')/Restrictions", encoded_username); ODataFeed userrestric = readFeedLogPerf(restricq, null); boolean has_restriction = !userrestric.getEntries().isEmpty(); // Reads user in database, may be null User user = USER_SERVICE.getUserNoCheck(username); // Updates existing user if (user != null && (force || creation.equals(user.getCreated()))) { boolean changed = false; // I wish users had their `Updated` field exposed on OData if (!username.equals(user.getUsername())) { user.setUsername(username); changed = true; } if (email == null && user.getEmail() != null || email != null && !email.equals(user.getEmail())) { user.setEmail(email); changed = true; } if (firstname == null && user.getFirstname() != null || firstname != null && !firstname.equals(user.getFirstname())) { user.setFirstname(firstname); changed = true; } if (lastname == null && user.getLastname() != null || lastname != null && !lastname.equals(user.getLastname())) { user.setLastname(lastname); changed = true; } if (country == null && user.getCountry() != null || country != null && !country.equals(user.getCountry())) { user.setCountry(country); changed = true; } if (domain == null && user.getDomain() != null || domain != null && !domain.equals(user.getDomain())) { user.setDomain(domain); changed = true; } if (subdomain == null && user.getSubDomain() != null || subdomain != null && !subdomain.equals(user.getSubDomain())) { user.setSubDomain(subdomain); changed = true; } if (usage == null && user.getUsage() != null || usage != null && !usage.equals(user.getUsage())) { user.setUsage(usage); changed = true; } if (subusage == null && user.getSubUsage() != null || subusage != null && !subusage.equals(user.getSubUsage())) { user.setSubUsage(subusage); changed = true; } if (phone == null && user.getPhone() != null || phone != null && !phone.equals(user.getPhone())) { user.setPhone(phone); changed = true; } if (address == null && user.getAddress() != null || address != null && !address.equals(user.getAddress())) { user.setAddress(address); changed = true; } if (password == null && user.getPassword() != null || password != null && !password.equals(user.getPassword())) { if (hash == null) hash = PasswordEncryption.NONE.getAlgorithmKey(); user.setEncryptedPassword(password, User.PasswordEncryption.valueOf(hash)); changed = true; } //user.setPasswordEncryption(User.PasswordEncryption.valueOf(hash)); if (!SetUtils.isEqualSet(user.getRoles(), new_roles)) { user.setRoles(new_roles); changed = true; } if (has_restriction != !user.getRestrictions().isEmpty()) { if (has_restriction) { user.addRestriction(new LockedAccessRestriction()); } else { user.setRestrictions(Collections.EMPTY_SET); } changed = true; } if (changed) { log(Level.DEBUG, "Updating user " + user.getUsername()); USER_SERVICE.systemUpdateUser(user); updated++; } } // Creates new user else if (user == null) { user = new User(); user.setUsername(username); user.setEmail(email); user.setFirstname(firstname); user.setLastname(lastname); user.setCountry(country); user.setDomain(domain); user.setSubDomain(subdomain); user.setUsage(usage); user.setSubUsage(subusage); user.setPhone(phone); user.setAddress(address); user.setPassword(password); //user.setPasswordEncryption(User.PasswordEncryption.valueOf(hash)); user.setCreated(creation); user.setRoles(new_roles); if (has_restriction) { user.addRestriction(new LockedAccessRestriction()); } log(Level.DEBUG, "Creating new user " + user.getUsername()); USER_SERVICE.systemCreateUser(user); created++; } else { log(Level.ERROR, "Namesake '" + username + "' detected!"); } } catch (RootNotModifiableException e) { } // Ignored exception catch (RequiredFieldMissingException ex) { log(Level.ERROR, "Cannot create user '" + username + "'", ex); } catch (IOException | ODataException ex) { log(Level.ERROR, "OData failure on user '" + username + "'", ex); } this.skip++; } // This is the end, resets `skip` to 0 if (userfeed.getEntries().size() < pageSize) { this.skip = 0; } } catch (IOException | ODataException ex) { log(Level.ERROR, "OData failure", ex); } catch (LockAcquisitionException | CannotAcquireLockException e) { throw new InterruptedException(e.getMessage()); } finally { StringBuilder sb = new StringBuilder("done: "); sb.append(created).append(" new Users, "); sb.append(updated).append(" updated Users, "); sb.append(" from ").append(this.client.getServiceRoot()); log(Level.INFO, sb.toString()); this.syncConf.setConfig("skip", String.valueOf(skip)); SYNC_SERVICE.saveSynchronizer(this); } return false; }
From source file:org.apache.cloudstack.agent.lb.algorithm.IndirectAgentLBShuffleAlgorithm.java
@Override public boolean compare(List<String> msList, List<String> receivedMsList) { return SetUtils.isEqualSet(msList, receivedMsList); }
From source file:org.apache.hadoop.hive.ql.hooks.LineageLogger.java
/** * Find an edge that has the same type, expression, and sources. */// w ww . jav a2s . co m private Edge findSimilarEdgeBySources(List<Edge> edges, Set<Vertex> sources, String expr, Edge.Type type) { for (Edge edge : edges) { if (edge.type == type && StringUtils.equals(edge.expr, expr) && SetUtils.isEqualSet(edge.sources, sources)) { return edge; } } return null; }
From source file:org.onehippo.forge.content.pojo.model.ContentNode.java
@Override public boolean equals(Object o) { if (!(o instanceof ContentNode)) { return false; }/*from ww w. j a v a 2s. com*/ ContentNode that = (ContentNode) o; if (!StringUtils.equals(getName(), that.getName())) { return false; } if (!StringUtils.equals(primaryType, that.primaryType)) { return false; } if (!SetUtils.isEqualSet(mixinTypes, that.mixinTypes)) { return false; } if (properties == null) { if (that.properties != null) { return false; } } else { if (!ListUtils.isEqualList(properties, that.properties)) { return false; } } if (!ListUtils.isEqualList(nodes, that.nodes)) { return false; } return true; }
From source file:org.projectforge.business.ldap.GroupDOConverter.java
/** * Copies the fields./*w w w . java 2s. com*/ * * @param src * @param dest * @return true if any modification is detected, otherwise false. */ public boolean copyGroupFields(final LdapGroup src, final LdapGroup dest) { boolean modified; final List<String> properties = new LinkedList<String>(); ListHelper.addAll(properties, "description", "organization"); if (ldapUserDao.isPosixAccountsConfigured() == true && isPosixAccountValuesEmpty(src) == false) { ListHelper.addAll(properties, "gidNumber"); } modified = BeanHelper.copyProperties(src, dest, true, properties.toArray(new String[0])); // Checks if the sets aren't equal: if (SetUtils.isEqualSet(src.getMembers(), dest.getMembers()) == false) { if (LdapGroupDao.hasMembers(src) == true || LdapGroupDao.hasMembers(dest) == true) { // If both, src and dest have no members, then do nothing, otherwise: modified = true; dest.clearMembers(); dest.addAllMembers(src.getMembers()); } } return modified; }
From source file:org.projectforge.ldap.GroupDOConverter.java
/** * Copies the fields./*w w w .j a v a 2 s .c o m*/ * @param src * @param dest * @return true if any modification is detected, otherwise false. */ public static boolean copyGroupFields(final LdapGroup src, final LdapGroup dest) { boolean modified = BeanHelper.copyProperties(src, dest, true, "description", "organization"); // Checks if the sets aren't equal: if (SetUtils.isEqualSet(src.getMembers(), dest.getMembers()) == false) { if (LdapGroupDao.hasMembers(src) == true || LdapGroupDao.hasMembers(dest) == true) { // If both, src and dest have no members, then do nothing, otherwise: modified = true; dest.clearMembers(); dest.addAllMembers(src.getMembers()); } } return modified; }
From source file:org.tonguetied.keywordmanagement.Keyword.java
@Override public boolean equals(Object obj) { boolean isEqual = false; // a good optimization if (this == obj) { isEqual = true;//from ww w . j a v a 2 s. c om } else if (obj instanceof Keyword) { final Keyword other = (Keyword) obj; isEqual = (this.keyword == null ? other.keyword == null : keyword.equals(other.keyword)) && (this.context == null ? other.context == null : context.equals(other.context)) && (this.translations == null ? other.translations == null : SetUtils.isEqualSet(translations, other.translations)); // translations.equals(other.translations)); } return isEqual; }
From source file:org.wso2.carbon.apimgt.impl.utils.APIUtilTest.java
@Test public void testGetAPIForPublishing() throws Exception { API expectedAPI = getUniqueAPI();/*from w w w . j a va2 s . co m*/ final String provider = expectedAPI.getId().getProviderName(); final String tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; final int tenantId = -1234; GovernanceArtifact artifact = Mockito.mock(GovernanceArtifact.class); Registry registry = Mockito.mock(Registry.class); ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito .mock(APIManagerConfigurationService.class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class); SubscriptionPolicy policy = Mockito.mock(SubscriptionPolicy.class); SubscriptionPolicy[] policies = new SubscriptionPolicy[] { policy }; QuotaPolicy quotaPolicy = Mockito.mock(QuotaPolicy.class); RequestCountLimit limit = Mockito.mock(RequestCountLimit.class); PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(GovernanceUtils.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); Mockito.when(apiMgtDAO.getAPIID(Mockito.any(APIIdentifier.class), eq((Connection) null))).thenReturn(123); Mockito.when(artifact.getId()).thenReturn(""); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn(provider); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_CACHE_TIMEOUT)).thenReturn("15"); Mockito.when(MultitenantUtils.getTenantDomain(provider)).thenReturn(tenantDomain); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId); String artifactPath = ""; Mockito.when(GovernanceUtils.getArtifactPath(registry, "")).thenReturn(artifactPath); Mockito.when(registry.get(artifactPath)).thenReturn(resource); Mockito.when(resource.getLastModified()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(resource.getCreatedTime()).thenReturn(expectedAPI.getLastUpdated()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()) .thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()) .thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties); Mockito.when(throttleProperties.isEnabled()).thenReturn(true); Mockito.when(apiMgtDAO.getSubscriptionPolicies(tenantId)).thenReturn(policies); Mockito.when(policy.getDefaultQuotaPolicy()).thenReturn(quotaPolicy); Mockito.when(quotaPolicy.getLimit()).thenReturn(limit); Mockito.when(registry.getTags(artifactPath)).thenReturn(getTagsFromSet(expectedAPI.getTags())); HashMap<String, String> urlPatterns = getURLTemplatePattern(expectedAPI.getUriTemplates()); Mockito.when(apiMgtDAO.getURITemplatesPerAPIAsString(Mockito.any(APIIdentifier.class))) .thenReturn(urlPatterns); CORSConfiguration corsConfiguration = expectedAPI.getCorsConfiguration(); Mockito.when( apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_HEADERS)) .thenReturn(corsConfiguration.getAccessControlAllowHeaders().toString()); Mockito.when( apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_METHODS)) .thenReturn(corsConfiguration.getAccessControlAllowMethods().toString()); Mockito.when( apiManagerConfiguration.getFirstProperty(APIConstants.CORS_CONFIGURATION_ACCESS_CTL_ALLOW_ORIGIN)) .thenReturn(corsConfiguration.getAccessControlAllowOrigins().toString()); Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_CONFIG)).thenReturn( "{\"production_endpoints\":{\"url\":\"http://www.mocky.io/v2/5b21fe0f2e00002a00e313fe\"," + "\"config\":null,\"template_not_supported\":false}," + "\"sandbox_endpoints\":{\"url\":\"http://www.mocky.io/v2/5b21fe0f2e00002a00e313fe\"," + "\"config\":null,\"template_not_supported\":false},\"endpoint_type\":\"http\"}"); API api = APIUtil.getAPIForPublishing(artifact, registry); Assert.assertNotNull(api); Set<String> testEnvironmentList = new HashSet<String>(); testEnvironmentList.add("PRODUCTION"); testEnvironmentList.add("SANDBOX"); Assert.assertThat(SetUtils.isEqualSet(api.getEnvironmentList(), testEnvironmentList), is(true)); }