List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:org.apache.hadoop.tools.distcp2.mapred.TestCopyMapper.java
private void testPreserveBlockSizeAndReplicationImpl(boolean preserve) { try {/* w ww . jav a2 s . c o m*/ deleteState(); createSourceData(); FileSystem fs = cluster.getFileSystem(); CopyMapper copyMapper = new CopyMapper(); StubContext stubContext = new StubContext(getConfiguration(), null, 0); Mapper<Text, FileStatus, Text, Text>.Context context = stubContext.getContext(); Configuration configuration = context.getConfiguration(); EnumSet<DistCpOptions.FileAttribute> fileAttributes = EnumSet.noneOf(DistCpOptions.FileAttribute.class); if (preserve) { fileAttributes.add(DistCpOptions.FileAttribute.BLOCKSIZE); fileAttributes.add(DistCpOptions.FileAttribute.REPLICATION); } configuration.set(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel(), DistCpUtils.packAttributes(fileAttributes)); copyMapper.setup(context); for (Path path : pathList) { final FileStatus fileStatus = fs.getFileStatus(path); copyMapper.map(new Text(DistCpUtils.getRelativePath(new Path(SOURCE_PATH), path)), fileStatus, context); } // Check that the block-size/replication aren't preserved. for (Path path : pathList) { final Path targetPath = new Path(path.toString().replaceAll(SOURCE_PATH, TARGET_PATH)); final FileStatus source = fs.getFileStatus(path); final FileStatus target = fs.getFileStatus(targetPath); if (!source.isDir()) { Assert.assertTrue(preserve || source.getBlockSize() != target.getBlockSize()); Assert.assertTrue(preserve || source.getReplication() != target.getReplication()); Assert.assertTrue(!preserve || source.getBlockSize() == target.getBlockSize()); Assert.assertTrue(!preserve || source.getReplication() == target.getReplication()); } } } catch (Exception e) { Assert.assertTrue("Unexpected exception: " + e.getMessage(), false); e.printStackTrace(); } }
From source file:com.github.helenusdriver.driver.impl.DataDecoder.java
/** * Gets a "set" to {@link Set} decoder based on the given element class. * * @author paouelle/* w w w.j a v a 2 s . com*/ * * @param eclazz the non-<code>null</code> class of elements * @param mandatory if the field associated with the decoder is mandatory or * represents a primary key * @return the non-<code>null</code> decoder for sets of the specified element * class */ @SuppressWarnings("rawtypes") public final static DataDecoder<Set> set(final Class<?> eclazz, final boolean mandatory) { return new DataDecoder<Set>(Set.class) { @SuppressWarnings("unchecked") private Set decodeImpl(Class<?> etype, Set<Object> set) { if (set == null) { // safe to return as is unless mandatory, that is because Cassandra // returns null for empty sets and the schema definition requires // that mandatory and primary keys be non null if (mandatory) { if (eclazz.isEnum()) { // for enum values we create an enum set. Now we won't preserve the order // the entries were added but that should be fine anyways in this case return EnumSet.noneOf((Class<? extends Enum>) eclazz); } return new LinkedHashSet(16); // to keep order } return set; } final Set nset; if (eclazz.isEnum()) { // for enum values we create an enum set. Now we won't preserve the order // the entries were added but that should be fine anyways in this case nset = EnumSet.noneOf((Class<? extends Enum>) eclazz); } else { nset = new LinkedHashSet(set.size()); // to keep order } if (eclazz.isAssignableFrom(etype)) { // we only need to store elements to make sure list is modifiable nset.addAll(set); } else { // will need to do some conversion of each element final ElementConverter converter = ElementConverter.getConverter(eclazz, etype); for (final Object o : set) { nset.add((o != null) ? converter.convert(o) : null); } } return nset; } @SuppressWarnings("unchecked") @Override protected Set decodeImpl(Row row, String name, Class clazz) { return decodeImpl( // get the element type from the row's metadata row.getColumnDefinitions().getType(name).getTypeArguments().get(0).getName().asJavaClass(), row.isNull(name) ? null : row.getSet(name, Object.class) // keeps things generic so we can handle our own errors ); } @SuppressWarnings("unchecked") @Override protected Set decodeImpl(UDTValue uval, String name, Class clazz) { return decodeImpl( // get the element type from the row's metadata uval.getType().getFieldType(name).getTypeArguments().get(0).getName().asJavaClass(), uval.isNull(name) ? null : uval.getSet(name, Object.class) // keeps things generic so we can handle our own errors ); } }; }
From source file:pl.edu.icm.cermine.pubmed.PubmedXMLGenerator.java
public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: <pubmed directory>"); System.exit(1);/*ww w. j a v a 2 s .com*/ } File dir = new File(args[0]); for (File pdfFile : FileUtils.listFiles(dir, new String[] { "pdf" }, true)) { try { String pdfPath = pdfFile.getPath(); String nxmlPath = StringTools.getNLMPath(pdfPath); File xmlFile = new File(StringTools.getTrueVizPath(nxmlPath)); if (xmlFile.exists()) { continue; } System.out.print(pdfPath + " "); InputStream pdfStream = new FileInputStream(pdfPath); InputStream nxmlStream = new FileInputStream(nxmlPath); PubmedXMLGenerator datasetGenerator = new PubmedXMLGenerator(); datasetGenerator.setVerbose(false); BxDocument bxDoc = datasetGenerator.generateTrueViz(pdfStream, nxmlStream); int keys = 0; Set<BxZoneLabel> set = EnumSet.noneOf(BxZoneLabel.class); int total = 0; int known = 0; for (BxZone z : bxDoc.asZones()) { total++; if (z.getLabel() != null) { known++; if (z.getLabel().isOfCategoryOrGeneral(BxZoneLabelCategory.CAT_METADATA)) { set.add(z.getLabel()); } if (BxZoneLabel.REFERENCES.equals(z.getLabel())) { keys = 1; } } } if (set.contains(BxZoneLabel.MET_AFFILIATION)) { keys++; } if (set.contains(BxZoneLabel.MET_AUTHOR)) { keys++; } if (set.contains(BxZoneLabel.MET_BIB_INFO)) { keys++; } if (set.contains(BxZoneLabel.MET_TITLE)) { keys++; } int coverage = 0; if (total > 0) { coverage = known * 100 / total; } System.out.print(coverage + " " + set.size() + " " + keys); FileWriter fstream = new FileWriter( StringTools.getTrueVizPath(nxmlPath).replace(".xml", "." + coverage + ".cxml")); BufferedWriter out = new BufferedWriter(fstream); BxDocumentToTrueVizWriter writer = new BxDocumentToTrueVizWriter(); out.write(writer.write(bxDoc.getPages())); out.close(); System.out.println(" done"); } catch (Exception e) { e.printStackTrace(); } } }
From source file:sx.blah.discord.handle.impl.obj.Guild.java
@Override public void reorderRoles(IRole... rolesInOrder) { if (rolesInOrder.length != getRoles().size()) throw new DiscordException( "The number of roles to reorder does not equal the number of available roles!"); PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_ROLES); int usersHighest = getRolesForUser(client.getOurUser()).stream().map(IRole::getPosition) .max(Comparator.comparing(Function.identity())).orElse(-1); ReorderRolesRequest[] request = new ReorderRolesRequest[roles.size()]; for (int i = 0; i < roles.size(); i++) { IRole role = rolesInOrder[i];// www . j a va 2 s . c o m int newPosition = role.getPosition(); int oldPosition = getRoleByID(role.getLongID()).getPosition(); if (newPosition != oldPosition && oldPosition >= usersHighest) { // If the position was changed and the user doesn't have permission to change it. throw new MissingPermissionsException( "Cannot edit the position of a role higher than or equal to your own.", EnumSet.noneOf(Permissions.class)); } else { request[i] = new ReorderRolesRequest(role.getStringID(), i); } } ((DiscordClientImpl) client).REQUESTS.PATCH.makeRequest(DiscordEndpoints.GUILDS + getStringID() + "/roles", request); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Get all the clusters this command is associated with. * * @param id The id of the command to get the clusters for. Not * NULL/empty/blank./* ww w . j a v a 2 s . co m*/ * @param statuses The statuses of the clusters to get * @return The list of clusters. * @throws GenieException For any error */ @GET @Path("/{id}/clusters") @ApiOperation(value = "Get the clusters this command is associated with", notes = "Get the clusters which this command exists on supports.", response = Cluster.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Cluster> getClustersForCommand( @ApiParam(value = "Id of the command to get the clusters for.", required = true) @PathParam("id") final String id, @ApiParam(value = "Status of the cluster.", allowableValues = "UP, OUT_OF_SERVICE, TERMINATED") @QueryParam("status") final Set<String> statuses) throws GenieException { LOG.info("Called with id " + id + " and statuses " + statuses); Set<ClusterStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(ClusterStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(ClusterStatus.parse(status)); } } } return this.commandConfigService.getClustersForCommand(id, enumStatuses); }
From source file:com.microsoft.windowsazure.mobileservices.MobileServiceTableBase.java
/** * Returns the system properties defined or annotated in the entity class * @param clazz Target entity class/*from w w w. j av a2 s . c o m*/ * @return List of entities */ protected static <F> EnumSet<MobileServiceSystemProperty> getSystemProperties(Class<F> clazz) { EnumSet<MobileServiceSystemProperty> result = EnumSet.noneOf(MobileServiceSystemProperty.class); Class<?> idClazz = getIdPropertyClass(clazz); if (idClazz != null && !isIntegerClass(idClazz)) { // Search for system properties annotations, regardless case for (Field field : clazz.getDeclaredFields()) { SerializedName serializedName = field.getAnnotation(SerializedName.class); if (serializedName != null) { if (SystemPropertyNameToEnum.containsKey(serializedName.value())) { result.add(SystemPropertyNameToEnum.get(serializedName.value())); } } else { if (SystemPropertyNameToEnum.containsKey(field.getName())) { result.add(SystemPropertyNameToEnum.get(field.getName())); } } } } // Otherwise, return empty return result; }
From source file:org.apache.hadoop.fs.nfs.NFSv3FileSystem.java
private boolean mkdir(NFSv3FileSystemStore store, FileHandle dir, String name, FsPermission permission) throws IOException { int status;//from www . jav a 2 s . com EnumSet<SetAttrField> updateFields = EnumSet.noneOf(SetAttrField.class); /* * Note we do not set a specific size for a directory. NFS server should be able to figure it * out when creating it. We also not set the mtime and ctime. Use the timestamp at the server * machine. */ updateFields.add(SetAttr3.SetAttrField.UID); updateFields.add(SetAttr3.SetAttrField.GID); updateFields.add(SetAttr3.SetAttrField.MODE); Nfs3SetAttr objAttr = new Nfs3SetAttr(permission.toShort(), NFS_UID, NFS_GID, 0, null, null, updateFields); MKDIR3Response mkdir3Response = store.mkdir(dir, name, objAttr, getCredentials()); status = mkdir3Response.getStatus(); if (status != Nfs3Status.NFS3_OK) { if (status == Nfs3Status.NFS3ERR_EXIST) { LOG.error("mkdir(): Could not create directory with name " + name); throw new FileAlreadyExistsException(); } else if (status == Nfs3Status.NFS3ERR_NOTDIR) { throw new ParentNotDirectoryException(); } else { throw new IOException("mkdir(): returned error status " + status); } } return true; }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get all the commands this application is associated with. * * @param id The id of the application to get the commands for. Not * NULL/empty/blank.//ww w . ja va 2s . c om * @param statuses The various statuses of the commands to retrieve * @return The set of commands. * @throws GenieException For any error */ @GET @Path("/{id}/commands") @ApiOperation(value = "Get the commands this application is associated with", notes = "Get the commands which this application supports.", response = Command.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid ID supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Command> getCommandsForApplication( @ApiParam(value = "Id of the application to get the commands for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses) throws GenieException { LOG.info("Called with id " + id); Set<CommandStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(CommandStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(CommandStatus.parse(status)); } } } return this.applicationConfigService.getCommandsForApplication(id, enumStatuses); }
From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java
private CohortAclEntry resolveCohortPermissions(long studyId, String userId, String groupId, Map<String, CohortAclEntry> userAclMap) throws CatalogException { if (userId.equals(ANONYMOUS)) { if (userAclMap.containsKey(userId)) { return userAclMap.get(userId); } else {/*w ww.j a va2 s . co m*/ return transformStudyAclToCohortAcl(getStudyAclBelonging(studyId, userId, groupId)); } } // Registered user EnumSet<CohortAclEntry.CohortPermissions> permissions = EnumSet .noneOf(CohortAclEntry.CohortPermissions.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 CohortAclEntry(userId, permissions); } else { return transformStudyAclToCohortAcl(getStudyAclBelonging(studyId, userId, groupId)); } }
From source file:org.apache.hadoop.fs.nfs.NFSv3FileSystem.java
private FileHandle create(NFSv3FileSystemStore store, FileHandle dir, String name, FsPermission permission) throws IOException { EnumSet<SetAttrField> updateFields = EnumSet.noneOf(SetAttrField.class); updateFields.add(SetAttr3.SetAttrField.UID); updateFields.add(SetAttr3.SetAttrField.GID); updateFields.add(SetAttr3.SetAttrField.MODE); Nfs3SetAttr objAttr = new Nfs3SetAttr(permission.toShort(), NFS_UID, NFS_GID, 0, null, null, updateFields); CREATE3Response create3Response = store.create(dir, name, Nfs3Constant.CREATE_UNCHECKED, objAttr, 0, getCredentials());/*from w w w . ja v a2s.co m*/ int status = create3Response.getStatus(); if (status != Nfs3Status.NFS3_OK) { throw new IOException("create(): returned error status " + status); } FileHandle handle = create3Response.getObjHandle(); return handle; }