Example usage for java.util EnumSet complementOf

List of usage examples for java.util EnumSet complementOf

Introduction

In this page you can find the example usage for java.util EnumSet complementOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> complementOf(EnumSet<E> s) 

Source Link

Document

Creates an enum set with the same element type as the specified enum set, initially containing all the elements of this type that are not contained in the specified set.

Usage

From source file:com.googlecode.jmxtrans.model.output.InfluxDbWriterTests.java

@Test
public void onlyRequestedResultPropertiesAreAppliedAsTags() throws Exception {
    for (ResultAttribute expectedResultTag : ResultAttribute.values()) {
        ImmutableSet<ResultAttribute> expectedResultTags = ImmutableSet.of(expectedResultTag);
        InfluxDbWriter writer = getTestInfluxDbWriterWithResultTags(expectedResultTags);
        writer.doWrite(dummyServer(), dummyQuery(), results);

        verify(influxDB, atLeastOnce()).write(messageCaptor.capture());
        BatchPoints batchPoints = messageCaptor.getValue();
        String lineProtocol = batchPoints.getPoints().get(0).lineProtocol();

        assertThat(lineProtocol).contains(enumValueToAttribute(expectedResultTag));
        EnumSet<ResultAttribute> unexpectedResultTags = EnumSet.complementOf(EnumSet.of(expectedResultTag));
        for (ResultAttribute unexpectedResultTag : unexpectedResultTags) {
            assertThat(lineProtocol).doesNotContain(enumValueToAttribute(unexpectedResultTag));
        }/*from  ww  w . j  a va2s .c o m*/
    }
}

From source file:gov.nih.nci.firebird.data.AbstractRegistrationTest.java

@Test
public void testIsCompleted_False() {
    EnumSet<RegistrationStatus> completedStatuses = EnumSet
            .complementOf(EnumSet.of(APPROVED, ACCEPTED, RETURNED));
    for (RegistrationStatus status : completedStatuses) {
        registration.setStatus(status);/* w  w  w  .  j av a  2  s .  c o m*/
        assertFalse(status + " should not be completed!", registration.isCompleted());
    }
}

From source file:fr.ritaly.dungeonmaster.champion.Party.java

/**
 * Tries adding the given champion to the party and if the operation
 * succeeded returns the location where the champion was added.
 *
 * @param champion//from w  w w. jav  a2s  . c o  m
 *            the champion to add to the party. Can't be null.
 * @return a location representing where the champion was successfully
 *         added.
 */
public Location addChampion(Champion champion) {
    Validate.notNull(champion, "The given champion is null");
    Validate.isTrue(!champions.containsValue(champion), "The given champion has already joined the party");
    if (isFull()) {
        throw new IllegalStateException("The party is already full");
    }

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s is joigning the party ...", champion.getName()));
    }

    final boolean wasEmpty = isEmpty(true);

    // Which locations are already occupied ?
    final EnumSet<Location> occupied;

    if (champions.isEmpty()) {
        occupied = EnumSet.noneOf(Location.class);
    } else {
        occupied = EnumSet.copyOf(champions.keySet());
    }

    // Free locations ?
    final EnumSet<Location> free = EnumSet.complementOf(occupied);

    if (log.isDebugEnabled()) {
        log.debug("Free locations = " + free);
    }

    // Get the first free location
    final Location location = free.iterator().next();

    champions.put(location, champion);

    // Listen to the events fired by the champion
    champion.addChangeListener(this);

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s.Location: %s", champion.getName(), location));
    }

    // Assign a color to this champion
    final Color color = pickColor();

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s.Color: %s", champion.getName(), color));
    }

    champion.setColor(color);
    champion.setParty(this);

    if (wasEmpty) {
        // This champion become the new leader
        setLeader(champion);
    }

    fireChangeEvent();

    if (log.isInfoEnabled()) {
        log.info(String.format("%s joined the party", champion.getName()));
    }

    return location;
}

From source file:gov.nih.nci.firebird.selenium2.tests.protocol.registration.ReviseReturnedRegistrationFormsTest.java

private void checkFormsAreRevised(FormTypeEnum... forms) {
    dataSet.reload();//from   w ww.ja v a 2 s. c  om
    registration = dataSet.getInvestigatorRegistration();
    EnumSet<FormTypeEnum> revisedFormTypes;
    if (forms.length == 0) {
        revisedFormTypes = EnumSet.noneOf(FormTypeEnum.class);
    } else {
        revisedFormTypes = EnumSet.copyOf(Arrays.asList(forms));
    }
    checkFormsRevised(revisedFormTypes);
    EnumSet<FormTypeEnum> notRevisedFormTypes = EnumSet.complementOf(revisedFormTypes);
    checkFormsNotRevised(notRevisedFormTypes);
}

From source file:gov.nih.nci.firebird.data.AbstractRegistrationTest.java

@Test
public void testIsSubmittable_False() {
    EnumSet<RegistrationStatus> submittableNotExpected = EnumSet
            .complementOf(AbstractProtocolRegistration.SUBMITTABLE_STATUSES);
    for (RegistrationStatus status : submittableNotExpected) {
        registration.setStatus(status);/*  w  w w  .  j  av  a 2s .  com*/
        assertFalse(status.name(), registration.isSubmittable());
    }
}

From source file:gov.nih.nci.firebird.data.AbstractRegistrationTest.java

@Test
public void testIsNotificationNotRequiredForUpdate_False() {
    EnumSet<RegistrationStatus> requiredNotExpected = EnumSet
            .complementOf(AbstractProtocolRegistration.NOTIFICATION_REQUIRED_ON_UPDATE_STATUSES);
    for (RegistrationStatus status : requiredNotExpected) {
        registration.setStatus(status);//  w  w  w .j av  a2  s  .c o m
        assertFalse(status.name(), registration.isNotificationRequiredForUpdate());
    }
}

From source file:gov.nih.nci.firebird.data.AbstractRegistrationTest.java

@Test
public void testIsResubmitRequiredForUpdate_False() {
    EnumSet<RegistrationStatus> resubmitNotExpected = EnumSet
            .complementOf(AbstractProtocolRegistration.RESUBMIT_REQUIRED_ON_UPDATE_STATUSES);
    for (RegistrationStatus status : resubmitNotExpected) {
        registration.setStatus(status);//from  ww w .ja  va2  s  .co  m
        assertFalse(status.name(), registration.isResubmitRequiredForUpdate());
    }
}

From source file:gov.nih.nci.firebird.data.AbstractRegistrationTest.java

@Test
public void testIsReviewable_False() {
    EnumSet<RegistrationStatus> nonReviewableStatuses = EnumSet
            .complementOf(AbstractRegistration.REVIEWABLE_STATUSES);
    for (RegistrationStatus status : nonReviewableStatuses) {
        registration.setStatus(status);//from w w  w. j  av a  2 s .co m
        assertFalse(status + " should not be reviewable!", registration.isReviewable());
    }
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java

private void validateUri(EnumSet<MobileServiceSystemProperty> systemProperties, String requestUri) {
    if (!systemProperties.isEmpty()) {
        assertTrue(requestUri.contains("__systemproperties"));
    } else {/*w w  w .j  a v a 2s . co m*/
        assertFalse(requestUri.contains("__systemproperties"));
    }

    if (EnumSet.complementOf(systemProperties).isEmpty()) {
        assertTrue(requestUri.contains("__systemproperties=*"));
    } else if (systemProperties.contains(MobileServiceSystemProperty.CreatedAt)) {
        assertTrue(requestUri.contains("__createdAt"));
    } else if (systemProperties.contains(MobileServiceSystemProperty.UpdatedAt)) {
        assertTrue(requestUri.contains("__updatedAt"));
    } else if (systemProperties.contains(MobileServiceSystemProperty.Version)) {
        assertTrue(requestUri.contains("__version"));
    }
}

From source file:nl.strohalm.cyclos.controls.customization.fields.EditCustomFieldAction.java

@Override
protected void prepareForm(final ActionContext context) throws Exception {
    final HttpServletRequest request = context.getRequest();
    final EditCustomFieldForm form = context.getForm();
    final long id = form.getFieldId();
    final CustomField.Nature nature = getNature(form);
    CustomField field;//from ww w .j a v a2s  . c  o  m
    final BaseCustomFieldService<CustomField> service = resolveService(nature);
    if (id <= 0L) {
        field = nature.getEntityType().newInstance();
        switch (nature) {
        case OPERATOR:
            ((OperatorCustomField) field).setMember((Member) context.getElement());
            break;
        case MEMBER_RECORD:
            final MemberRecordType memberRecordType = memberRecordTypeService
                    .load(form.getMemberRecordTypeId());
            ((MemberRecordCustomField) field).setMemberRecordType(memberRecordType);
            break;
        case PAYMENT:
            final TransferType transferType = transferTypeService.load(form.getTransferTypeId());
            ((PaymentCustomField) field).setTransferType(transferType);
            break;
        }
        // Retrieve the possible parent fields
        final List<? extends CustomField> possibleParentFields = service.listPossibleParentFields(field);
        request.setAttribute("possibleParentFields", possibleParentFields);
    } else {
        field = service.load(id);

        // Get the possible values according to the selected parent value, if any
        Collection<CustomFieldPossibleValue> possibleValues;
        final CustomField parent = field.getParent();
        if (parent == null) {
            // No parent - use all
            possibleValues = field.getPossibleValues(false);
        } else {
            final long parentValueId = form.getParentValueId();
            CustomFieldPossibleValue parentValue = null;
            if (parentValueId > 0L) {
                // There's a parent value - load it
                parentValue = service.loadPossibleValue(parentValueId);
            } else {
                // No parent value selected - check whether the parent has at least one and select it
                if (parent != null && CollectionUtils.isNotEmpty(parent.getPossibleValues(false))) {
                    parentValue = parent.getPossibleValues(false).iterator().next();
                    form.setParentValueId(parentValue.getId());
                }
            }
            possibleValues = field.getPossibleValuesByParent(parentValue, false);
        }
        request.setAttribute("possibleValues", possibleValues);
    }

    getDataBinder(nature).writeAsString(form.getField(), field);
    request.setAttribute("field", field);
    request.setAttribute("nature", nature.name());
    RequestHelper.storeEnum(request, CustomField.Control.class, "controls");
    RequestHelper.storeEnum(request, CustomField.Type.class, "types");
    RequestHelper.storeEnum(request, CustomField.Size.class, "sizes");

    // Check the whether the field can be managed
    boolean canManage = false;
    switch (nature) {
    case OPERATOR:
        canManage = permissionService.hasPermission(MemberPermission.OPERATORS_MANAGE);
        break;
    case MEMBER_RECORD:
        canManage = permissionService.hasPermission(AdminSystemPermission.MEMBER_RECORD_TYPES_MANAGE);
        break;
    case PAYMENT:
        final PaymentCustomField paymentField = (PaymentCustomField) field;
        final TransferType backToTransferType = transferTypeService
                .load(paymentField.getTransferType().getId());
        if (paymentField.getTransferType().equals(backToTransferType)) {
            // When should back to another TT, the form is not editable
            canManage = permissionService.hasPermission(AdminSystemPermission.ACCOUNTS_MANAGE);
        }
        request.setAttribute("backToTransferType", backToTransferType);
        break;
    default:
        canManage = permissionService.hasPermission(AdminSystemPermission.CUSTOM_FIELDS_MANAGE);
        break;
    }
    request.setAttribute("canManage", canManage);

    // Store specific nature values
    final GroupQuery groupQuery = new GroupQuery();
    groupQuery.setStatus(Group.Status.NORMAL);
    switch (nature) {
    case MEMBER:
        // View may be any access level but WEB_SERVICE
        request.setAttribute("accessForView",
                EnumSet.complementOf(EnumSet.of(MemberCustomField.Access.WEB_SERVICE)));
        // Edit access level can be any but OTHER and WEB_SERVICE
        request.setAttribute("accessForEdit", EnumSet.complementOf(
                EnumSet.of(MemberCustomField.Access.OTHER, MemberCustomField.Access.WEB_SERVICE)));
        // The member search and ads search includes WEB_SERVICE
        request.setAttribute("memberAndAdsAccess",
                EnumSet.of(MemberCustomField.Access.NONE, MemberCustomField.Access.WEB_SERVICE,
                        MemberCustomField.Access.ADMIN, MemberCustomField.Access.BROKER,
                        MemberCustomField.Access.MEMBER));
        // The others (searches, etc.) are only NONE, ADMIN, BROKER or MEMBER
        request.setAttribute("access", EnumSet.of(MemberCustomField.Access.NONE, MemberCustomField.Access.ADMIN,
                MemberCustomField.Access.BROKER, MemberCustomField.Access.MEMBER));
        groupQuery.setNatures(Group.Nature.MEMBER, Group.Nature.BROKER);
        request.setAttribute("groups", groupService.search(groupQuery));
        RequestHelper.storeEnum(request, MemberCustomField.Indexing.class, "indexings");
        break;
    case ADMIN:
        groupQuery.setNatures(Group.Nature.ADMIN);
        request.setAttribute("groups", groupService.search(groupQuery));
        break;
    case OPERATOR:
        RequestHelper.storeEnum(request, OperatorCustomField.Visibility.class, "visibilities");
        break;
    case AD:
        RequestHelper.storeEnum(request, AdCustomField.Visibility.class, "visibilities");
        break;
    case MEMBER_RECORD:
        final MemberRecordCustomField memberRecordCustomField = (MemberRecordCustomField) field;
        request.setAttribute("memberRecordType", memberRecordCustomField.getMemberRecordType());
        RequestHelper.storeEnum(request, MemberRecordCustomField.Access.class, "accesses");
        break;
    case PAYMENT:
        final PaymentCustomField paymentCustomField = (PaymentCustomField) field;
        final TransferType transferType = paymentCustomField.getTransferType();
        request.setAttribute("transferType", transferType);
        final Set<PaymentCustomField.Access> accesses = EnumSet.allOf(PaymentCustomField.Access.class);
        if (paymentCustomField.getTransferType().getFixedDestinationMember() == null) {
            accesses.remove(PaymentCustomField.Access.DESTINATION_MEMBER);
        }
        request.setAttribute("accesses", accesses);
        break;
    }
}