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:Numbers.java

public static void main(String[] args) {

    EnumSet<Numbers> set1 = EnumSet.of(Numbers.FOUR);

    System.out.println("Set1:" + set1);

    // create a set2 which has all elements that set1 doesn't have
    EnumSet<Numbers> set2 = EnumSet.complementOf(set1);

    System.out.println("Set2:" + set2);

}

From source file:com.github.fge.jackson.SampleNodeProvider.java

public static Iterator<Object[]> getSamplesExcept(final EnumSet<NodeType> types) {
    return getSamples(EnumSet.complementOf(types));
}

From source file:com.github.fge.jsonschema.keyword.digest.helpers.DraftV3TypeKeywordDigester.java

@Override
public JsonNode digest(final JsonNode schema) {
    final ObjectNode ret = FACTORY.objectNode();
    final ArrayNode simpleTypes = FACTORY.arrayNode();
    ret.put(keyword, simpleTypes);//from   w w  w.  j  a  v  a 2  s .  c om
    final ArrayNode schemas = FACTORY.arrayNode();
    ret.put("schemas", schemas);

    final JsonNode node = schema.get(keyword);

    final EnumSet<NodeType> set = EnumSet.noneOf(NodeType.class);

    if (node.isTextual()) // Single type
        putType(set, node.textValue());
    else { // More than one type, and possibly schemas
        final int size = node.size();
        JsonNode element;
        for (int index = 0; index < size; index++) {
            element = node.get(index);
            if (element.isTextual())
                putType(set, element.textValue());
            else
                schemas.add(index);
        }
    }

    /*
     * If all types are there, no need to collect schemas
     */
    if (EnumSet.complementOf(set).isEmpty())
        schemas.removeAll();

    /*
     * Note that as this is an enumset, order is guaranteed
     */
    for (final NodeType type : set)
        simpleTypes.add(type.toString());

    return ret;
}

From source file:org.eel.kitchen.jsonschema.keyword.TypeKeywordValidator.java

@Override
public boolean alwaysTrue() {
    return EnumSet.complementOf(typeSet).isEmpty();
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.SyntaxCheckersTest.java

/**
 * Constructor//from  w ww  . ja  v  a2  s .  c o m
 *
 * @param dict the {@link Dictionary} of {@link SyntaxChecker}s
 * @param prefix the prefix to use for resource files
 * @param keyword the keyword to test
 * @throws JsonProcessingException source JSON (if any) is not legal JSON
 */
protected SyntaxCheckersTest(final Dictionary<SyntaxChecker> dict, final String prefix, final String keyword)
        throws JsonProcessingException {
    this.keyword = keyword;
    checker = dict.entries().get(keyword);
    invalidTypes = checker == null ? null : EnumSet.complementOf(checker.getValidTypes());
    /*
     * Try and load the data and affect pointers. Barf on invalid JSON.
     *
     * If IOException, it means no file (hopefully); affect a MissingNode
     * to both valueTests and pointerTests.
     */
    JsonNode valueTestsNode, pointerTestsNode;
    try {
        final String resource = "/syntax/" + prefix + '/' + keyword + ".json";
        final JsonNode data = JsonLoader.fromResource(resource);
        valueTestsNode = data.path("valueTests");
        pointerTestsNode = data.path("pointerTests");
    } catch (JsonProcessingException oops) {
        throw oops;
    } catch (IOException ignored) {
        valueTestsNode = MissingNode.getInstance();
        pointerTestsNode = MissingNode.getInstance();
    }

    valueTests = valueTestsNode;
    pointerTests = pointerTestsNode;
}

From source file:fr.ritaly.dungeonmaster.ai.CreatureManager.java

/**
 * Return the unoccupied sectors.//from  w  w  w  .  j a  v a  2s  .c  o  m
 *
 * @return the set of unoccupied sectors. Never returns null.
 */
public EnumSet<Sector> getFreeSectors() {
    return (creatures != null) ? EnumSet.complementOf(getOccupiedSectors()) : EnumSet.allOf(Sector.class);
}

From source file:com.spotify.apollo.elide.ElideResourceTest.java

@Test
public void shouldHaveNoRouteForDisabledMethod() throws Exception {
    EnumSet<Method> allButGet = EnumSet.complementOf(EnumSet.of(Method.GET));
    resource = ElideResource.builder(PREFIX, elide).enabledMethods(allButGet).build();

    assertThat(resource.routes().filter(r -> r.method().equals("GET")).findAny(), is(empty()));
}

From source file:de.appsolve.padelcampus.controller.pro.ProOperatorsController.java

@RequestMapping(method = POST, value = "newaccount")
public ModelAndView postNewAccount(HttpServletRequest request,
        @ModelAttribute("Model") CustomerRegistrationModel customerAccount, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("pro/newaccount", "Model", customerAccount);
    }/*from  w  w w. jav  a 2  s.  c o m*/
    try {
        if (StringUtils.isEmpty(customerAccount.getCustomer().getName())) {
            throw new Exception(msg.get("ProjectNameFormatRequirements"));
        }
        String projectName = customerAccount.getCustomer().getName().toLowerCase(Constants.DEFAULT_LOCALE)
                .replace(" ", "-");
        //verify dns name requirements
        if (!DNS_SUBDOMAIN_PATTERN.matcher(projectName).matches()) {
            throw new Exception(msg.get("ProjectNameFormatRequirements"));
        }

        //make sure customer does not exist yet
        Customer customer = customerDAO.findByName(projectName);
        if (customer != null) {
            throw new Exception(msg.get("ProjectAlreadyExists"));
        }

        String dnsHostname = environment.getProperty("DNS_HOSTNAME");
        String cloudflareUrl = environment.getProperty("CLOUDFLARE_URL");
        //create DNS subdomain in cloudflare
        String domainName = cloudFlareApiClient.addCnameRecord(projectName, cloudflareUrl, dnsHostname);

        //save customer to DB
        HashSet<String> domainNames = new HashSet<>();
        domainNames.add(domainName);
        customerAccount.getCustomer().setDomainNames(domainNames);
        customer = customerDAO.saveOrUpdate(customerAccount.getCustomer());

        //create admin account in DB
        Player adminPlayer = playerDAO.findByEmail(customerAccount.getPlayer().getEmail());
        if (adminPlayer == null) {
            customerAccount.getPlayer().setCustomer(customer);
            adminPlayer = playerDAO.saveOrUpdate(customerAccount.getPlayer());
        }

        //create admin group in DB
        AdminGroup adminGroup = adminGroupDAO.findByAttribute("customer", customer);
        if (adminGroup == null) {
            adminGroup = new AdminGroup();
            adminGroup.setName(domainName + " Admins");
            EnumSet<Privilege> privileges = EnumSet.complementOf(EnumSet.of(Privilege.ManageCustomers));
            adminGroup.setPrivileges(privileges);
            adminGroup.setPlayers(new HashSet<>(Arrays.asList(new Player[] { adminPlayer })));
            adminGroup.setCustomer(customer);
            adminGroupDAO.saveOrUpdate(adminGroup);
        }

        //create all.min.css.stylesheet for new customer
        htmlResourceUtil.updateCss(servletContext, customer);

        Mail mail = new Mail();
        mail.addRecipient(getDefaultContact());
        mail.setSubject("New Customer Registration");
        mail.setBody(customer.toString());
        mailUtils.send(mail, request);

        return new ModelAndView("redirect:/pro/operators/newaccount/" + customer.getId());
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        errorReporter.notify(e);
        bindingResult.addError(new ObjectError("id", e.getMessage()));
        return new ModelAndView("pro/newaccount", "Model", customerAccount);
    }
}

From source file:com.github.fge.jsonschema.syntax.checkers.SyntaxCheckersTest.java

@Test(dependsOnMethods = "keywordIsSupportedInThisDictionary", dataProvider = "invalidTypes")
public final void invalidTypesAreReportedAsErrors(final JsonNode node) throws ProcessingException {
    final SchemaTree tree = treeFromValue(keyword, node);
    final NodeType type = NodeType.getNodeType(node);
    final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class);

    checker.checkSyntax(pointers, report, tree);

    verify(report).error(captor.capture());

    final ProcessingMessage msg = captor.getValue();
    assertMessage(msg).isSyntaxError(keyword, BUNDLE.getString("incorrectType"), tree)
            .hasField("expected", EnumSet.complementOf(invalidTypes)).hasField("found", type);
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.SyntaxCheckersTest.java

@Test(dependsOnMethods = "keywordIsSupportedInThisDictionary", dataProvider = "invalidTypes")
public final void invalidTypesAreReportedAsErrors(final JsonNode node) throws ProcessingException {
    final SchemaTree tree = treeFromValue(keyword, node);
    final NodeType type = NodeType.getNodeType(node);
    final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class);

    checker.checkSyntax(pointers, BUNDLE, report, tree);

    verify(report).error(captor.capture());

    final ProcessingMessage msg = captor.getValue();
    final String message = BUNDLE.printf("common.incorrectType", type, EnumSet.complementOf(invalidTypes));
    assertMessage(msg).isSyntaxError(keyword, message, tree)
            .hasField("expected", EnumSet.complementOf(invalidTypes)).hasField("found", type);
}