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:org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.java

/**
 * Build up a metadata list of blobs in an Azure blob directory. This method
 * uses a in-order first traversal of blob directory structures to maintain
 * the sorted order of the blob names.//w  w  w  .  jav  a 2 s  .c o  m
 * 
 * @param aCloudBlobDirectory Azure blob directory
 * @param aFileMetadataList a list of file metadata objects for each
 *                          non-directory blob.
 * @param maxListingCount maximum length of the built up list.
 */
private void buildUpList(CloudBlobDirectoryWrapper aCloudBlobDirectory,
        ArrayList<FileMetadata> aFileMetadataList, final int maxListingCount, final int maxListingDepth)
        throws Exception {

    // Push the blob directory onto the stack.
    //
    AzureLinkedStack<Iterator<ListBlobItem>> dirIteratorStack = new AzureLinkedStack<Iterator<ListBlobItem>>();

    Iterable<ListBlobItem> blobItems = aCloudBlobDirectory.listBlobs(null, false,
            EnumSet.of(BlobListingDetails.METADATA), null, getInstrumentedContext());
    Iterator<ListBlobItem> blobItemIterator = blobItems.iterator();

    if (0 == maxListingDepth || 0 == maxListingCount) {
        // Recurrence depth and listing count are already exhausted. Return
        // immediately.
        return;
    }

    // The directory listing depth is unbounded if the maximum listing depth
    // is negative.
    final boolean isUnboundedDepth = (maxListingDepth < 0);

    // Reset the current directory listing depth.
    int listingDepth = 1;

    // Loop until all directories have been traversed in-order. Loop only
    // the following conditions are satisfied:
    // (1) The stack is not empty, and
    // (2) maxListingCount > 0 implies that the number of items in the
    // metadata list is less than the max listing count.
    while (null != blobItemIterator && (maxListingCount <= 0 || aFileMetadataList.size() < maxListingCount)) {
        while (blobItemIterator.hasNext()) {
            // Check if the count of items on the list exhausts the maximum
            // listing count.
            //
            if (0 < maxListingCount && aFileMetadataList.size() >= maxListingCount) {
                break;
            }

            ListBlobItem blobItem = blobItemIterator.next();

            // Add the file metadata to the list if this is not a blob
            // directory item.
            //
            if (blobItem instanceof CloudBlockBlobWrapper || blobItem instanceof CloudPageBlobWrapper) {
                String blobKey = null;
                CloudBlobWrapper blob = (CloudBlobWrapper) blobItem;
                BlobProperties properties = blob.getProperties();

                // Determine format of the blob name depending on whether an absolute
                // path is being used or not.
                blobKey = normalizeKey(blob);

                FileMetadata metadata;
                if (retrieveFolderAttribute(blob)) {
                    metadata = new FileMetadata(blobKey, properties.getLastModified().getTime(),
                            getPermissionStatus(blob), BlobMaterialization.Explicit);
                } else {
                    metadata = new FileMetadata(blobKey, getDataLength(blob, properties),
                            properties.getLastModified().getTime(), getPermissionStatus(blob));
                }

                // Add the directory metadata to the list only if it's not already
                // there.
                FileMetadata existing = getDirectoryInList(aFileMetadataList, blobKey);
                if (existing != null) {
                    aFileMetadataList.remove(existing);
                }
                aFileMetadataList.add(metadata);
            } else if (blobItem instanceof CloudBlobDirectoryWrapper) {
                CloudBlobDirectoryWrapper directory = (CloudBlobDirectoryWrapper) blobItem;

                // This is a directory blob, push the current iterator onto
                // the stack of iterators and start iterating through the current
                // directory.
                if (isUnboundedDepth || maxListingDepth > listingDepth) {
                    // Push the current directory on the stack and increment the listing
                    // depth.
                    dirIteratorStack.push(blobItemIterator);
                    ++listingDepth;

                    // The current blob item represents the new directory. Get
                    // an iterator for this directory and continue by iterating through
                    // this directory.
                    blobItems = directory.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), null,
                            getInstrumentedContext());
                    blobItemIterator = blobItems.iterator();
                } else {
                    // Determine format of directory name depending on whether an
                    // absolute path is being used or not.
                    String dirKey = normalizeKey(directory);

                    if (getDirectoryInList(aFileMetadataList, dirKey) == null) {
                        // Reached the targeted listing depth. Return metadata for the
                        // directory using default permissions.
                        //
                        // Note: Something smarter should be done about permissions. Maybe
                        // inherit the permissions of the first non-directory blob.
                        // Also, getting a proper value for last-modified is tricky.
                        //
                        FileMetadata directoryMetadata = new FileMetadata(dirKey, 0,
                                defaultPermissionNoBlobMetadata(), BlobMaterialization.Implicit);

                        // Add the directory metadata to the list.
                        aFileMetadataList.add(directoryMetadata);
                    }
                }
            }
        }

        // Traversal of directory tree

        // Check if the iterator stack is empty. If it is set the next blob
        // iterator to null. This will act as a terminator for the for-loop.
        // Otherwise pop the next iterator from the stack and continue looping.
        //
        if (dirIteratorStack.isEmpty()) {
            blobItemIterator = null;
        } else {
            // Pop the next directory item from the stack and decrement the
            // depth.
            blobItemIterator = dirIteratorStack.pop();
            --listingDepth;

            // Assertion: Listing depth should not be less than zero.
            if (listingDepth < 0) {
                throw new AssertionError("Non-negative listing depth expected");
            }
        }
    }
}

From source file:de.escidoc.core.aa.business.UserAccountHandler.java

/**
 * See Interface for functional description.
 *
 * @param parameters parameter map//from  www  .  j  av a 2s .co  m
 * @return filter sub query with permission rules
 * @throws SystemException             e
 * @throws InvalidSearchQueryException e
 */
@Override
public String retrievePermissionFilterQuery(final Map<String, String[]> parameters)
        throws InvalidSearchQueryException, SystemException {
    final Set<ResourceType> resourceTypes = EnumSet.noneOf(ResourceType.class);
    final String[] types = parameters.get("index");
    if (types != null) {
        final Collection<String> hashedTypes = new HashSet<String>();
        hashedTypes.addAll(Arrays.asList(types));
        final Map<String, Map<String, Map<String, Object>>> objectTypeParameters = this.indexingHandler
                .getObjectTypeParameters();
        for (final Entry<String, Map<String, Map<String, Object>>> entry : objectTypeParameters.entrySet()) {
            final Map<String, Map<String, Object>> index = entry.getValue();
            for (final String indexName : index.keySet()) {
                if (hashedTypes.contains(indexName)) {
                    resourceTypes.add(ResourceType.getResourceTypeFromUri(entry.getKey()));
                }
            }
        }
    }
    return Utility.prepareReturnXml(null, "<filter>" + permissionsQuery.getFilterQuery(resourceTypes,
            this.utility.getCurrentUserId(), new FilterInterface() {
                @Override
                public String getRoleId() {
                    final String[] parameter = parameters.get("role");

                    return parameter != null && parameter.length > 0 ? parameter[0] : null;
                }

                @Override
                public String getUserId() {
                    final String[] parameter = parameters.get("user");

                    return parameter != null && parameter.length > 0 ? parameter[0] : null;
                }

                @Override
                public String toString() {
                    return "[userId=" + getUserId() + ",roleId=" + getRoleId() + ']';
                }
            }) + "</filter>");
}

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

/**
 * Flushes out to all replicas of the block. The data is in the buffers
 * of the DNs but not necessarily in the DN's OS buffers.
 * /*  w w  w  .j a v a2s  .com*/
 * It is a synchronous operation. When it returns,
 * it guarantees that flushed data become visible to new readers.
 * It is not guaranteed that data has been flushed to
 * persistent store on the datanode.
 * Block allocations are persisted on namenode.
 */
@Override
public void hflush() throws IOException {
    TraceScope scope = dfsClient.getPathTraceScope("hflush", src);
    try {
        flushOrSync(false, EnumSet.noneOf(SyncFlag.class));
    } finally {
        scope.close();
    }
}

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

@Override
public void hsync() throws IOException {
    TraceScope scope = dfsClient.getPathTraceScope("hsync", src);
    try {/*from  w  w w  .  j  av a2 s  . c  o  m*/
        flushOrSync(true, EnumSet.noneOf(SyncFlag.class));
    } finally {
        scope.close();
    }
}

From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java

/**
 * Retrieves the StudyAcl where the user/group belongs to.
 *
 * @param studyId study id./* www .  j  a  va  2s .  c  o m*/
 * @param userId user id.
 * @param groupId group id. This can be null.
 * @return the studyAcl where the user/group belongs to.
 * @throws CatalogException when there is any database error.
 */
StudyAclEntry getStudyAclBelonging(long studyId, String userId, @Nullable String groupId)
        throws CatalogException {
    List<String> members = (groupId != null) ? Arrays.asList(userId, groupId, OTHER_USERS_ID, ANONYMOUS)
            : Arrays.asList(userId, OTHER_USERS_ID, ANONYMOUS);

    QueryResult<StudyAclEntry> studyQueryResult = studyDBAdaptor.getAcl(studyId, members);
    Map<String, StudyAclEntry> userAclMap = studyQueryResult.getResult().stream()
            .collect(Collectors.toMap(StudyAclEntry::getMember, Function.identity()));

    if (userId.equals(ANONYMOUS)) {
        if (userAclMap.containsKey(userId)) {
            return userAclMap.get(userId);
        }
        return null;
    }

    // Registered user
    EnumSet<StudyAclEntry.StudyPermissions> permissions = EnumSet.noneOf(StudyAclEntry.StudyPermissions.class);
    boolean flagPermissionFound = false;

    if (userAclMap.containsKey(userId)) {
        permissions.addAll(userAclMap.get(userId).getPermissions());
        flagPermissionFound = true;
    }
    if (StringUtils.isNotEmpty(groupId) && userAclMap.containsKey(groupId)) {
        permissions.addAll(userAclMap.get(groupId).getPermissions());
        flagPermissionFound = true;
    }
    if (userAclMap.containsKey(ANONYMOUS)) {
        permissions.addAll(userAclMap.get(ANONYMOUS).getPermissions());
        flagPermissionFound = true;
    }
    if (userAclMap.containsKey(OTHER_USERS_ID)) {
        permissions.addAll(userAclMap.get(OTHER_USERS_ID).getPermissions());
        flagPermissionFound = true;
    }

    if (flagPermissionFound) {
        return new StudyAclEntry(userId, permissions);
    }
    return null;
}

From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java

private FileAclEntry transformStudyAclToFileAcl(StudyAclEntry studyAcl) {
    FileAclEntry fileAcl = new FileAclEntry(null, Collections.emptyList());
    if (studyAcl == null) {
        return fileAcl;
    }//  w  w  w.  j a  v a  2s.c  o m

    fileAcl.setMember(studyAcl.getMember());
    EnumSet<StudyAclEntry.StudyPermissions> studyPermissions = studyAcl.getPermissions();
    EnumSet<FileAclEntry.FilePermissions> filePermissions = EnumSet.noneOf(FileAclEntry.FilePermissions.class);

    for (StudyAclEntry.StudyPermissions studyPermission : studyPermissions) {
        FileAclEntry.FilePermissions aux = studyPermission.getFilePermission();
        if (aux != null) {
            filePermissions.add(aux);
        }
    }
    fileAcl.setPermissions(filePermissions);
    return fileAcl;
}

From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java

private SampleAclEntry transformStudyAclToSampleAcl(StudyAclEntry studyAcl) {
    SampleAclEntry sampleAcl = new SampleAclEntry(null, Collections.emptyList());
    if (studyAcl == null) {
        return sampleAcl;
    }/*from ww  w. j a va2s  .c  o m*/

    sampleAcl.setMember(studyAcl.getMember());
    EnumSet<StudyAclEntry.StudyPermissions> studyPermissions = studyAcl.getPermissions();
    EnumSet<SampleAclEntry.SamplePermissions> samplePermission = EnumSet
            .noneOf(SampleAclEntry.SamplePermissions.class);

    for (StudyAclEntry.StudyPermissions studyPermission : studyPermissions) {
        SampleAclEntry.SamplePermissions aux = studyPermission.getSamplePermission();
        if (aux != null) {
            samplePermission.add(aux);
        }
    }
    sampleAcl.setPermissions(samplePermission);
    return sampleAcl;
}

From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java

private IndividualAclEntry transformStudyAclToIndividualAcl(StudyAclEntry studyAcl) {
    IndividualAclEntry individualAcl = new IndividualAclEntry(null, Collections.emptyList());
    if (studyAcl == null) {
        return individualAcl;
    }//from  w w  w.  java2  s . c o m

    individualAcl.setMember(studyAcl.getMember());
    EnumSet<StudyAclEntry.StudyPermissions> studyPermissions = studyAcl.getPermissions();
    EnumSet<IndividualAclEntry.IndividualPermissions> individualPermissions = EnumSet
            .noneOf(IndividualAclEntry.IndividualPermissions.class);

    for (StudyAclEntry.StudyPermissions studyPermission : studyPermissions) {
        IndividualAclEntry.IndividualPermissions aux = studyPermission.getIndividualPermission();
        if (aux != null) {
            individualPermissions.add(aux);
        }
    }
    individualAcl.setPermissions(individualPermissions);
    return individualAcl;
}

From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java

private JobAclEntry transformStudyAclToJobAcl(StudyAclEntry studyAcl) {
    JobAclEntry jobAcl = new JobAclEntry(null, Collections.emptyList());
    if (studyAcl == null) {
        return jobAcl;
    }//www  .java 2  s  . c o  m

    jobAcl.setMember(studyAcl.getMember());
    EnumSet<StudyAclEntry.StudyPermissions> studyPermissions = studyAcl.getPermissions();
    EnumSet<JobAclEntry.JobPermissions> jobPermissions = EnumSet.noneOf(JobAclEntry.JobPermissions.class);

    for (StudyAclEntry.StudyPermissions studyPermission : studyPermissions) {
        JobAclEntry.JobPermissions aux = studyPermission.getJobPermission();
        if (aux != null) {
            jobPermissions.add(aux);
        }
    }
    jobAcl.setPermissions(jobPermissions);
    return jobAcl;
}

From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java

private CohortAclEntry transformStudyAclToCohortAcl(StudyAclEntry studyAcl) {
    CohortAclEntry cohortAcl = new CohortAclEntry(null, Collections.emptyList());
    if (studyAcl == null) {
        return cohortAcl;
    }/*w ww.j  a v  a  2 s.c  o  m*/

    cohortAcl.setMember(studyAcl.getMember());
    EnumSet<StudyAclEntry.StudyPermissions> studyPermissions = studyAcl.getPermissions();
    EnumSet<CohortAclEntry.CohortPermissions> cohortPermissions = EnumSet
            .noneOf(CohortAclEntry.CohortPermissions.class);

    for (StudyAclEntry.StudyPermissions studyPermission : studyPermissions) {
        CohortAclEntry.CohortPermissions aux = studyPermission.getCohortPermission();
        if (aux != null) {
            cohortPermissions.add(aux);
        }
    }
    cohortAcl.setPermissions(cohortPermissions);
    return cohortAcl;
}