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.couchbase.lite.AttachmentsTest.java

@SuppressWarnings("unchecked")
public void testPutAttachment() throws CouchbaseLiteException {

    String testAttachmentName = "test_attachment";
    BlobStore attachments = database.getAttachments();
    attachments.deleteBlobs();//from   w  w w . j av a 2s  .c o  m
    Assert.assertEquals(0, attachments.count());

    // Put a revision that includes an _attachments dict:
    byte[] attach1 = "This is the body of attach1".getBytes();
    String base64 = Base64.encodeBytes(attach1);

    Map<String, Object> attachment = new HashMap<String, Object>();
    attachment.put("content_type", "text/plain");
    attachment.put("data", base64);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put(testAttachmentName, attachment);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", 1);
    properties.put("bar", false);
    properties.put("_attachments", attachmentDict);

    RevisionInternal rev1 = database.putRevision(new RevisionInternal(properties, database), null, false);

    // Examine the attachment store:
    Assert.assertEquals(1, attachments.count());

    // Get the revision:
    RevisionInternal gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(),
            EnumSet.noneOf(Database.TDContentOptions.class));
    Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");

    Map<String, Object> innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "text/plain");
    innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    innerDict.put("length", 27);
    innerDict.put("stub", true);
    innerDict.put("revpos", 1);

    Map<String, Object> expectAttachmentDict = new HashMap<String, Object>();
    expectAttachmentDict.put(testAttachmentName, innerDict);

    Assert.assertEquals(expectAttachmentDict, gotAttachmentDict);

    // Update the attachment directly:
    byte[] attachv2 = "Replaced body of attach".getBytes();
    boolean gotExpectedErrorCode = false;

    BlobStoreWriter blobWriter = new BlobStoreWriter(database.getAttachments());
    blobWriter.appendData(attachv2);
    blobWriter.finish();

    try {
        database.updateAttachment(testAttachmentName, blobWriter, "application/foo",
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocId(), null);
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.CONFLICT);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    gotExpectedErrorCode = false;
    try {
        database.updateAttachment(testAttachmentName, blobWriter, "application/foo",
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocId(), "1-bogus");
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.CONFLICT);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    gotExpectedErrorCode = false;
    RevisionInternal rev2 = null;
    try {
        rev2 = database.updateAttachment(testAttachmentName, blobWriter, "application/foo",
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocId(), rev1.getRevId());
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = true;
    }
    Assert.assertFalse(gotExpectedErrorCode);

    Assert.assertEquals(rev1.getDocId(), rev2.getDocId());
    Assert.assertEquals(2, rev2.getGeneration());

    // Get the updated revision:
    RevisionInternal gotRev2 = database.getDocumentWithIDAndRev(rev2.getDocId(), rev2.getRevId(),
            EnumSet.noneOf(Database.TDContentOptions.class));
    attachmentDict = (Map<String, Object>) gotRev2.getProperties().get("_attachments");

    innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "application/foo");
    innerDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk=");
    innerDict.put("length", 23);
    innerDict.put("stub", true);
    innerDict.put("revpos", 2);

    expectAttachmentDict.put(testAttachmentName, innerDict);

    Assert.assertEquals(expectAttachmentDict, attachmentDict);

    // Delete the attachment:
    gotExpectedErrorCode = false;
    try {
        database.updateAttachment("nosuchattach", null, null,
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev2.getDocId(), rev2.getRevId());
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.NOT_FOUND);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    gotExpectedErrorCode = false;
    try {
        database.updateAttachment("nosuchattach", null, null,
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, "nosuchdoc", "nosuchrev");
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.NOT_FOUND);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    RevisionInternal rev3 = database.updateAttachment(testAttachmentName, null, null,
            AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev2.getDocId(), rev2.getRevId());
    Assert.assertEquals(rev2.getDocId(), rev3.getDocId());
    Assert.assertEquals(3, rev3.getGeneration());

    // Get the updated revision:
    RevisionInternal gotRev3 = database.getDocumentWithIDAndRev(rev3.getDocId(), rev3.getRevId(),
            EnumSet.noneOf(Database.TDContentOptions.class));
    attachmentDict = (Map<String, Object>) gotRev3.getProperties().get("_attachments");
    Assert.assertNull(attachmentDict);

    database.close();
}

From source file:org.alfresco.filesys.AbstractServerConfigurationBean.java

/**
 * Parse the platforms attribute returning the set of platform ids
 * //w  w  w .  jav  a 2  s.c o  m
 * @param platformStr String
 */
protected final EnumSet<Platform.Type> parsePlatformString(String platformStr) {
    // Split the platform string and build up a set of platform types

    EnumSet<Platform.Type> platformTypes = EnumSet.noneOf(Platform.Type.class);
    if (platformStr == null || platformStr.length() == 0)
        return platformTypes;

    StringTokenizer token = new StringTokenizer(platformStr.toUpperCase(Locale.ENGLISH), ",");
    String typ = null;

    try {
        while (token.hasMoreTokens()) {

            // Get the current platform type string and validate

            typ = token.nextToken().trim();
            Platform.Type platform = Platform.Type.valueOf(typ);

            if (platform != Platform.Type.Unknown)
                platformTypes.add(platform);
            else
                throw new AlfrescoRuntimeException("Invalid platform type, " + typ);
        }
    } catch (IllegalArgumentException ex) {
        throw new AlfrescoRuntimeException("Invalid platform type, " + typ);
    }

    // Return the platform types

    return platformTypes;
}

From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystemTest.java

@Test
public void testGetFilesUnderPath() throws IOException {
    tmp.newFile("file1");
    tmp.newFolder("dir1");
    tmp.newFile("dir1/file2");
    tmp.newFolder("dir1/dir2");
    tmp.newFile("dir1/dir2/file3");

    assertThat(//from  w  ww .ja v  a  2s.  c o  m
            filesystem.getFilesUnderPath(Paths.get("dir1"), x -> true, EnumSet.noneOf(FileVisitOption.class)),
            containsInAnyOrder(Paths.get("dir1/file2"), Paths.get("dir1/dir2/file3")));

    assertThat(filesystem.getFilesUnderPath(Paths.get("dir1"), Paths.get("dir1/dir2/file3")::equals,
            EnumSet.noneOf(FileVisitOption.class)), containsInAnyOrder(Paths.get("dir1/dir2/file3")));

    assertThat(filesystem.getFilesUnderPath(Paths.get("dir1")),
            containsInAnyOrder(Paths.get("dir1/file2"), Paths.get("dir1/dir2/file3")));

    assertThat(filesystem.getFilesUnderPath(Paths.get("dir1"), Paths.get("dir1/file2")::equals),
            containsInAnyOrder(Paths.get("dir1/file2")));
}

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

private SampleAclEntry resolveSamplePermissions(long studyId, String userId, String groupId,
        Map<String, SampleAclEntry> userAclMap) throws CatalogException {
    if (userId.equals(ANONYMOUS)) {
        if (userAclMap.containsKey(userId)) {
            return userAclMap.get(userId);
        } else {//from w  w w  .j av a  2s .c o  m
            return transformStudyAclToSampleAcl(getStudyAclBelonging(studyId, userId, groupId));
        }
    }

    // Registered user
    EnumSet<SampleAclEntry.SamplePermissions> permissions = EnumSet
            .noneOf(SampleAclEntry.SamplePermissions.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 SampleAclEntry(userId, permissions);
    } else {
        return transformStudyAclToSampleAcl(getStudyAclBelonging(studyId, userId, groupId));
    }
}

From source file:org.globus.gsi.util.CertificateUtil.java

/**
 * Gets a boolean array representing bits of the KeyUsage extension.
 *
 * @throws IOException if failed to extract the KeyUsage extension value.
 * @see java.security.cert.X509Certificate#getKeyUsage
 *//*  w  w w .ja v  a 2  s . c om*/
public static EnumSet<KeyUsage> getKeyUsage(X509Extension ext) throws IOException {
    DERBitString bits = (DERBitString) getExtensionObject(ext);
    EnumSet<KeyUsage> keyUsage = EnumSet.noneOf(KeyUsage.class);
    for (KeyUsage bit : KeyUsage.values()) {
        if (bit.isSet(bits)) {
            keyUsage.add(bit);
        }
    }
    return keyUsage;
}

From source file:org.photovault.imginfo.PhotoInfo.java

/**
 Get operations that have been applied to this photo.
 @return set of {@link ImageOperations} values for those operations that have 
 been applied./*ww  w. ja  va  2 s.c o  m*/
 */
@Transient
public EnumSet<ImageOperations> getAppliedOperations() {
    EnumSet<ImageOperations> applied = EnumSet.noneOf(ImageOperations.class);

    if (!this.getCropBounds().contains(0.0, 0.0, 1.0, 1.0) || this.getPrefRotation() != 0.0) {
        applied.add(ImageOperations.CROP);
    }
    // Check for raw conversion
    if (getRawSettings() != null) {
        applied.add(ImageOperations.RAW_CONVERSION);
    }
    // Check for color mapping
    ChannelMapOperation colorMap = getColorChannelMapping();
    if (colorMap != null) {
        applied.add(ImageOperations.COLOR_MAP);
    }
    return applied;
}

From source file:me.jdknight.ums.ccml.core.CcmlRootFolderListener.java

/**
 * Return a virtual folder for all media resources in the provided directory.
 * //from   w  ww. j  a v a 2  s .  c  o m
 * @param directory The directory to search on.
 */
private IVirtualFolderMediaResources getVirtualFolderForDirectoryMedia(File directory) {
    assert (directory.isDirectory() == true);

    VirtualFolder folderSection = new VirtualFolder(directory.getName(), null);
    EnumSet<EMediaType> mediaTypes = EnumSet.noneOf(EMediaType.class);

    File[] directoryChildren = directory.listFiles();
    if (directoryChildren != null) {
        for (File child : directoryChildren) {
            if (child.isFile() == true) {
                // Find if this file is a supported media type.
                EMediaType mediaType = EMediaType.UNKNOWN;
                RealFileWithVirtualFolderThumbnails mediaResource = new RealFileWithVirtualFolderThumbnails(
                        child);

                Format mediaFormat = LazyCompatibility.getAssociatedExtension(child.getPath());
                if (mediaFormat == null) {
                    continue;
                }

                switch (mediaFormat.getType()) {
                case Format.VIDEO:
                    mediaType = EMediaType.VIDEO;
                    break;

                case Format.AUDIO:
                    mediaType = EMediaType.AUDIO;
                    break;

                case Format.IMAGE:
                    mediaType = EMediaType.IMAGE;
                    break;
                }

                // Ignore unsupported media types.
                if (mediaType == EMediaType.UNKNOWN) {
                    continue;
                }

                mediaTypes.add(mediaType);
                folderSection.addChild(mediaResource);
            } else {
                IVirtualFolderMediaResources subFolderSection = getVirtualFolderForDirectoryMedia(child);

                mediaTypes.addAll(subFolderSection.getMediaType());
                folderSection.addChild(subFolderSection.getVirtualFolder());
            }
        }
    }

    return new VirtualFolderMediaResources(folderSection, mediaTypes);
}

From source file:gov.nih.nci.firebird.data.user.FirebirdUser.java

/**
 * @return An EnumSet of the UserRoleTypes that this user represents (unverified).
 *//*from   w ww. j  a  v  a 2  s. c o m*/
@Transient
public EnumSet<UserRoleType> getRoles() {
    EnumSet<UserRoleType> roles = EnumSet.noneOf(UserRoleType.class);
    if (isInvestigator()) {
        roles.add(UserRoleType.INVESTIGATOR);
    }
    if (isRegistrationCoordinator()) {
        roles.add(UserRoleType.REGISTRATION_COORDINATOR);
    }
    if (isSponsorRepresentative()) {
        roles.add(UserRoleType.SPONSOR);
    }
    if (isSponsorDelegate()) {
        roles.add(UserRoleType.SPONSOR_DELEGATE);
    }
    return roles;
}

From source file:org.dcache.xrootd.door.XrootdDoor.java

/**
 * List the contents of a path, usually a directory. In order to make
 * fragmented responses, as supported by the xrootd protocol, possible and
 * not block the processing thread in the door, this will register the
 * passed callback along with the UUID of the message that is sent to
 * PNFS-manager./*  w w w.  jav a  2  s .  c o m*/
 *
 * Once PNFS-manager replies to the message, that callback is retrieved and
 * the response is processed by the callback.
 *
 * @param path The path that is listed
 * @param subject Representation of user that request listing
 * @param callback The callback that will process the response
 */
public void listPath(FsPath path, Subject subject, MessageCallback<PnfsListDirectoryMessage> callback) {
    PnfsHandler pnfsHandler = new PnfsHandler(_pnfs, subject);

    PnfsListDirectoryMessage msg = new PnfsListDirectoryMessage(path.toString(), null, Ranges.<Integer>all(),
            EnumSet.noneOf(FileAttribute.class));
    UUID uuid = msg.getUUID();

    try {
        DirlistRequestHandler requestHandler = new DirlistRequestHandler(uuid, pnfsHandler.getPnfsTimeout(),
                callback);
        _requestHandlers.put(uuid, requestHandler);
        pnfsHandler.send(msg);
        requestHandler.resetTimeout();
    } catch (NoRouteToCellException e) {
        _requestHandlers.remove(uuid);
        callback.noroute(e.getDestinationPath());
    } catch (RejectedExecutionException ree) {
        _requestHandlers.remove(uuid);
        callback.failure(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, ree.getMessage());
    }
}