Example usage for java.util EnumSet noneOf

List of usage examples for java.util EnumSet noneOf

Introduction

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

Prototype

public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) 

Source Link

Document

Creates an empty enum set with the specified element type.

Usage

From source file:com.github.pjungermann.config.specification.constraint.inetAddress.InetAddressConstraint.java

@Nullable
protected EnumSet<InetAddressType> asCheckedEnumSet(Collection collection) {
    EnumSet<InetAddressType> set = EnumSet.noneOf(InetAddressType.class);

    for (Object item : collection) {
        if (item instanceof String) {
            InetAddressType type = InetAddressType.valueOfIgnoreCase((String) item);
            if (type == null) {
                return null;
            }/*w  ww.j  av a  2 s  .  c o m*/
            set.add(type);

        } else if (item instanceof InetAddressType) {
            set.add((InetAddressType) item);

        } else {
            return null;
        }
    }

    return set;
}

From source file:de.blizzy.documentr.web.access.RoleController.java

@RequestMapping(value = "/save", method = RequestMethod.POST)
@PreAuthorize("hasApplicationPermission(ADMIN)")
public String saveRole(@ModelAttribute @Valid RoleForm form, BindingResult bindingResult,
        Authentication authentication) throws IOException {

    if (StringUtils.isNotBlank(form.getName()) && (StringUtils.isBlank(form.getOriginalName())
            || !form.getName().equals(form.getOriginalName()))) {

        try {//from  w w  w. j  a v a 2  s . c o  m
            if (userStore.getRole(form.getName()) != null) {
                bindingResult.rejectValue("name", "role.name.exists"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        } catch (RoleNotFoundException e) {
            // okay
        }
    }

    if (bindingResult.hasErrors()) {
        return "/user/role/edit"; //$NON-NLS-1$
    }

    EnumSet<Permission> permissions = EnumSet.noneOf(Permission.class);
    for (String permission : form.getPermissions()) {
        permissions.add(Permission.valueOf(permission));
    }
    String newRoleName = form.getOriginalName();
    if (StringUtils.isBlank(newRoleName)) {
        newRoleName = form.getName();
    }
    Role role = new Role(newRoleName, permissions);
    User user = userStore.getUser(authentication.getName());
    userStore.saveRole(role, user);

    if (StringUtils.isNotBlank(form.getOriginalName()) && StringUtils.isNotBlank(form.getName())
            && !StringUtils.equals(form.getName(), form.getOriginalName())) {

        userStore.renameRole(form.getOriginalName(), form.getName(), user);
    }

    return "redirect:/roles"; //$NON-NLS-1$
}

From source file:org.pentaho.platform.repository2.unified.jcr.DefaultPermissionConversionHelper.java

public EnumSet<RepositoryFilePermission> privilegesToPentahoPermissions(final Session session,
        final Privilege[] privileges) throws RepositoryException {
    Assert.notNull(session);// w  w w. j a  v a2  s.  c  o m
    Assert.notNull(privileges);

    new PentahoJcrConstants(session);
    EnumSet<RepositoryFilePermission> permissions = EnumSet.noneOf(RepositoryFilePermission.class);

    Privilege[] expandedPrivileges = JcrRepositoryFileAclUtils.expandPrivileges(privileges, true);

    for (Privilege privilege : expandedPrivileges) {
        // this privilege name is of the format xyz:blah where xyz is the namespace prefix;
        // convert it to match the Privilege.JCR_* string constants
        String extendedPrivilegeName = privilege.getName();
        String privilegeName = privilege.getName();
        int colonIndex = privilegeName.indexOf(":"); //$NON-NLS-1$
        if (colonIndex > -1) {
            String namespaceUri = session.getNamespaceURI(privilegeName.substring(0, colonIndex));
            extendedPrivilegeName = "{" + namespaceUri + "}" + privilegeName.substring(colonIndex + 1); //$NON-NLS-1$ //$NON-NLS-2$
        }

        if (privilegeNameToPermissionEnumsMap.containsKey(extendedPrivilegeName)) {
            Collection<RepositoryFilePermission> permEnums = privilegeNameToPermissionEnumsMap
                    .get(extendedPrivilegeName);
            for (RepositoryFilePermission perm : permEnums) {
                permissions.add(perm);
            }
        } else {
            logger.debug("skipping privilege with name=" + extendedPrivilegeName //$NON-NLS-1$
                    + " as it doesn't have any corresponding permissions"); //$NON-NLS-1$
        }
    }

    Assert.isTrue(!permissions.isEmpty(), "no permissions; see previous 'skipping privilege' messages");

    return permissions;
}

From source file:com.cloudera.ByteBufferRecordReader.java

private void initialize(Configuration job, long splitStart, long splitLength, Path file) throws IOException {
    start = splitStart;//from   w w w  .ja v  a2s.  com
    end = start + splitLength;
    pos = start;

    // open the file and seek to the start of the split
    final FileSystem fs = file.getFileSystem(job);
    fileIn = fs.open(file);

    this.readStats = new ReadStatistics();
    this.bufferPool = new ElasticByteBufferPool();
    boolean skipChecksums = job.getBoolean("bytecount.skipChecksums", false);
    this.readOption = skipChecksums ? EnumSet.of(ReadOption.SKIP_CHECKSUMS) : EnumSet.noneOf(ReadOption.class);

    CompressionCodec codec = new CompressionCodecFactory(job).getCodec(file);
    if (null != codec) {
        isCompressedInput = true;
        decompressor = CodecPool.getDecompressor(codec);
        CompressionInputStream cIn = codec.createInputStream(fileIn, decompressor);
        filePosition = cIn;
        inputStream = cIn;
        LOG.info("Compressed input; cannot compute number of records in the split");
    } else {
        fileIn.seek(start);
        filePosition = fileIn;
        inputStream = fileIn;
        LOG.info("Split pos = " + start + " length " + splitLength);
    }
}

From source file:com.opengamma.engine.fudgemsg.ExecutionOptionsFudgeBuilder.java

@Override
public ExecutionOptions buildObject(FudgeDeserializer deserializer, FudgeMsg message) {
    ViewCycleExecutionSequence executionSequence = deserializer
            .fudgeMsgToObject(ViewCycleExecutionSequence.class, message.getMessage(EXECUTION_SEQUENCE_FIELD));
    EnumSet<ViewExecutionFlags> flags = EnumSet.noneOf(ViewExecutionFlags.class);
    for (Pair<String, ViewExecutionFlags> flagField : s_flags) {
        if (BooleanUtils.isTrue(message.getBoolean(flagField.getFirst()))) {
            flags.add(flagField.getSecond());
        }//w  w  w  .ja v  a 2 s.c  om
    }
    Integer maxSuccessiveDeltaCycles = null;
    if (message.hasField(MAX_SUCCESSIVE_DELTA_CYCLES_FIELD)) {
        maxSuccessiveDeltaCycles = message.getInt(MAX_SUCCESSIVE_DELTA_CYCLES_FIELD);
    }
    FudgeField defaultExecutionOptionsField = message.getByName(DEFAULT_EXECUTION_OPTIONS_FIELD);
    ViewCycleExecutionOptions defaultExecutionOptions = defaultExecutionOptionsField != null
            ? deserializer.fieldValueToObject(ViewCycleExecutionOptions.class, defaultExecutionOptionsField)
            : null;

    return new ExecutionOptions(executionSequence, flags, maxSuccessiveDeltaCycles, defaultExecutionOptions);
}

From source file:com.alcatel_lucent.nz.wnmsextract.WNMSDataExtractor.java

/**
 * Null constructor sets up empty logger.
 */
public WNMSDataExtractor() {
    wdl = new DataLogger(EnumSet.noneOf(LogAppType.class), slog);
}

From source file:com.mellanox.r4h.TestHFlush.java

/**
 * The test uses//from  ww  w. j  ava2 s  .  c o m
 * {@link #doTheJob(Configuration, String, long, short, boolean, EnumSet)} 
 * to write a file with a custom block size so the writes will be 
 * happening across block's and checksum' boundaries
 */
@Test
public void hFlush_03() throws IOException {
    Configuration conf = new HdfsConfiguration();
    int customPerChecksumSize = 400;
    int customBlockSize = customPerChecksumSize * 3;
    // Modify defaul filesystem settings
    conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY, customPerChecksumSize);
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, customBlockSize);

    doTheJob(conf, fName, customBlockSize, (short) 2, false, EnumSet.noneOf(SyncFlag.class));
}

From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingServiceTypeCalendar.java

private void parseCalendarFile(final Reader calendarReader, final Multimap<LocalDate, String> serviceTypesMap)
        throws IOException {

    final CSVParser calendarParser = new CSVParser(calendarReader, CSVFormat.DEFAULT.withHeader());
    final List<CSVRecord> calendarRecords = calendarParser.getRecords();

    LocalDate earliestDate = null;
    LocalDate latestDate = null;/*from ww  w.  j  a  v  a  2s  .c om*/
    for (final CSVRecord record : calendarRecords) {
        final String serviceType = record.get("service_id");

        final LocalDate start = LocalDate.parse(record.get("start_date"), DateTimeFormatter.BASIC_ISO_DATE);
        if (earliestDate == null || start.isBefore(earliestDate)) {
            earliestDate = start;
        }

        final LocalDate end = LocalDate.parse(record.get("end_date"), DateTimeFormatter.BASIC_ISO_DATE);
        if (latestDate == null || end.isAfter(latestDate)) {
            latestDate = end;
        }

        final EnumSet<DayOfWeek> daysOfWeek = EnumSet.noneOf(DayOfWeek.class);
        if (record.get("monday").equals("1")) {
            daysOfWeek.add(DayOfWeek.MONDAY);
        }
        if (record.get("tuesday").equals("1")) {
            daysOfWeek.add(DayOfWeek.TUESDAY);
        }
        if (record.get("wednesday").equals("1")) {
            daysOfWeek.add(DayOfWeek.WEDNESDAY);
        }
        if (record.get("thursday").equals("1")) {
            daysOfWeek.add(DayOfWeek.THURSDAY);
        }
        if (record.get("friday").equals("1")) {
            daysOfWeek.add(DayOfWeek.FRIDAY);
        }
        if (record.get("saturday").equals("1")) {
            daysOfWeek.add(DayOfWeek.SATURDAY);
        }
        if (record.get("sunday").equals("1")) {
            daysOfWeek.add(DayOfWeek.SUNDAY);
        }

        LocalDate targetDate = start;
        while (!targetDate.isAfter(end)) {
            if (daysOfWeek.contains(targetDate.getDayOfWeek())) {
                serviceTypesMap.put(targetDate, serviceType);
            }
            targetDate = targetDate.plusDays(1);
        }
    }
}

From source file:org.rhq.plugins.iis.IISResponseTimeDelegate.java

public IISResponseTimeDelegate(String logDirectory, String logFormat,
        ResponseTimeConfiguration responseTimeConfiguration/*, boolean isAbsoluteTime*/) {
    if (logDirectory == null) {
        throw new IllegalArgumentException("logDirectory can not be null");
    }/*from  w w  w  .ja v  a2 s . c  om*/
    this.logDirectory = new File(logDirectory);

    // IIS always logs in UTC, even if the "Use local time for file naming and rollover" option is selected
    this.isAbsoluteTime = true;

    this.responseTimeConfiguration = responseTimeConfiguration;

    logTokenPositions = new HashMap<LogFormatToken, Integer>();
    String[] logFormatTokens = logFormat.split(" ");
    EnumSet<LogFormatToken> foundTokens = EnumSet.noneOf(LogFormatToken.class);
    for (int i = 0; i < logFormatTokens.length; i++) {
        String nextLiteral = logFormatTokens[i];
        LogFormatToken nextToken = LogFormatToken.getViaTokenLiteral(nextLiteral);
        if (nextToken != null) {
            if (foundTokens.contains(nextToken)) {
                // weird, but I suppose it's possible possible
                log.warn("Token '" + nextLiteral + "' was specified more than once");
            } else {
                log.debug("Required token found '" + nextLiteral + "' at position " + i);
                foundTokens.add(nextToken);
                logTokenPositions.put(nextToken, i);
            }
        } else {
            log.debug("Extra token found '" + nextLiteral + "' at position " + i);
        }
    }
    if (!foundTokens.containsAll(EnumSet.allOf(LogFormatToken.class))) {
        log.error(
                "Log format '" + logFormat + "' needs to include: " + LogFormatToken.getRequiredTokenString());
    }
}

From source file:edu.emory.cci.aiw.cvrg.eureka.services.translation.CategorizationTranslator.java

private CategoryType checkPropositionType(Category phenotype, List<PhenotypeEntity> inverseIsA)
        throws PhenotypeHandlingException {
    if (inverseIsA.isEmpty()) {
        throw new PhenotypeHandlingException(Response.Status.PRECONDITION_FAILED,
                "Category " + phenotype.getKey() + " is invalid because it has no children");
    }/*from ww w.  j a v a 2s.  c  o  m*/
    Set<CategoryType> categorizationTypes = EnumSet.noneOf(CategoryType.class);
    for (PhenotypeEntity phenotypeEntity : inverseIsA) {
        categorizationTypes.add(phenotypeEntity.getCategoryType());
    }
    if (categorizationTypes.size() > 1) {
        throw new PhenotypeHandlingException(Response.Status.PRECONDITION_FAILED,
                "Category " + phenotype.getKey() + " has children with inconsistent types: "
                        + StringUtils.join(categorizationTypes, ", "));
    }
    return categorizationTypes.iterator().next();
}