下面列出了java.util.EnumSet#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public EnumSet<Axis> getAxis(CommandContext cmdCtx, String key) {
EnumSet<Axis> set = EnumSet.noneOf(Axis.class);
EnumSet<EnumAxis> parsedEnumSet = ArgumentRotationAxis.a(cmdCtx, key);
for (EnumAxis element : parsedEnumSet) {
switch (element) {
case X:
set.add(Axis.X);
break;
case Y:
set.add(Axis.Y);
break;
case Z:
set.add(Axis.Z);
break;
}
}
return set;
}
public void addClusters(String contingencyId, EnumSet<WCAClusterNum> clustersNums, WCAClusterOrigin flag) {
Objects.requireNonNull(contingencyId, "contingency id is null");
Objects.requireNonNull(clustersNums, "clustersNums is null");
LOGGER.info("Network {}, contingency {}: adding clusters {} for {}", networkId, contingencyId, clustersNums.toString(), flag);
if (contingencyClusters.containsKey(contingencyId)) {
// add clusters to the list of the contingency
EnumSet<WCAClusterNum> clusters = contingencyClusters.get(contingencyId);
clustersNums.forEach(clusterNum -> clusters.add(clusterNum));
contingencyClusters.put(contingencyId, clusters);
if (flag != null) {
// add flag to the list of the contingency
EnumSet<WCAClusterOrigin> flags = EnumSet.noneOf(WCAClusterOrigin.class);
if (contingencyFlags.containsKey(contingencyId)) {
flags = contingencyFlags.get(contingencyId);
}
flags.add(flag);
contingencyFlags.put(contingencyId, flags);
}
} else {
LOGGER.warn("Network {}, contingency {}: no possible clusters", networkId, contingencyId);
}
}
/**
* Returns a collection of time zone display name matches for the specified types in the
* given text at the given offset. This method only finds matches from the TimeZoneNames
* used by this object.
* @param text the text
* @param start the start offset in the text
* @param types the set of name types.
* @return A collection of match info.
*/
private Collection<MatchInfo> findTimeZoneNames(String text, int start, EnumSet<GenericNameType> types) {
Collection<MatchInfo> tznamesMatches = null;
// Check if the target name type is really in the TimeZoneNames
EnumSet<NameType> nameTypes = EnumSet.noneOf(NameType.class);
if (types.contains(GenericNameType.LONG)) {
nameTypes.add(NameType.LONG_GENERIC);
nameTypes.add(NameType.LONG_STANDARD);
}
if (types.contains(GenericNameType.SHORT)) {
nameTypes.add(NameType.SHORT_GENERIC);
nameTypes.add(NameType.SHORT_STANDARD);
}
if (!nameTypes.isEmpty()) {
// Find matches in the TimeZoneNames
tznamesMatches = _tznames.find(text, start, nameTypes);
}
return tznamesMatches;
}
private EnumSet<SharedAccessFilePermissions> getPermissions(int bits) {
EnumSet<SharedAccessFilePermissions> permissionSet = EnumSet.noneOf(SharedAccessFilePermissions.class);
if ((bits & 0x1) == 0x1) {
permissionSet.add(SharedAccessFilePermissions.READ);
}
if ((bits & 0x2) == 0x2) {
permissionSet.add(SharedAccessFilePermissions.CREATE);
}
if ((bits & 0x4) == 0x4) {
permissionSet.add(SharedAccessFilePermissions.WRITE);
}
if ((bits & 0x8) == 0x8) {
permissionSet.add(SharedAccessFilePermissions.DELETE);
}
if ((bits & 0x10) == 0x10) {
permissionSet.add(SharedAccessFilePermissions.LIST);
}
return permissionSet;
}
static EnumSet<FileAttribute> parse(String s) {
if (s == null || s.length() == 0) {
return EnumSet.allOf(FileAttribute.class);
}
EnumSet<FileAttribute> set = EnumSet.noneOf(FileAttribute.class);
FileAttribute[] attributes = values();
for(char c : s.toCharArray()) {
int i = 0;
for(; i < attributes.length && c != attributes[i].symbol; i++);
if (i < attributes.length) {
if (!set.contains(attributes[i])) {
set.add(attributes[i]);
} else {
throw new IllegalArgumentException("There are more than one '"
+ attributes[i].symbol + "' in " + s);
}
} else {
throw new IllegalArgumentException("'" + c + "' in " + s
+ " is undefined.");
}
}
return set;
}
static EnumSet<VerboseResolutionMode> getVerboseResolutionMode(Options opts) {
String s = opts.get("verboseResolution");
EnumSet<VerboseResolutionMode> res = EnumSet.noneOf(VerboseResolutionMode.class);
if (s == null) return res;
if (s.contains("all")) {
res = EnumSet.allOf(VerboseResolutionMode.class);
}
Collection<String> args = Arrays.asList(s.split(","));
for (VerboseResolutionMode mode : values()) {
if (args.contains(mode.opt)) {
res.add(mode);
} else if (args.contains("-" + mode.opt)) {
res.remove(mode);
}
}
return res;
}
private void testFlagsSetSequence(Supplier<StatefulTestOp<Integer>> cf) {
EnumSet<StreamOpFlag> known = EnumSet.of(StreamOpFlag.ORDERED, StreamOpFlag.SIZED);
EnumSet<StreamOpFlag> preserve = EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED);
List<IntermediateTestOp<Integer, Integer>> ops = new ArrayList<>();
for (StreamOpFlag f : EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED)) {
ops.add(cf.get());
ops.add(new TestFlagExpectedOp<>(f.set(),
known.clone(),
preserve.clone(),
EnumSet.noneOf(StreamOpFlag.class)));
known.add(f);
preserve.remove(f);
}
ops.add(cf.get());
ops.add(new TestFlagExpectedOp<>(0,
known.clone(),
preserve.clone(),
EnumSet.noneOf(StreamOpFlag.class)));
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
@SuppressWarnings("rawtypes")
IntermediateTestOp[] opsArray = ops.toArray(new IntermediateTestOp[ops.size()]);
withData(data).ops(opsArray).
without(StreamTestScenario.CLEAR_SIZED_SCENARIOS).
exercise();
}
public static EnumSet<Mode> fromId(int id) {
EnumSet<Mode> mode = EnumSet.noneOf(Mode.class);
if (id == 0) {
mode.add(ALWAYS);
}
else {
for (Mode m : ALL) {
if ((id & m.getId()) != 0) {
mode.add(m);
}
}
}
return mode;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Bridge.init();
EnumSet<TestCase> tests = EnumSet.noneOf(TestCase.class);
for (String arg : args) {
tests.add(TestCase.valueOf(arg));
}
if (args.length == 0) {
tests = EnumSet.complementOf(EnumSet.of(TestCase.LoadingMain));
}
final EnumSet<TestCase> loadingTests =
EnumSet.of(TestCase.LoadingApplet, TestCase.LoadingMain);
int testrun = 0;
for (TestCase test : tests) {
if (loadingTests.contains(test)) {
if (testrun > 0) {
throw new UnsupportedOperationException("Test case "
+ test + " must be executed first!");
}
}
System.out.println("Testing "+ test+": ");
System.out.println(test.describe());
try {
test.test();
} catch (Exception x) {
throw new Error(String.valueOf(test)
+ (System.getSecurityManager() == null ? " without " : " with ")
+ "security failed: "+x+"\n "+"FAILED: "+test.describe()+"\n", x);
} finally {
testrun++;
}
Bridge.changeContext();
System.out.println("PASSED: "+ test);
}
}
static UnifiedHighlighter randomUnifiedHighlighter(IndexSearcher searcher, Analyzer indexAnalyzer,
EnumSet<HighlightFlag> mandatoryFlags, Boolean requireFieldMatch) {
final UnifiedHighlighter uh = new UnifiedHighlighter(searcher, indexAnalyzer) {
Set<HighlightFlag> flags; // consistently random set of flags for this test run
@Override
protected Set<HighlightFlag> getFlags(String field) {
if (flags != null) {
return flags;
}
final EnumSet<HighlightFlag> result = EnumSet.copyOf(mandatoryFlags);
int r = random().nextInt();
for (HighlightFlag highlightFlag : HighlightFlag.values()) {
if (((1 << highlightFlag.ordinal()) & r) == 0) {
result.add(highlightFlag);
}
}
if (result.contains(HighlightFlag.WEIGHT_MATCHES)) {
// these two are required for WEIGHT_MATCHES
result.add(HighlightFlag.MULTI_TERM_QUERY);
result.add(HighlightFlag.PHRASES);
}
return flags = result;
}
};
uh.setCacheFieldValCharsThreshold(random().nextInt(100));
if (requireFieldMatch == Boolean.FALSE || (requireFieldMatch == null && random().nextBoolean())) {
uh.setFieldMatcher(f -> true); // requireFieldMatch==false
}
return uh;
}
private static EnumSet<WorldType> getTypes(int mask)
{
EnumSet<WorldType> types = EnumSet.noneOf(WorldType.class);
for (ServiceWorldType type : ServiceWorldType.values())
{
if ((mask & type.getMask()) != 0)
{
types.add(type.getApiType());
}
}
return types;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Bridge.init();
EnumSet<TestCase> tests = EnumSet.noneOf(TestCase.class);
for (String arg : args) {
tests.add(TestCase.valueOf(arg));
}
if (args.length == 0) {
tests = EnumSet.complementOf(EnumSet.of(TestCase.LoadingMain));
}
final EnumSet<TestCase> loadingTests =
EnumSet.of(TestCase.LoadingApplet, TestCase.LoadingMain);
int testrun = 0;
for (TestCase test : tests) {
if (loadingTests.contains(test)) {
if (testrun > 0) {
throw new UnsupportedOperationException("Test case "
+ test + " must be executed first!");
}
}
System.out.println("Testing "+ test+": ");
System.out.println(test.describe());
try {
test.test();
} catch (Exception x) {
throw new Error(String.valueOf(test)
+ (System.getSecurityManager() == null ? " without " : " with ")
+ "security failed: "+x+"\n "+"FAILED: "+test.describe()+"\n", x);
} finally {
testrun++;
}
Bridge.changeContext();
System.out.println("PASSED: "+ test);
}
}
/**
* Create a constraints object.
*
* @param flags constraint flags
* @return constraints object
*/
public static Object constraint(SLayout ... flags) {
EnumSet<SLayout> obj = EnumSet.noneOf(SLayout.class);
for (SLayout flag : flags) {
obj.add(flag);
}
return obj;
}
private void testFlagsSetSequence(Supplier<StatefulTestOp<Integer>> cf) {
EnumSet<StreamOpFlag> known = EnumSet.of(StreamOpFlag.ORDERED, StreamOpFlag.SIZED);
EnumSet<StreamOpFlag> preserve = EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED);
List<IntermediateTestOp<Integer, Integer>> ops = new ArrayList<>();
for (StreamOpFlag f : EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED)) {
ops.add(cf.get());
ops.add(new TestFlagExpectedOp<>(f.set(),
known.clone(),
preserve.clone(),
EnumSet.noneOf(StreamOpFlag.class)));
known.add(f);
preserve.remove(f);
}
ops.add(cf.get());
ops.add(new TestFlagExpectedOp<>(0,
known.clone(),
preserve.clone(),
EnumSet.noneOf(StreamOpFlag.class)));
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
@SuppressWarnings("rawtypes")
IntermediateTestOp[] opsArray = ops.toArray(new IntermediateTestOp[ops.size()]);
withData(data).ops(opsArray).
without(StreamTestScenario.PAR_STREAM_TO_ARRAY_CLEAR_SIZED).
exercise();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Bridge.init();
EnumSet<TestCase> tests = EnumSet.noneOf(TestCase.class);
for (String arg : args) {
tests.add(TestCase.valueOf(arg));
}
if (args.length == 0) {
tests = EnumSet.complementOf(EnumSet.of(TestCase.LoadingMain));
}
final EnumSet<TestCase> loadingTests =
EnumSet.of(TestCase.LoadingApplet, TestCase.LoadingMain);
int testrun = 0;
for (TestCase test : tests) {
if (loadingTests.contains(test)) {
if (testrun > 0) {
throw new UnsupportedOperationException("Test case "
+ test + " must be executed first!");
}
}
System.out.println("Testing "+ test+": ");
System.out.println(test.describe());
try {
test.test();
} catch (Exception x) {
throw new Error(String.valueOf(test)
+ (System.getSecurityManager() == null ? " without " : " with ")
+ "security failed: "+x+"\n "+"FAILED: "+test.describe()+"\n", x);
} finally {
testrun++;
}
Bridge.changeContext();
System.out.println("PASSED: "+ test);
}
}
/**
* @return The currently selected DialogOptions.
*/
protected final EnumSet<DialogOption> getSelectedOptions() {
EnumSet<DialogOption> selected = EnumSet.noneOf(DialogOption.class);
for (Item item : mItems) {
if (item.isSelected()) selected.add(item.getOption());
}
return selected;
}
/**
* Tests (=(decode (encode T)) T)
*/
public void testEncodeUsageType() {
EnumSet<UsageType> c = EnumSet.noneOf(UsageType.class);
c.add (UsageType.SUPER_CLASS);
c.add (UsageType.SUPER_INTERFACE);
String s = DocumentUtil.encodeUsage("foo", c);
Set<UsageType> r = EnumSet.noneOf(UsageType.class);
DocumentUtil.decodeUsage(s,r);
assertEquals(c.size(), r.size());
assertTrue(r.containsAll(c));
c.clear();
c.add (UsageType.TYPE_REFERENCE);
s = DocumentUtil.encodeUsage("foo", c);
r = EnumSet.noneOf(UsageType.class);
DocumentUtil.decodeUsage(s,r);
assertEquals(c.size(), r.size());
assertTrue(r.containsAll(c));
c.clear();
c.add (UsageType.SUPER_CLASS);
c.add (UsageType.TYPE_REFERENCE);
c.add (UsageType.FIELD_REFERENCE);
s = DocumentUtil.encodeUsage("foo", c);
r = EnumSet.noneOf(UsageType.class);
DocumentUtil.decodeUsage(s,r);
assertEquals(c.size(), r.size());
assertTrue(r.containsAll(c));
c.clear();
c.add (UsageType.SUPER_CLASS);
c.add (UsageType.METHOD_REFERENCE);
s = DocumentUtil.encodeUsage("foo", c);
r = EnumSet.noneOf(UsageType.class);
DocumentUtil.decodeUsage(s,r);
assertEquals(c.size(), r.size());
assertTrue(r.containsAll(c));
c.clear();
c.allOf(UsageType.class);
s = DocumentUtil.encodeUsage("foo", c);
r = EnumSet.noneOf(UsageType.class);
DocumentUtil.decodeUsage(s,r);
assertEquals(c.size(), r.size());
assertTrue(r.containsAll(c));
c.clear();
c.add (UsageType.SUPER_INTERFACE);
c.add (UsageType.METHOD_REFERENCE);
s = DocumentUtil.encodeUsage("foo", c);
r = EnumSet.noneOf(UsageType.class);
DocumentUtil.decodeUsage(s,r);
assertEquals(c.size(), r.size());
assertTrue(r.containsAll(c));
c.clear();
}
/**
* Add a state to the total CompilationState of this node, e.g. if
* FunctionNode has been lowered, the compiler will add
* {@code CompilationState#LOWERED} to the state vector
*
* @param lc lexical context
* @param state {@link CompilationState} to add
* @return function node or a new one if state was changed
*/
public FunctionNode setState(final LexicalContext lc, final CompilationState state) {
if (this.compilationState.contains(state)) {
return this;
}
final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);
newState.add(state);
return Node.replaceInLexicalContext(lc, this, new FunctionNode(this, lastToken, flags, name, returnType, compileUnit, newState, body, parameters, snapshot, hints));
}
public static EnumSet<OptionsMenuUtility.OptionsMenuItemsPref> pref_menus_optionsmenu_items(final Context context, final SharedPreferences sharedPreferences) {
final Set<String> strings = getStringSet(R.string.pref_menus_optionsmenu_items_key, R.array.pref_menus_optionsmenu_items_items_default, context, sharedPreferences);
final EnumSet<OptionsMenuUtility.OptionsMenuItemsPref> result = EnumSet.noneOf(OptionsMenuUtility.OptionsMenuItemsPref.class);
for(String s : strings) result.add(OptionsMenuUtility.OptionsMenuItemsPref.valueOf(General.asciiUppercase(s)));
return result;
}
/**
* Add a state to the total CompilationState of this node, e.g. if
* FunctionNode has been lowered, the compiler will add
* {@code CompilationState#LOWERED} to the state vector
*
* @param lc lexical context
* @param state {@link CompilationState} to add
* @return function node or a new one if state was changed
*/
public FunctionNode setState(final LexicalContext lc, final CompilationState state) {
if (!AssertsEnabled.assertsEnabled() || this.compilationState.contains(state)) {
return this;
}
final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);
newState.add(state);
return setCompilationState(lc, newState);
}