List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:io.webfolder.cdp.ChromiumDownloader.java
private static Set<PosixFilePermission> modeToPosixPermissions(final int mode) { int mask = 1; Set<PosixFilePermission> perms = EnumSet.noneOf(PosixFilePermission.class); for (PosixFilePermission flag : DECODE_MAP) { if ((mask & mode) != 0) { perms.add(flag);//w w w . java2s . c o m } mask = mask << 1; } return perms; }
From source file:de.blizzy.documentr.access.UserStore.java
/** * Returns the role that has the specified name. * * @throws RoleNotFoundException when the role could not be found *//*from ww w .j ava 2 s . c o m*/ public Role getRole(String roleName) throws IOException { Assert.hasLength(roleName); ILockedRepository repo = null; try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); String json = BlobUtils.getHeadContent(repo.r(), roleName + ROLE_SUFFIX); if (json == null) { throw new RoleNotFoundException(roleName); } Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create(); Map<String, Object> roleMap = gson.fromJson(json, new TypeToken<Map<String, Object>>() { }.getType()); @SuppressWarnings("unchecked") Collection<String> permissions = (Collection<String>) roleMap.get("permissions"); //$NON-NLS-1$ EnumSet<Permission> rolePermissions = EnumSet.noneOf(Permission.class); for (String permission : permissions) { rolePermissions.add(Permission.valueOf(permission)); } Role role = new Role(roleName, rolePermissions); return role; } finally { Closeables.closeQuietly(repo); } }
From source file:org.apache.nifi.authorization.AuthorityProviderFactoryBean.java
/** * @return a default provider to use when running unsecurely with no * provider configured//ww w .j av a 2s .c o m */ private AuthorityProvider createDefaultProvider() { return new AuthorityProvider() { @Override public boolean doesDnExist(String dn) throws AuthorityAccessException { return false; } @Override public Set<Authority> getAuthorities(String dn) throws UnknownIdentityException, AuthorityAccessException { return EnumSet.noneOf(Authority.class); } @Override public void setAuthorities(String dn, Set<Authority> authorities) throws UnknownIdentityException, AuthorityAccessException { } @Override public Set<String> getUsers(Authority authority) throws AuthorityAccessException { return new HashSet<>(); } @Override public void revokeUser(String dn) throws UnknownIdentityException, AuthorityAccessException { } @Override public void addUser(String dn, String group) throws IdentityAlreadyExistsException, AuthorityAccessException { } @Override public String getGroupForUser(String dn) throws UnknownIdentityException, AuthorityAccessException { return null; } @Override public void revokeGroup(String group) throws UnknownIdentityException, AuthorityAccessException { } @Override public void setUsersGroup(Set<String> dn, String group) throws UnknownIdentityException, AuthorityAccessException { } @Override public void ungroupUser(String dn) throws UnknownIdentityException, AuthorityAccessException { } @Override public void ungroup(String group) throws AuthorityAccessException { } @Override public DownloadAuthorization authorizeDownload(List<String> dnChain, Map<String, String> attributes) throws UnknownIdentityException, AuthorityAccessException { return DownloadAuthorization.approved(); } @Override public void initialize(AuthorityProviderInitializationContext initializationContext) throws ProviderCreationException { } @Override public void onConfigured(AuthorityProviderConfigurationContext configurationContext) throws ProviderCreationException { } @Override public void preDestruction() throws ProviderDestructionException { } }; }
From source file:me.jdknight.ums.ccml.core.CcmlRootFolderListener.java
/** * Build the media library on the provided library based off the provided base directory. * /*from w ww. java2 s . c o m*/ * @param library The library to add to. * @param directory The directory to scan. */ private void buildMediaLibrary(ICustomCategoryMediaLibrary library, File directory) { assert (directory.isDirectory() == true); File[] directoryChildren = directory.listFiles(); if (directoryChildren != null) { for (File child : directoryChildren) { if (child.isFile() == true) { // Find if this file is a supported media type. RealFileWithVirtualFolderThumbnails mediaResource = new RealFileWithVirtualFolderThumbnails( child); Format mediaFormat = LazyCompatibility.getAssociatedExtension(child.getPath()); EMediaType mediaType = EMediaType.get(mediaFormat); // Ignore unsupported media types. if (mediaType == EMediaType.UNKNOWN) { continue; } // Check if a meta file exists. String metaFilePath = mediaResource.getFile().getPath() + ".meta"; //$NON-NLS-1$ File metaFile = new File(metaFilePath); // No meta file? Check the alternative folder (if any is provided). if (metaFile.isFile() == false) { String alternativeFolderPath = CcmlConfiguration.getInstance().getAlternativeMetaFolder(); if (alternativeFolderPath != null) { File alternativeFolder = new File(alternativeFolderPath); if (alternativeFolder.isDirectory() == true) { String originalFileName = metaFile.getName(); metaFile = new File(alternativeFolder, originalFileName); } } } // Still no meta file? Ignore. if (metaFile.isFile() == false) { continue; } _logger.trace("[CCML] Parsing meta file: " + metaFile); //$NON-NLS-1$ Map<String, List<String>> mapOfCategories = parseMetaFile(metaFile); if (mapOfCategories == null) { continue; } // Attempt to find this meta file's master reference(s). String[] masterSections = stripSpecialValues(mapOfCategories, metaFile, SPECIAL_CATEGORY_TYPE_NAME_MASTER); // Strip out any filter entries; they are not used on single meta file. stripSpecialValues(mapOfCategories, metaFile, SPECIAL_CATEGORY_TYPE_NAME_FILTER); // Add resources to a respective media category type. Set<Entry<String, List<String>>> categorySet = mapOfCategories.entrySet(); if (categorySet.isEmpty() == false) { for (String masterSection : masterSections) { for (Entry<String, List<String>> categoryReference : categorySet) { // Find/create category. String categoryName = categoryReference.getKey(); IMediaCategoryType category = library.acquireCategoryType(mediaType, masterSection, categoryName); // Add resource to it. List<String> categoryValues = categoryReference.getValue(); for (String categoryValue : categoryValues) { category.addResource(new RealFileWithVirtualFolderThumbnails(mediaResource), categoryValue); _logger.trace("[CCML] Adding resource to category a '" + categoryName //$NON-NLS-1$ + "' with a value of '" + categoryValue + "'" + //$NON-NLS-1$ //$NON-NLS-2$ (masterSection != null ? " (Master: " + masterSection + ")" : "") + ": " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + metaFile); } } } } else { _logger.warn( "[CCML] The following meta file does not have any defined categories: " + metaFile); //$NON-NLS-1$ } } else { // Recursive - scan folder for more resources. buildMediaLibrary(library, child); } } } // We will check if this folder has a meta file for its contents. // // Check if a folder meta file exists. File folderMetaFile = new File(directory, FOLDER_FOLDER_NAME); // No meta file? Ignore. if (folderMetaFile.isFile() == false) { return; } _logger.trace("[CCML] Parsing folder meta file: " + folderMetaFile); //$NON-NLS-1$ Map<String, List<String>> mapOfCategories = parseMetaFile(folderMetaFile); if (mapOfCategories == null) { return; } // Attempt to find this meta file's master reference(s). String[] masterSections = stripSpecialValues(mapOfCategories, folderMetaFile, SPECIAL_CATEGORY_TYPE_NAME_MASTER); // Find if this meta file is specific to any media types. String[] filterValues = stripSpecialValues(mapOfCategories, folderMetaFile, SPECIAL_CATEGORY_TYPE_NAME_FILTER); boolean isFirstFilterAdded = false; EnumSet<EMediaType> mediaTypeFilter = EnumSet.allOf(EMediaType.class); for (String filterValue : filterValues) { if (filterValue != null) { EMediaType[] mediaTypes = EMediaType.values(); for (EMediaType mediaType : mediaTypes) { if (mediaType.getEnglishName().equalsIgnoreCase(filterValue) == true || mediaType.getDisplayName().equalsIgnoreCase(filterValue) == true) { // If we have actual content to filter, start fresh. if (isFirstFilterAdded == false) { mediaTypeFilter = EnumSet.noneOf(EMediaType.class); isFirstFilterAdded = true; } mediaTypeFilter.add(mediaType); break; } } } } // Compile a list of media resources for this folder. IVirtualFolderMediaResources mediaResourcePoint = getVirtualFolderForDirectoryMedia(directory); DLNAResource resource = mediaResourcePoint.getVirtualFolder(); // Add resources to a respective media category type. Set<Entry<String, List<String>>> categorySet = mapOfCategories.entrySet(); if (categorySet.isEmpty() == false) { for (String masterSection : masterSections) { for (Entry<String, List<String>> categoryReference : categorySet) { EnumSet<EMediaType> mediaTypes = mediaResourcePoint.getMediaType(); if (mediaTypes.isEmpty() == false) { for (EMediaType mediaType : mediaTypes) { // This media type filtered? If so, next. if (mediaTypeFilter.contains(mediaType) == false) { continue; } // Find/create category. String categoryName = categoryReference.getKey(); IMediaCategoryType category = library.acquireCategoryType(mediaType, masterSection, categoryName); // Add resource to it. List<String> categoryValues = categoryReference.getValue(); for (String categoryValue : categoryValues) { category.addResource(resource, categoryValue); _logger.trace("[CCML] Adding resource to category a '" + categoryName //$NON-NLS-1$ + "' with a value of '" + categoryValue + "'" + //$NON-NLS-1$ //$NON-NLS-2$ (masterSection != null ? " (Master: " + masterSection + ")" : "") + ": " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + folderMetaFile); } } } else { _logger.warn( "[CCML] The following folder meta file does not have any content to reference: " //$NON-NLS-1$ + folderMetaFile); } } } } else { _logger.warn("[CCML] The following folder meta file does not have any defined categories: " //$NON-NLS-1$ + folderMetaFile); } }
From source file:org.photovault.imginfo.PhotoInfo.java
/** Find instance that is preferred for use in particular situation. This function seeks for an image that has at least a given resolution, has certain operations already applied and is available. @param requiredOpers Set of operations that must be applied correctly in the returned image (but not that the operations need not be applied if this photo does not specify some operation. So even if this is non-empty it is possible that the method returns original image! @param allowedOpers Set of operations that may be applied to the returned image/* w w w .j a v a 2s . com*/ @param minWidth Minimum width of the returned image in pixels @param minHeight Minimum height of the returned image in pixels @param maxWidth Maximum width of the returned image in pixels @param maxHeight Maximum height of the returned image in pixels @return Image that best matches the given criteria or <code>null</code> if no suct image exists or is not available. */ public ImageDescriptorBase getPreferredImage(Set<ImageOperations> requiredOpers, Set<ImageOperations> allowedOpers, int minWidth, int minHeight, int maxWidth, int maxHeight) { ImageDescriptorBase preferred = null; EnumSet<ImageOperations> appliedPreferred = null; // We are not interested in operations that are not specified for this photo EnumSet<ImageOperations> specifiedOpers = getAppliedOperations(); requiredOpers = EnumSet.copyOf(requiredOpers); requiredOpers.removeAll(EnumSet.complementOf(specifiedOpers)); /* Would the original be OK? */ if (requiredOpers.size() == 0 && original.getWidth() <= maxWidth && original.getHeight() <= maxHeight && original.getFile().findAvailableCopy() != null) { preferred = original; appliedPreferred = EnumSet.noneOf(ImageOperations.class); } // Calculate minimum & maimum scaling of resolution compared to original double minScale = ((double) minWidth) / ((double) original.getWidth()); double maxScale = ((double) maxHeight) / ((double) original.getHeight()); if (allowedOpers.contains(ImageOperations.CROP)) { Dimension croppedSize = getCroppedSize(); double aspectRatio = croppedSize.getWidth() / croppedSize.getHeight(); double miw = minWidth; double mih = minHeight; double maw = maxWidth; double mah = maxHeight; if (mih == 0.0 || (miw / mih) > aspectRatio) { mih = miw / aspectRatio; } if (mih > 0.0 && (miw / mih) < aspectRatio) { miw = mih * aspectRatio; } if (maw / mah > aspectRatio) { maw = mah * aspectRatio; } if (maw / mah < aspectRatio) { mah = maw / aspectRatio; } miw = Math.floor(miw); mih = Math.floor(mih); maw = Math.ceil(maw); mah = Math.ceil(mah); minScale = ((double) miw) / ((double) croppedSize.getWidth()); maxScale = ((double) maw) / ((double) croppedSize.getWidth()); } // Check the copies Set<CopyImageDescriptor> copies = original.getCopies(); for (CopyImageDescriptor copy : copies) { double scale = ((double) copy.getWidth()) / ((double) original.getWidth()); if (copy.getAppliedOperations().contains(ImageOperations.CROP)) { scale = ((double) copy.getWidth()) / ((double) getCroppedSize().getWidth()); } if (scale >= minScale && scale <= maxScale && copy.getFile().findAvailableCopy() != null) { EnumSet<ImageOperations> applied = copy.getAppliedOperations(); if (applied.containsAll(requiredOpers) && allowedOpers.containsAll(applied) && isConsistentWithCurrentSettings(copy)) { // This is a potential one if (preferred == null || !appliedPreferred.containsAll(applied)) { preferred = copy; appliedPreferred = applied; } } } } return preferred; }
From source file:io.lavagna.service.SearchServiceTest.java
@Test public void testUserWithReadPermissionInProject() { Role r = new Role("READ"); permissionService.createRoleInProjectId(r, project.getId()); permissionService.assignRoleToUsersInProjectId(r, Collections.singleton(userWithNoAccess.getId()), project.getId());//w w w . j a va2 s .com permissionService.updatePermissionsToRoleInProjectId(r, EnumSet.of(Permission.READ), project.getId()); ProjectRoleAndPermissionFullHolder permissionsHolder = permissionService .findPermissionsGroupedByProjectForUserId(userWithNoAccess.getId()); UserWithPermission uwp = new UserWithPermission(userWithNoAccess, EnumSet.noneOf(Permission.class), permissionsHolder.getPermissionsByProject(), permissionsHolder.getPermissionsByProjectId()); cardService.createCard("test", column.getId(), new Date(), uwp); SearchResults find = searchService.find(Arrays.asList(createdByMe), null, null, uwp, 0); Assert.assertEquals(1, find.getCount()); }
From source file:org.apache.hadoop.tools.util.TestDistCpUtils.java
@Test public void testPreserveNothingOnFile() throws IOException { FileSystem fs = FileSystem.get(config); EnumSet<FileAttribute> attributes = EnumSet.noneOf(FileAttribute.class); Path dst = new Path("/tmp/dest2"); Path src = new Path("/tmp/src2"); createFile(fs, src);/*from w w w . ja v a 2 s . c om*/ createFile(fs, dst); fs.setPermission(src, fullPerm); fs.setOwner(src, "somebody", "somebody-group"); fs.setTimes(src, 0, 0); fs.setReplication(src, (short) 1); fs.setPermission(dst, noPerm); fs.setOwner(dst, "nobody", "nobody-group"); fs.setTimes(dst, 100, 100); fs.setReplication(dst, (short) 2); CopyListingFileStatus srcStatus = new CopyListingFileStatus(fs.getFileStatus(src)); DistCpUtils.preserve(fs, dst, srcStatus, attributes, false); CopyListingFileStatus dstStatus = new CopyListingFileStatus(fs.getFileStatus(dst)); // FileStatus.equals only compares path field, must explicitly compare all fields Assert.assertFalse(srcStatus.getPermission().equals(dstStatus.getPermission())); Assert.assertFalse(srcStatus.getOwner().equals(dstStatus.getOwner())); Assert.assertFalse(srcStatus.getGroup().equals(dstStatus.getGroup())); Assert.assertFalse(srcStatus.getAccessTime() == dstStatus.getAccessTime()); Assert.assertFalse(srcStatus.getModificationTime() == dstStatus.getModificationTime()); Assert.assertFalse(srcStatus.getReplication() == dstStatus.getReplication()); }
From source file:com.facebook.buck.util.ProjectFilesystemTest.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(/* w w w . ja v a 2s .c om*/ filesystem.getFilesUnderPath(Paths.get("dir1"), Predicates.<Path>alwaysTrue(), EnumSet.noneOf(FileVisitOption.class)), containsInAnyOrder(Paths.get("dir1/file2"), Paths.get("dir1/dir2/file3"))); assertThat(filesystem.getFilesUnderPath(Paths.get("dir1"), Predicates.equalTo(Paths.get("dir1/dir2/file3")), 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"), Predicates.equalTo(Paths.get("dir1/file2"))), containsInAnyOrder(Paths.get("dir1/file2"))); }
From source file:nl.mvdr.umvc3replayanalyser.ocr.TesseractOCREngine.java
/** * Tesseract seems to have trouble reading a few letter combinations. For example, A is often read as II. This * method replaces one of these occurences of known difficult combinations and tries to match the resulting text to * a character name.//from w ww . jav a 2 s . c o m * * @param text * original text, which did not uniquely match any character's name * @param possibleCharacters * the characters that text may match * @param suppressedExceptions * list of suppressed exceptions; if any OCRExceptions occur while executing this method, they are added * to this list * @return matching character, or null if no match could be found */ private Umvc3Character matchByReplacingLetters(String text, Set<Umvc3Character> possibleCharacters, List<OCRException> suppressedExceptions) { Set<Umvc3Character> matches = EnumSet.noneOf(Umvc3Character.class); matchByReplacingLetters(text, "II", "A", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "II", "N", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "II", "U", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "IM", "MA", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "W", "VI", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "o", "O", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "c", "C", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "s", "S", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "w", "W", possibleCharacters, matches, suppressedExceptions); matchByReplacingLetters(text, "v", "V", possibleCharacters, matches, suppressedExceptions); Umvc3Character result; if (matches.size() == 1) { result = matches.iterator().next(); } else { result = null; } return result; }
From source file:uk.org.rbc1b.roms.controller.volunteer.VolunteersController.java
/** * Displays a Volunteers Qualification for editing. * * @param volunteerQualificationId skill ID to edit * @param model mvc model/*from w ww. ja v a 2 s . c o m*/ * @return view name */ @RequestMapping(value = "{volunteerId}/qualifications/{volunteerQualificationId}/edit", method = RequestMethod.GET) @PreAuthorize("hasPermission('VOLUNTEER', 'EDIT')") public String showEditVolunteerQualificationForm(@PathVariable Integer volunteerQualificationId, ModelMap model) { VolunteerQualification volunteerQualification = volunteerDao.findQualification(volunteerQualificationId); if (volunteerQualification == null) { throw new ResourceNotFoundException( "No volunteer qualification #" + volunteerQualificationId + " found"); } Volunteer volunteer = volunteerDao.findVolunteer(volunteerQualification.getPersonId(), EnumSet.noneOf(VolunteerData.class)); VolunteerQualificationForm form = new VolunteerQualificationForm(); form.setComments(volunteerQualification.getComments()); form.setQualificationId(volunteerQualification.getQualificationId()); model.addAttribute("volunteerQualification", form); model.addAttribute("forename", volunteer.getPerson().getForename()); model.addAttribute("surname", volunteer.getPerson().getSurname()); model.addAttribute("qualificationValues", referenceDao.findQualificationValues()); model.addAttribute("submitUri", VolunteerModelFactory.generateUri(volunteerQualification.getVolunteerQualificationId()) + "/qualifications"); return "volunteers/edit-qualification"; }