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

The following examples show how to use java.util.EnumSet#allOf() . 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 File: ConnectionProfile.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a connection profile that is dedicated to a single channel type. Allows passing connection and
 * handshake timeouts and compression settings.
 */
public static ConnectionProfile buildSingleChannelProfile(TransportRequestOptions.Type channelType, @Nullable TimeValue connectTimeout,
                                                          @Nullable TimeValue handshakeTimeout, @Nullable TimeValue pingInterval,
                                                          @Nullable Boolean compressionEnabled) {
    Builder builder = new Builder();
    builder.addConnections(1, channelType);
    final EnumSet<TransportRequestOptions.Type> otherTypes = EnumSet.allOf(TransportRequestOptions.Type.class);
    otherTypes.remove(channelType);
    builder.addConnections(0, otherTypes.toArray(new TransportRequestOptions.Type[0]));
    if (connectTimeout != null) {
        builder.setConnectTimeout(connectTimeout);
    }
    if (handshakeTimeout != null) {
        builder.setHandshakeTimeout(handshakeTimeout);
    }
    if (pingInterval != null) {
        builder.setPingInterval(pingInterval);
    }
    if (compressionEnabled != null) {
        builder.setCompressionEnabled(compressionEnabled);
    }
    return builder.build();
}
 
Example 2
Source File: ProxyDataItem.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param id
 * @param proxyValueHolder
 * @param executor
 *            the executor to use for write calls
 */
public ProxyDataItem ( final String id, final ProxyValueHolder proxyValueHolder, final ProxyWriteHandler writeHandler, final Executor executor )
{
    super ( new DataItemInformationBase ( id, EnumSet.allOf ( IODirection.class ) ), executor );
    this.proxyValueHolder = proxyValueHolder;
    this.proxyValueHolder.setListener ( new ItemUpdateListener () {
        @Override
        public void notifyDataChange ( final Variant value, final Map<String, Variant> attributes, final boolean cache )
        {
            ProxyDataItem.this.updateData ( value, attributes, cache ? AttributeMode.SET : AttributeMode.UPDATE );
        }

        @Override
        public void notifySubscriptionChange ( final SubscriptionState subscriptionState, final Throwable subscriptionError )
        {
            // TODO: (jr2) is there something which is to be done?
        }
    } );

    this.writeHandler = writeHandler;
}
 
Example 3
Source File: SkylarkProjectBuildFileParserTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void nativeFunctionUsageAtTopLevelIsReportedAsAnError() throws Exception {
  EventCollector eventCollector = new EventCollector(EnumSet.allOf(EventKind.class));
  parser = createParser(eventCollector);
  Path buildFile = projectFilesystem.resolve("BUCK");
  Files.write(buildFile, Collections.singletonList("load('//:ext.bzl', 'ext')"));
  Path extensionFile = projectFilesystem.resolve("ext.bzl");
  Files.write(extensionFile, Collections.singletonList("ext = native.read_config('foo', 'bar')"));
  try {
    parser.getManifest(buildFile);
    fail("Parsing should have failed.");
  } catch (BuildFileParseException e) {
    Event printEvent = eventCollector.iterator().next();
    assertThat(
        printEvent.getMessage(),
        equalTo(
            "Top-level invocations of native.read_config are not allowed in .bzl files. "
                + "Wrap it in a macro and call it from a BUCK file."));
    assertThat(printEvent.getKind(), equalTo(EventKind.ERROR));
  }
}
 
Example 4
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method is used to parse the {@code find} option.
 * Possible modes are separated by colon; a mode can be excluded by
 * prepending '-' to its name. Finally, the special mode 'all' can be used to
 * add all modes to the resulting enum.
 */
static EnumSet<AnalyzerMode> getAnalyzerModes(String opt, Source source) {
    if (opt == null) {
        return EnumSet.noneOf(AnalyzerMode.class);
    }
    List<String> modes = List.from(opt.split(","));
    EnumSet<AnalyzerMode> res = EnumSet.noneOf(AnalyzerMode.class);
    if (modes.contains("all")) {
        res = EnumSet.allOf(AnalyzerMode.class);
    }
    for (AnalyzerMode mode : values()) {
        if (modes.contains(mode.opt)) {
            res.add(mode);
        } else if (modes.contains("-" + mode.opt) || !mode.sourceFilter.test(source)) {
            res.remove(mode);
        }
    }
    return res;
}
 
Example 5
Source File: EdfiEntityTest.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testLayersFinish() {
    Set<EdfiEntity> set = EnumSet.allOf(EdfiEntity.class);

    for (int i = 1; i < 100; i++) {
        Set<EdfiEntity> cleansed = EdfiEntity.cleanse(set);
        set.removeAll(cleansed);
        LOG.info(cleansed.toString());
        if (set.isEmpty()) {
            LOG.info("Dependency diminuation finished in: {} passes", i);
            break;
        }
    }
}
 
Example 6
Source File: Enums.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@GwtIncompatible // java.lang.ref.WeakReference
private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache(Class<T> enumClass) {
  Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<String, WeakReference<? extends Enum<?>>>();
  for (T enumInstance : EnumSet.allOf(enumClass)) {
    result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance));
  }
  enumConstantCache.put(enumClass, result);
  return result;
}
 
Example 7
Source File: BaseOutputDialog.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create an output dialog for the given shell.
 * 
 * @param parentShell the shell to create this dialog in.
 * @param extension the file type extension.
 * @param components the set of task parameter components to show.
 * If empty, show all components.
 */
public BaseOutputDialog(Shell parentShell, String extension,
    Component... components) {
  super(parentShell);
  this.extension = extension;
  if (components.length == 0) {
    this.components = EnumSet.allOf(Component.class);
  } else {
    this.components = EnumSet.noneOf(Component.class);
    this.components.addAll(Arrays.asList(components));
  }
}
 
Example 8
Source File: StartupProgress.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the entire startup process has completed, determined by
 * checking if each phase is complete.
 * 
 * @return boolean true if the entire startup process has completed
 */
private boolean isComplete() {
  for (Phase phase: EnumSet.allOf(Phase.class)) {
    if (getStatus(phase) != Status.COMPLETE) {
      return false;
    }
  }
  return true;
}
 
Example 9
Source File: FileBench.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static <T extends Enum<T>> EnumSet<T> rem(Class<T> c,
    EnumSet<T> set, String s) {
  if (null != fullmap.get(c) && fullmap.get(c).get(s) != null) {
    if (null == set) {
      set = EnumSet.allOf(c);
    }
    set.remove(fullmap.get(c).get(s));
  }
  return set;
}
 
Example 10
Source File: StateFilter.java    From vespa with Apache License 2.0 5 votes vote down vote up
/** Returns a node filter which matches a comma or space-separated list of states */
public static StateFilter from(String states, boolean includeDeprovisioned, NodeFilter next) {
    if (states == null) {
        return new StateFilter(includeDeprovisioned ?
                EnumSet.allOf(Node.State.class) : EnumSet.complementOf(EnumSet.of(Node.State.deprovisioned)), next);
    }

    return new StateFilter(StringUtilities.split(states).stream().map(Node.State::valueOf).collect(Collectors.toSet()), next);
}
 
Example 11
Source File: OptimizerOptions.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Compares the output of the optimizer run normally with a run skipping
 * some optional steps. Results are printed to stderr.
 *
 * @param nonOptRmeth {@code non-null;} origional rop method
 * @param paramSize {@code >= 0;} parameter size of method
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param args {@code non-null;} translator arguments
 * @param advice {@code non-null;} translation advice
 * @param rmeth {@code non-null;} method with all optimization steps run.
 */
public static void compareOptimizerStep(RopMethod nonOptRmeth,
        int paramSize, boolean isStatic, CfOptions args,
        TranslationAdvice advice, RopMethod rmeth) {
    EnumSet<Optimizer.OptionalStep> steps;

    steps = EnumSet.allOf(Optimizer.OptionalStep.class);

    // This is the step to skip.
    steps.remove(Optimizer.OptionalStep.CONST_COLLECTOR);

    RopMethod skipRopMethod
            = Optimizer.optimize(nonOptRmeth,
                    paramSize, isStatic, args.localInfo, advice, steps);

    int normalInsns
            = rmeth.getBlocks().getEffectiveInstructionCount();
    int skipInsns
            = skipRopMethod.getBlocks().getEffectiveInstructionCount();

    System.err.printf(
            "optimize step regs:(%d/%d/%.2f%%)"
            + " insns:(%d/%d/%.2f%%)\n",
            rmeth.getBlocks().getRegCount(),
            skipRopMethod.getBlocks().getRegCount(),
            100.0 * ((skipRopMethod.getBlocks().getRegCount()
                    - rmeth.getBlocks().getRegCount())
                    / (float) skipRopMethod.getBlocks().getRegCount()),
            normalInsns, skipInsns,
            100.0 * ((skipInsns - normalInsns) / (float) skipInsns));
}
 
Example 12
Source File: SkylarkUserDefinedRulesParserTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void attrsOutputHandlesAbsentDefault() throws IOException, InterruptedException {
  setupWorkspace("attr");

  EventCollector eventCollector = new EventCollector(EnumSet.allOf(EventKind.class));
  Path noDefault = projectFilesystem.resolve("output").resolve("no_default").resolve("BUCK");

  parser = createParser(eventCollector);

  assertParserFails(
      eventCollector,
      parser,
      noDefault,
      "output attributes must have a default value, or be mandatory");
}
 
Example 13
Source File: SkylarkUserDefinedRulesParserTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void acceptsAutomaticallyAddedAttributes() throws IOException, InterruptedException {
  setupWorkspace("rule_with_builtin_arguments");

  // TODO: Change this to visibility when that is added to SkylarkUserDefinedRule
  EventCollector eventCollector = new EventCollector(EnumSet.allOf(EventKind.class));

  Path buildFile = projectFilesystem.resolve("subdir").resolve("BUCK");

  ImmutableMap<String, ImmutableMap<String, Object>> expected =
      ImmutableMap.of(
          "target1",
          ImmutableMap.<String, Object>builder()
              .put("name", "target1")
              .put("buck.base_path", "subdir")
              .put("buck.type", "//subdir:foo.bzl:some_rule")
              .put("attr1", 3)
              .put("attr2", 2)
              .put("licenses", ImmutableSortedSet.of())
              .put("labels", ImmutableSortedSet.of())
              .put("default_target_platform", Optional.empty())
              .put("compatible_with", ImmutableList.of())
              .build());

  parser = createParser(eventCollector);

  BuildFileManifest rules = parser.getManifest(buildFile);

  assertEquals(expected, rules.getTargets());
}
 
Example 14
Source File: SnippetNode.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Set<Property> getPropertyInfoSet()
{
	return EnumSet.allOf(Property.class);
}
 
Example 15
Source File: EventPropertyElementPropertySource.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Set<Property> getPropertyInfoSet()
{
	return EnumSet.allOf(Property.class);
}
 
Example 16
Source File: ExperimentalTaglet.java    From morphia with Apache License 2.0 4 votes vote down vote up
@Override
public Set<Location> getAllowedLocations() {
    return EnumSet.allOf(Location.class);
}
 
Example 17
Source File: SingleItemSelector.java    From Dividers with Apache License 2.0 4 votes vote down vote up
@Override public EnumSet<Direction> getDirectionsByPosition(Position position) {
  return EnumSet.allOf(Direction.class);
}
 
Example 18
Source File: TestOzoneBlockTokenIdentifier.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Test
public void testSignToken() throws GeneralSecurityException, IOException {
  String keystore = new File(KEYSTORES_DIR, "keystore.jks")
      .getAbsolutePath();
  String truststore = new File(KEYSTORES_DIR, "truststore.jks")
      .getAbsolutePath();
  String trustPassword = "trustPass";
  String keyStorePassword = "keyStorePass";
  String keyPassword = "keyPass";


  KeyStoreTestUtil.createKeyStore(keystore, keyStorePassword, keyPassword,
      "OzoneMaster", keyPair.getPrivate(), cert);

  // Create trust store and put the certificate in the trust store
  Map<String, X509Certificate> certs = Collections.singletonMap("server",
      cert);
  KeyStoreTestUtil.createTrustStore(truststore, trustPassword, certs);

  // Sign the OzoneMaster Token with Ozone Master private key
  PrivateKey privateKey = keyPair.getPrivate();
  OzoneBlockTokenIdentifier tokenId = new OzoneBlockTokenIdentifier(
      "testUser", "84940",
      EnumSet.allOf(HddsProtos.BlockTokenSecretProto.AccessModeProto.class),
      expiryTime, cert.getSerialNumber().toString(), 128L);
  byte[] signedToken = signTokenAsymmetric(tokenId, privateKey);

  // Verify a valid signed OzoneMaster Token with Ozone Master
  // public key(certificate)
  boolean isValidToken = verifyTokenAsymmetric(tokenId, signedToken, cert);
  LOG.info("{} is {}", tokenId, isValidToken ? "valid." : "invalid.");

  // Verify an invalid signed OzoneMaster Token with Ozone Master
  // public key(certificate)
  tokenId = new OzoneBlockTokenIdentifier("", "",
      EnumSet.allOf(HddsProtos.BlockTokenSecretProto.AccessModeProto.class),
      expiryTime, cert.getSerialNumber().toString(), 128L);
  LOG.info("Unsigned token {} is {}", tokenId,
      verifyTokenAsymmetric(tokenId, RandomUtils.nextBytes(128), cert));

}
 
Example 19
Source File: SkylarkUserDefinedRulesParserTest.java    From buck with Apache License 2.0 3 votes vote down vote up
@Test
public void attrsOutputThrowsExceptionOnInvalidTypes() throws IOException, InterruptedException {

  setupWorkspace("attr");

  EventCollector eventCollector = new EventCollector(EnumSet.allOf(EventKind.class));
  Path buildFile = projectFilesystem.resolve("output").resolve("malformed").resolve("BUCK");

  parser = createParser(eventCollector);

  assertParserFails(
      eventCollector, parser, buildFile, "expected value of type 'string or NoneType'");
}
 
Example 20
Source File: ServiceInstanceServiceBean.java    From development with Apache License 2.0 2 votes vote down vote up
/**
 * List all available operations for the given service instance.
 * 
 * @param serviceInstance
 *            - the service instance object
 * @return a set of instance operations
 */
public EnumSet<InstanceOperation> listOperationsForInstance(
        ServiceInstance serviceInstance) {
    return EnumSet.allOf(InstanceOperation.class);
}