org.apache.commons.collections.SetUtils Java Examples

The following examples show how to use org.apache.commons.collections.SetUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleClassNode.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (!(obj instanceof SimpleClassNode))
        return false;
    SimpleClassNode other = (SimpleClassNode) obj;
    if (uris == null) {
        if (other.uris != null)
            return false;
    } else if (!SetUtils.isEqualSet(uris, other.uris))
        return false;
    return true;
}
 
Example #2
Source File: GroupDOConverter.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Copies the fields.
 * @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;
  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;
}
 
Example #3
Source File: TestStateMachine.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void testStateMachineStates() throws InvalidStateTransitionException {
  Set<STATES> finals = new HashSet<>();
  finals.add(FINAL);

  StateMachine<STATES, EVENTS> stateMachine =
      new StateMachine<>(INIT, finals);

  stateMachine.addTransition(INIT, CREATING, EVENTS.ALLOCATE);
  stateMachine.addTransition(CREATING, OPERATIONAL, EVENTS.CREATE);
  stateMachine.addTransition(OPERATIONAL, OPERATIONAL, EVENTS.UPDATE);
  stateMachine.addTransition(OPERATIONAL, CLEANUP, EVENTS.DELETE);
  stateMachine.addTransition(OPERATIONAL, CLOSED, EVENTS.CLOSE);
  stateMachine.addTransition(CREATING, CLEANUP, EVENTS.TIMEOUT);

  // Initial and Final states
  Assert.assertEquals("Initial State", INIT, stateMachine.getInitialState());
  Assert.assertTrue("Final States", SetUtils.isEqualSet(finals,
      stateMachine.getFinalStates()));

  // Valid state transitions
  Assert.assertEquals("STATE should be OPERATIONAL after being created",
      OPERATIONAL, stateMachine.getNextState(CREATING, EVENTS.CREATE));
  Assert.assertEquals("STATE should be OPERATIONAL after being updated",
      OPERATIONAL, stateMachine.getNextState(OPERATIONAL, EVENTS.UPDATE));
  Assert.assertEquals("STATE should be CLEANUP after being deleted",
      CLEANUP, stateMachine.getNextState(OPERATIONAL, EVENTS.DELETE));
  Assert.assertEquals("STATE should be CLEANUP after being timeout",
      CLEANUP, stateMachine.getNextState(CREATING, EVENTS.TIMEOUT));
  Assert.assertEquals("STATE should be CLOSED after being closed",
      CLOSED, stateMachine.getNextState(OPERATIONAL, EVENTS.CLOSE));

  // Negative cases: invalid transition
  expectException();
  stateMachine.getNextState(OPERATIONAL, EVENTS.CREATE);

  expectException();
  stateMachine.getNextState(CREATING, EVENTS.CLOSE);
}
 
Example #4
Source File: StringUtil.java    From das with Apache License 2.0 5 votes vote down vote up
public static Set<String> toSet(String values) {
    if (StringUtils.isNotBlank(values)) {
        List<String> list = toList(values, ",");
        return new HashSet(list);
    }
    return SetUtils.EMPTY_SET;
}
 
Example #5
Source File: SchemaBranchLifeCycleTest.java    From registry with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #6
Source File: InitializeSet.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void create_new_set_apache () {

	@SuppressWarnings("unchecked")
	Set<String> newSet = SetUtils.EMPTY_SET;
	
	assertNotNull(newSet);
}
 
Example #7
Source File: ReturnEmptySet.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void return_empty_set_apache_commons () {
	
	@SuppressWarnings("unchecked")
	Set<String> emptySet = SetUtils.EMPTY_SET;
	
	assertTrue(emptySet.isEmpty());
}
 
Example #8
Source File: ReturnEmptySet.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Used for post example
 */
@SuppressWarnings({ "unused", "unchecked" })
private void return_empty_set_apache_commons_exception () {
	DomainObject domain = null; // dao populate domain

	Set<String> strings;
	if (domain != null && !CollectionUtils.isEmpty(domain.getStrings())) {
		strings = domain.getStrings();
	} else {
		strings = SetUtils.EMPTY_SET;
	}

	//...
}
 
Example #9
Source File: NavigationProviderImpl.java    From the-app with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked") // apache commons collection api does not support generics
public static Set<Class<? extends Page>> getAnnotatedWicketPage(String packageScanPath, Class<? extends Annotation> annotationClazz) {
    Reflections reflections = new Reflections(packageScanPath);
    return SetUtils.predicatedSet(reflections.getTypesAnnotatedWith(annotationClazz), PAGE_PREDICATE);
}
 
Example #10
Source File: NavigationProviderImpl.java    From AppStash with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked") // apache commons collection api does not support generics
public static Set<Class<? extends Page>> getAnnotatedWicketPage(String packageScanPath, Class<? extends Annotation> annotationClazz) {
    Reflections reflections = new Reflections(packageScanPath);
    return SetUtils.predicatedSet(reflections.getTypesAnnotatedWith(annotationClazz), PAGE_PREDICATE);
}
 
Example #11
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetAPIForPublishing() throws Exception {
    API expectedAPI = getUniqueAPI();

    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.getPolicyName()).thenReturn("policy");
    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));
}
 
Example #12
Source File: IndirectAgentLBShuffleAlgorithm.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
@Override
public boolean compare(List<String> msList, List<String> receivedMsList) {
    return SetUtils.isEqualSet(msList, receivedMsList);
}
 
Example #13
Source File: ReturnEmptySortedSet.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void return_empty_sorted_set_apache_commons () {

	@SuppressWarnings("unchecked")
	Set<String> emptySortedSet = SetUtils.EMPTY_SORTED_SET;
	
	assertTrue(emptySortedSet.isEmpty());

}