下面列出了java.util.EnumSet#noneOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates an AggregateReduceFunctionsRule with client
* provided information on which specific functions will
* be reduced by this rule
* @param aggregateClass aggregate class
* @param relBuilderFactory builder for relational expressions
* @param functionsToReduce client provided information
* on which specific functions
* will be reduced by this rule
*/
public AggregateReduceFunctionsRule(Class<? extends Aggregate> aggregateClass,
RelBuilderFactory relBuilderFactory, EnumSet<SqlKind> functionsToReduce) {
super(operand(aggregateClass, any()), relBuilderFactory, null);
Objects.requireNonNull(functionsToReduce,
"Expecting a valid handle for AggregateFunctionsToReduce");
this.functionsToReduce = EnumSet.noneOf(SqlKind.class);
for (SqlKind function : functionsToReduce) {
if (SqlKind.AVG_AGG_FUNCTIONS.contains(function)
|| SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(function)
|| function == SqlKind.SUM) {
this.functionsToReduce.add(function);
} else {
throw new IllegalArgumentException(
"AggregateReduceFunctionsRule doesn't support function: " + function.sql);
}
}
}
public static EnumSet<Metric> parseString(String param, boolean ignoreUnknown) {
String[] metrics = Strings.splitStringByCommaToArray(param);
EnumSet<Metric> result = EnumSet.noneOf(Metric.class);
for (String metric : metrics) {
if ("_all".equals(metric)) {
result = EnumSet.allOf(Metric.class);
break;
}
Metric m = valueToEnum.get(metric);
if (m == null) {
if (!ignoreUnknown) {
throw new IllegalArgumentException("Unknown metric [" + metric + "]");
}
} else {
result.add(m);
}
}
return result;
}
void run() throws Exception {
List<File> files = new ArrayList<File>();
File testSrc = new File(System.getProperty("test.src"));
for (File f: testSrc.listFiles()) {
if (f.isFile() && f.getName().endsWith(".java"))
files.add(f);
}
JavacTool javac = JavacTool.create();
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
JavacTask t = javac.getTask(null, fm, null, null, null, fos);
DocTrees trees = DocTrees.instance(t);
Iterable<? extends CompilationUnitTree> units = t.parse();
Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
DeclScanner ds = new DeclScanner(trees, found);
for (CompilationUnitTree unit: units) {
ds.scan(unit, null);
}
for (DocTree.Kind k: DocTree.Kind.values()) {
if (!found.contains(k) && k != DocTree.Kind.OTHER)
error("not found: " + k);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
static OperationHeaders fromOperation(ModelNode operation) throws OperationFailedException {
final EnumSet<OperationContextImpl.ContextFlag> contextFlags;
Integer blockingTimeout = null;
String warningLevel = null;
String domainUUID = null;
AccessMechanism accessMechanism = null;
if (operation.hasDefined(OPERATION_HEADERS)) {
final ModelNode headers = operation.get(OPERATION_HEADERS).clone();
final boolean rollbackOnFailure = ROLLBACK.resolveModelAttribute(ExpressionResolver.REJECTING, headers).asBoolean();
final boolean restartResourceServices = RESTART.resolveModelAttribute(ExpressionResolver.REJECTING, headers).asBoolean();
contextFlags = rollbackOnFailure ? EnumSet.of(AbstractOperationContext.ContextFlag.ROLLBACK_ON_FAIL) : EnumSet.noneOf(OperationContextImpl.ContextFlag.class);
if (restartResourceServices) {
contextFlags.add(AbstractOperationContext.ContextFlag.ALLOW_RESOURCE_SERVICE_RESTART);
}
final ModelNode blockingTimeoutConfig = BLOCKING.resolveModelAttribute(ExpressionResolver.REJECTING, headers);
if (blockingTimeoutConfig.isDefined()) {
blockingTimeout = blockingTimeoutConfig.asInt();
// Check the value is positive. We could use a ParameterValidator on the AttributeDefinition to do this but since
// in the past we used this particular failure message, let's stick with it just to not change things.
// Note that failure message compatibility has never been a requirement though, so we could change this.
if (blockingTimeout < 1) {
throw ControllerLogger.MGMT_OP_LOGGER.invalidBlockingTimeout(blockingTimeout.longValue(), BLOCKING_TIMEOUT);
}
}
warningLevel = headers.hasDefined(WARNING_LEVEL) ? headers.get(WARNING_LEVEL).asString() : null;
domainUUID = headers.hasDefined(DOMAIN_UUID) ? headers.get(DOMAIN_UUID).asString() : null;
accessMechanism = headers.hasDefined(ACCESS_MECHANISM) ? AccessMechanism.valueOf(headers.get(ACCESS_MECHANISM).asString()) : null;
} else {
contextFlags = EnumSet.of(AbstractOperationContext.ContextFlag.ROLLBACK_ON_FAIL);
}
return new OperationHeaders(contextFlags, blockingTimeout, warningLevel, domainUUID, accessMechanism);
}
public static EnumSet<Flag> asFlagSet(long flags) {
EnumSet<Flag> flagSet = EnumSet.noneOf(Flag.class);
for (Flag flag : Flag.values()) {
if ((flags & flag.value) != 0) {
flagSet.add(flag);
flags &= ~flag.value;
}
}
Assert.check(flags == 0);
return flagSet;
}
@Override
protected EnumSet<OperandFlag> getFlags(Field field) {
EnumSet<OperandFlag> result = EnumSet.noneOf(OperandFlag.class);
if (field.isAnnotationPresent(CompositeValue.Component.class)) {
result.addAll(Arrays.asList(field.getAnnotation(CompositeValue.Component.class).value()));
} else {
GraalError.shouldNotReachHere();
}
return result;
}
EnumSet<BoxItem.Permission> getPermissions() {
EnumSet<BoxItem.Permission> permissions = EnumSet.noneOf(BoxItem.Permission.class);
for (String key : getPropertiesKeySet()){
Boolean value = getPropertyAsBoolean(key);
if (value == null || value == false) {
continue;
}
if (key.equals(BoxItem.Permission.CAN_DOWNLOAD.toString())) {
permissions.add(BoxItem.Permission.CAN_DOWNLOAD);
} else if (key.equals(BoxItem.Permission.CAN_UPLOAD.toString())) {
permissions.add(BoxItem.Permission.CAN_UPLOAD);
} else if (key.equals(BoxItem.Permission.CAN_RENAME.toString())) {
permissions.add(BoxItem.Permission.CAN_RENAME);
} else if (key.equals(BoxItem.Permission.CAN_DELETE.toString())) {
permissions.add(BoxItem.Permission.CAN_DELETE);
} else if (key.equals(BoxItem.Permission.CAN_SHARE.toString())) {
permissions.add(BoxItem.Permission.CAN_SHARE);
} else if (key.equals(BoxItem.Permission.CAN_SET_SHARE_ACCESS.toString())) {
permissions.add(BoxItem.Permission.CAN_SET_SHARE_ACCESS);
} else if (key.equals(BoxItem.Permission.CAN_PREVIEW.toString())) {
permissions.add(BoxItem.Permission.CAN_PREVIEW);
} else if (key.equals(BoxItem.Permission.CAN_COMMENT.toString())) {
permissions.add(BoxItem.Permission.CAN_COMMENT);
} else if (key.equals(BoxItem.Permission.CAN_INVITE_COLLABORATOR.toString())) {
permissions.add(BoxItem.Permission.CAN_INVITE_COLLABORATOR);
}
}
return permissions;
}
/**
* Returns a new, <i>mutable</i> {@code EnumSet} instance containing the given elements in their
* natural order. This method behaves identically to {@link EnumSet#copyOf(Collection)}, but also
* accepts non-{@code Collection} iterables and empty iterables.
*/
public static <E extends Enum<E>> EnumSet<E> newEnumSet(
Iterable<E> iterable, Class<E> elementType) {
EnumSet<E> set = EnumSet.noneOf(elementType);
Iterables.addAll(set, iterable);
return set;
}
/**
* Get an EnumSet of {@link VatInfo} from a String representation produced with
* {@link VatInfo#encodeAsString(EnumSet)}.
*
* @param code
* @return
*/
public static EnumSet<VatInfo> decodeFromString(String code){
String[] names = code.split(",");
EnumSet<VatInfo> ret = EnumSet.noneOf(VatInfo.class);
for (int i = 0; i < names.length; i++) {
ret.add(VatInfo.valueOf(names[i]));
}
return ret;
}
public static Set<Flag> valuesOf(final short flags) {
Set<Flag> result = EnumSet.noneOf(Flag.class);
for (Flag flag : values()) {
if ((flag.getValue() & flags) > 0) {
result.add(flag);
}
}
return result;
}
@SuppressWarnings("fallthrough")
public RichConfiguration(Options options, AbstractDiagnosticFormatter formatter) {
super(formatter.getConfiguration());
features = formatter.isRaw() ? EnumSet.noneOf(RichFormatterFeature.class) :
EnumSet.of(RichFormatterFeature.SIMPLE_NAMES,
RichFormatterFeature.WHERE_CLAUSES,
RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
String diagOpts = options.get("diags");
if (diagOpts != null) {
for (String args: diagOpts.split(",")) {
if (args.equals("-where")) {
features.remove(RichFormatterFeature.WHERE_CLAUSES);
}
else if (args.equals("where")) {
features.add(RichFormatterFeature.WHERE_CLAUSES);
}
if (args.equals("-simpleNames")) {
features.remove(RichFormatterFeature.SIMPLE_NAMES);
}
else if (args.equals("simpleNames")) {
features.add(RichFormatterFeature.SIMPLE_NAMES);
}
if (args.equals("-disambiguateTvars")) {
features.remove(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
}
else if (args.equals("disambiguateTvars")) {
features.add(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
}
}
}
}
/**
* Returns all of the validation failures in this {@code DataflowProject}.
*/
private Collection<DataflowProjectValidationStatus> failedValidations() {
Collection<DataflowProjectValidationStatus> statuses =
EnumSet.noneOf(DataflowProjectValidationStatus.class);
statuses.add(validateProjectName());
statuses.add(validateProjectLocation());
statuses.add(validateMavenGroupId());
statuses.add(validateMavenArtifactId());
statuses.add(validatePackage());
// Must be last: Remove OK so the set contains only failed validations.
statuses.remove(DataflowProjectValidationStatus.OK);
return statuses;
}
/**
* Returns the default parse options used by this <code>TimeZoneFormat</code> instance.
* @return the default parse options.
* @see ParseOption
* @stable ICU 49
*/
public EnumSet<ParseOption> getDefaultParseOptions() {
if (_parseAllStyles && _parseTZDBNames) {
return EnumSet.of(ParseOption.ALL_STYLES, ParseOption.TZ_DATABASE_ABBREVIATIONS);
} else if (_parseAllStyles) {
return EnumSet.of(ParseOption.ALL_STYLES);
} else if (_parseTZDBNames) {
return EnumSet.of(ParseOption.TZ_DATABASE_ABBREVIATIONS);
}
return EnumSet.noneOf(ParseOption.class);
}
@Override
void parseSizeRotatingHandlerElement(final XMLExtendedStreamReader reader, final PathAddress address, final List<ModelNode> operations, final Set<String> names) throws XMLStreamException {
final ModelNode operation = Util.createAddOperation();
// Attributes
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
name = value;
break;
}
case AUTOFLUSH: {
AUTOFLUSH.parseAndSetParameter(value, operation, reader);
break;
}
case ENABLED: {
ENABLED.parseAndSetParameter(value, operation, reader);
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
if (!names.add(name)) {
throw duplicateNamedElement(reader, name);
}
// Setup the operation address
addOperationAddress(operation, address, SizeRotatingHandlerResourceDefinition.NAME, name);
final EnumSet<Element> requiredElem = EnumSet.of(Element.FILE);
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
requiredElem.remove(element);
switch (element) {
case LEVEL: {
LEVEL.parseAndSetParameter(readNameAttribute(reader), operation, reader);
break;
}
case ENCODING: {
ENCODING.parseAndSetParameter(readValueAttribute(reader), operation, reader);
break;
}
case FILTER_SPEC: {
SizeRotatingHandlerResourceDefinition.FILTER_SPEC.parseAndSetParameter(readValueAttribute(reader), operation, reader);
break;
}
case FORMATTER: {
parseHandlerFormatterElement(reader, operation);
break;
}
case FILE: {
parseFileElement(operation.get(FILE.getName()), reader);
break;
}
case APPEND: {
APPEND.parseAndSetParameter(readValueAttribute(reader), operation, reader);
break;
}
case ROTATE_SIZE: {
ROTATE_SIZE.parseAndSetParameter(readValueAttribute(reader), operation, reader);
break;
}
case MAX_BACKUP_INDEX: {
MAX_BACKUP_INDEX.parseAndSetParameter(readValueAttribute(reader), operation, reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
operations.add(operation);
}
@Test // SPR-17619
public void createsEnumSetSubclass() {
EnumSet<Color> enumSet = EnumSet.noneOf(Color.class);
assertThat(createCollection(enumSet.getClass(), Color.class, 0), is(instanceOf(enumSet.getClass())));
}
/** Constructs with case-insensitive keys. */
public GenericData() {
this(EnumSet.noneOf(Flags.class));
}
@Override
public Set<Option> options()
{
return EnumSet.noneOf(Option.class);
}
protected Set<EnumPublic> getAnotherObject() {
Set<EnumPublic> set = EnumSet.noneOf(EnumPublic.class);
set.add(EnumPublic.A);
set.add(EnumPublic.Z);
return set;
}
public void setPowerfulPlanets(Map<Planet, Double> strengthPercent){
powerfulPlanets = EnumSet.noneOf(Planet.class);
for(Entry<Planet,Double> entry : strengthPercent.entrySet()){
if (entry.getValue().doubleValue() >= POWERFUL_PLANET_THRESHOLD){
powerfulPlanets.add(entry.getKey());
}
}
log.fine(powerfulPlanets.toString());
}
/**
* <p>Creates a bit vector representation of the given subset of an Enum using as many {@code long}s as needed.</p>
*
* <p>This generates a value that is usable by {@link EnumUtils#processBitVectors}.</p>
*
* <p>Use this method if you have more than 64 values in your Enum.</p>
*
* @param enumClass the class of the enum we are working with, not {@code null}
* @param values the values we want to convert, not {@code null}, neither containing {@code null}
* @param <E> the type of the enumeration
* @return a long[] whose values provide a binary representation of the given set of enum values
* with least significant digits rightmost.
* @throws NullPointerException if {@code enumClass} or {@code values} is {@code null}
* @throws IllegalArgumentException if {@code enumClass} is not an enum class, or if any {@code values} {@code null}
* @since 3.2
*/
public static <E extends Enum<E>> long[] generateBitVectors(Class<E> enumClass, E... values) {
asEnum(enumClass);
Validate.noNullElements(values);
final EnumSet<E> condensed = EnumSet.noneOf(enumClass);
Collections.addAll(condensed, values);
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
for (E value : condensed) {
result[value.ordinal() / Long.SIZE] |= 1 << (value.ordinal() % Long.SIZE);
}
ArrayUtils.reverse(result);
return result;
}