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.DistCpV1.java
@Deprecated public static void copy(Configuration conf, String srcPath, String destPath, Path logPath, boolean srcAsList, boolean ignoreReadFailures) throws IOException { final Path src = new Path(srcPath); List<Path> tmp = new ArrayList<Path>(); if (srcAsList) { tmp.addAll(fetchFileList(conf, src)); } else {/*w ww . j a v a2 s . c o m*/ tmp.add(src); } EnumSet<Options> flags = ignoreReadFailures ? EnumSet.of(Options.IGNORE_READ_FAILURES) : EnumSet.noneOf(Options.class); final Path dst = new Path(destPath); copy(conf, new Arguments(tmp, null, dst, logPath, flags, null, Long.MAX_VALUE, Long.MAX_VALUE, null, false)); }
From source file:org.simplx.args.MainArgs.java
/** * Returns a value selected from an enum class. The argument string names * an element of the enum. The string must match one element name in the * enum. An abbreviation of any unique starting string is accepted by * default. For example, if the enum had elements <tt>MIN</tt>, * <tt>AVG</tt>, and <tt>MAX</tt>, the user could use any of <tt>a</tt>, * <tt>av</tt>, or <tt>avg</tt> to match <tt>AVG</tt>. But <tt>m</tt> would * cause an error since it could match either <tt>MIN</tt> or <tt>MAX</tt>, * whose shortest abbreviations are <tt>mi</tt> and <tt>ma</tt>, * respectively.//from w ww. j av a2s. c o m * <p/> * The string is compared against the enum element names both with and * without any underscore they may have. For example, if {@code GO_HOME} is * an enum member, the command-line argument to match it can be {@code * GO_HOME}, {@code go_home}, {@code GoHome}, or even {@code gOhOmE}. (If * the enum has two elements whose names differ only by the presence of * underscores, the behavior is undefined.) * <p/> * You can turn off abbreviations, requiring only full enum member names, * using {@link #setAbbreviatedEnums(boolean)}. * * @param option The option. * @param defaultValue The enum value to use if the option is not * specified. * @param enumClass The class of the enum to be parsed. * @param doc Usage documentation for the option (@see {@link * #getString(String,String,String...)} getString}). * @param <T> The type of the enum; derived from {@code * defaultValue}. * * @return The value for the option, or {@code defaultValue}. * * @see #setAbbreviatedEnums(boolean) */ public <T extends Enum<T>> T getEnumValue(String option, T defaultValue, Class<T> enumClass, String... doc) { String typeName = enumClass.getSimpleName(); String str = getArgument(option, typeName, doc); if (str == null) return defaultValue; T[] possibles = enumClass.getEnumConstants(); EnumSet<T> matches = EnumSet.noneOf(enumClass); for (T e : possibles) { String name = e.toString(); if (str.equalsIgnoreCase(name)) return e; String stripped = STRIP_NAME_PATTERN.matcher(name).replaceAll(""); if (str.equalsIgnoreCase(stripped)) return e; if (abbreviatedEnums && (abbreviation(str, name) || abbreviation(str, stripped))) { matches.add(e); } } // No exact match, see if it is an abbreviation if (abbreviatedEnums) { if (matches.size() == 0) { throw new CommandLineException(str + " unknown in " + enumClass.getSimpleName()); } if (matches.size() == 1) return matches.iterator().next(); else if (matches.size() > 1) { String msg = "Ambiguous option \"" + str + "\": Could be " + matches; throw new CommandLineException(msg); } } return defaultValue; }
From source file:org.lilyproject.repository.impl.HBaseRepository.java
private EnumSet<Scope> calculateChangedFields(Record record, Record originalRecord, RecordType recordType, Long version, Put put, RecordEvent recordEvent, Set<BlobReference> referencedBlobs, Set<BlobReference> unReferencedBlobs, FieldTypes fieldTypes) throws InterruptedException, RepositoryException { Map<QName, Object> originalFields = originalRecord.getFields(); EnumSet<Scope> changedScopes = EnumSet.noneOf(Scope.class); Map<QName, Object> fields = getFieldsToUpdate(record); changedScopes.addAll(calculateUpdateFields(record, fields, record.getMetadataMap(), originalFields, originalRecord.getMetadataMap(), null, version, put, recordEvent, referencedBlobs, unReferencedBlobs, false, fieldTypes)); for (BlobReference referencedBlob : referencedBlobs) { referencedBlob.setRecordId(record.getId()); }/* ww w . j a va 2s . co m*/ for (BlobReference unReferencedBlob : unReferencedBlobs) { unReferencedBlob.setRecordId(record.getId()); } // Update record types for (Scope scope : changedScopes) { long versionOfRTField = version; if (Scope.NON_VERSIONED.equals(scope)) { versionOfRTField = 1L; // For non-versioned fields the record type is always stored at version 1. } // Only update the recordTypeNames and versions if they have indeed changed QName originalScopeRecordTypeName = originalRecord.getRecordTypeName(scope); if (originalScopeRecordTypeName == null) { put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(scope), versionOfRTField, recordType.getId().getBytes()); put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(scope), versionOfRTField, Bytes.toBytes(recordType.getVersion())); } else { RecordType originalScopeRecordType = typeManager.getRecordTypeByName(originalScopeRecordTypeName, originalRecord.getRecordTypeVersion(scope)); if (!recordType.getId().equals(originalScopeRecordType.getId())) { put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(scope), versionOfRTField, recordType.getId().getBytes()); } if (!recordType.getVersion().equals(originalScopeRecordType.getVersion())) { put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(scope), versionOfRTField, Bytes.toBytes(recordType.getVersion())); } } record.setRecordType(scope, recordType.getName(), recordType.getVersion()); } return changedScopes; }
From source file:cz.dasnet.dasik.Dasik.java
@Override protected void onUserList(String channel, User[] users) { if (!activeChannels.containsKey(channel)) { Channel c = new Channel(channel); activeChannels.put(channel, c);// www . java 2 s. c o m } Channel c = activeChannels.get(channel); for (User u : users) { String p = u.getPrefix(); EnumSet<ChannelAccess> mode = EnumSet.noneOf(ChannelAccess.class); if (p.contains("@")) { mode.add(ChannelAccess.OP); } if (p.contains("+")) { mode.add(ChannelAccess.VOICE); } c.addUser(new ChannelUser(u.getNick(), mode)); } sendWhoOnChannel(channel); }
From source file:org.auraframework.integration.test.util.WebDriverTestCase.java
/** * Browser types to be excluded for this testcase or test class. * * @return//from w w w . j a v a 2 s. c o m * @throws NoSuchMethodException */ public Set<BrowserType> getExcludedBrowsers() { ExcludeBrowsers excludeBrowsers = null; try { Method method = getClass().getMethod(getName()); excludeBrowsers = method.getAnnotation(ExcludeBrowsers.class); if (excludeBrowsers == null) { // Inherit defaults from the test class excludeBrowsers = getClass().getAnnotation(ExcludeBrowsers.class); } } catch (NoSuchMethodException e) { // Do nothing } if (excludeBrowsers == null) { return EnumSet.noneOf(BrowserType.class); } return Sets.newEnumSet(Arrays.asList(excludeBrowsers.value()), BrowserType.class); }
From source file:org.apache.hadoop.fs.nfs.NFSv3FileSystem.java
private void truncate(NFSv3FileSystemStore store, FileHandle handle, long newSize) throws IOException { int status;//from ww w. j a va 2 s . co m EnumSet<SetAttrField> updateFields = EnumSet.noneOf(SetAttrField.class); updateFields.add(SetAttr3.SetAttrField.SIZE); Nfs3SetAttr objAttr = new Nfs3SetAttr(); objAttr.setUpdateFields(updateFields); objAttr.setSize(newSize); SETATTR3Response setAttr3Response = store.setattr(handle, objAttr, false, null, getCredentials()); status = setAttr3Response.getStatus(); checkNFSStatus(handle, null, status, "NFS_SETATTR"); }
From source file:org.apache.flex.compiler.internal.parsing.as.BaseASParser.java
/** * Parses a databinding expression./* w ww .j a va 2s.c o m*/ */ public static final IExpressionNode parseDataBinding(IWorkspace workspace, Reader reader, Collection<ICompilerProblem> problems) { StreamingASTokenizer tokenizer = new StreamingASTokenizer(); tokenizer.setReader(reader); IRepairingTokenBuffer buffer = new StreamingTokenBuffer(tokenizer); ASParser parser = new ASParser(workspace, buffer); FileNode fileNode = new FileNode(workspace); // Parse the databinding and build children inside the FileNode. parser.parseFile(fileNode, EnumSet.noneOf(PostProcessStep.class)); // Run post-processing to calculate all offsets. // Without this, identifiers have the right offsets but operators don't. EnumSet<PostProcessStep> postProcessSteps = EnumSet.of(PostProcessStep.CALCULATE_OFFSETS); Collection<ICompilerProblem> postProcessProblems = fileNode.runPostProcess(postProcessSteps, null); problems.addAll(tokenizer.getTokenizationProblems()); problems.addAll(parser.getSyntaxProblems()); problems.addAll(postProcessProblems); int n = fileNode.getChildCount(); // If we didn't get any children of the file node, // we must have parsed whitespace (or nothing). // An databinding like {} or { } represents the empty string. if (n == 0) { return new LiteralNode(LiteralType.STRING, ""); } // If we got more than one child, report that the databinding expression // is invalid. It must be a single expression. else if (n > 1) { final ICompilerProblem problem = new MXMLInvalidDatabindingExpressionProblem(fileNode); problems.add(problem); return null; } IASNode firstChild = fileNode.getChild(0); // If we got a single child but it isn't an expression, // report a problem. if (!(firstChild instanceof IExpressionNode)) { final ICompilerProblem problem = new MXMLInvalidDatabindingExpressionProblem(fileNode); problems.add(problem); return null; } // We got a single expression, so return it. return (IExpressionNode) firstChild; }
From source file:org.apache.hadoop.hive.ql.parse.CalcitePlanner.java
private static EnumSet<ExtendedCBOProfile> obtainCBOProfiles(QueryProperties queryProperties) { EnumSet<ExtendedCBOProfile> profilesCBO = EnumSet.noneOf(ExtendedCBOProfile.class); // If the query contains more than one join if (queryProperties.getJoinCount() > 1) { profilesCBO.add(ExtendedCBOProfile.JOIN_REORDERING); }//w ww.j ava2 s . c o m // If the query contains windowing processing if (queryProperties.hasWindowing()) { profilesCBO.add(ExtendedCBOProfile.WINDOWING_POSTPROCESSING); } return profilesCBO; }
From source file:org.apache.hadoop.tools.distcp2.mapred.TestCopyMapper.java
private void testPreserveUserGroupImpl(boolean preserve) { try {//from w ww .j a v a 2 s . co m deleteState(); createSourceData(); changeUserGroup("Michael", "Corleone"); 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.USER); fileAttributes.add(DistCpOptions.FileAttribute.GROUP); fileAttributes.add(DistCpOptions.FileAttribute.PERMISSION); } 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 user/group attributes are preserved // (only) as necessary. 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.getOwner().equals(target.getOwner())); Assert.assertTrue(!preserve || source.getGroup().equals(target.getGroup())); Assert.assertTrue(!preserve || source.getPermission().equals(target.getPermission())); Assert.assertTrue(preserve || !source.getOwner().equals(target.getOwner())); Assert.assertTrue(preserve || !source.getGroup().equals(target.getGroup())); Assert.assertTrue(preserve || !source.getPermission().equals(target.getPermission())); Assert.assertTrue(source.isDir() || source.getReplication() != target.getReplication()); } } } catch (Exception e) { Assert.assertTrue("Unexpected exception: " + e.getMessage(), false); e.printStackTrace(); } }
From source file:nl.strohalm.cyclos.services.elements.MessageServiceImpl.java
/** * Sends the message, returning a set containing the channels actually delivered *//*ww w. j a va 2s . co m*/ private Set<MessageChannel> send(final Message message, final String smsMessage, final String smsTraceData, Set<MessageChannel> messageChannels) { final Member toMember = fetchService.fetch(message.getToMember(), Element.Relationships.GROUP); message.setCategory(fetchService.fetch(message.getCategory())); final Set<MessageChannel> result = EnumSet.noneOf(MessageChannel.class); if (toMember != null) { final MemberGroup group = toMember.getMemberGroup(); final Type type = message.getType(); // Check which message channels will be used if (messageChannels == null) { messageChannels = preferenceService.receivedChannels(toMember, type); } if (CollectionUtils.isEmpty(messageChannels)) { // Nothing to send for this member return result; } // Send an e-mail if needed final String email = toMember.getEmail(); if (messageChannels.contains(MessageChannel.EMAIL) && StringUtils.isNotEmpty(email)) { InternetAddress replyTo = mailHandler.getInternetAddress(message.getFromMember()); InternetAddress to = mailHandler.getInternetAddress(toMember); mailHandler.sendAfterTransactionCommit(message.getSubject(), replyTo, to, message.getBody(), message.isHtml()); message.setEmailSent(true); result.add(MessageChannel.EMAIL); } // Check if we need to send a SMS if (StringUtils.isNotEmpty(smsMessage) && messageChannels.contains(MessageChannel.SMS) && group.getSmsMessages().contains(type)) { // Send the SMS final SendSmsDTO sendDTO = new SendSmsDTO(); sendDTO.setTargetMember(toMember); sendDTO.setMessageType(type); sendDTO.setText(smsMessage); sendDTO.setTraceData(smsTraceData); sendSmsAfterTransactionCommit(sendDTO); result.add(MessageChannel.SMS); } // If the user does not want the internal message, return now if (!messageChannels.contains(MessageChannel.MESSAGE)) { // If not, return now return result; } result.add(MessageChannel.MESSAGE); } // Insert the internal message messageDao.insert(message); return result; }