Java Code Examples for java.util.EnumSet#add()

The following examples show how to use java.util.EnumSet#add() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: 1.13-Command-API   File: NMS_1_13_2.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
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);
    }
}
 
Example 3
/**
 * 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;
}
 
Example 4
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;
}
 
Example 5
Source Project: RDFS   File: DistCp.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source Project: openjdk-8   File: Resolve.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 7
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();
}
 
Example 8
Source Project: swift-k   File: StagingSetEntry.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
/**
 * @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);
    }
}
 
Example 10
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;

}
 
Example 11
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;
}
 
Example 12
/**
 * @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);
    }
}
 
Example 13
/**
 * 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;
}
 
Example 14
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();
}
 
Example 15
/**
 * @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);
    }
}
 
Example 16
/**
 * @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;
}
 
Example 17
Source Project: netbeans   File: CompromiseSATest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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();
}
 
Example 18
/**
 * 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));
}
 
Example 19
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;
	}
 
Example 20
/**
 * 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);
}