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

The following examples show how to use java.util.EnumSet#allOf() . 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: neoscada   File: ProxyDataItem.java    License: 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 2
@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 3
/**
 * 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 4
Source Project: crate   File: ConnectionProfile.java    License: 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 5
@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 6
/**
 * 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 7
Source Project: hadoop   File: StartupProgress.java    License: 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 8
Source Project: vespa   File: StateFilter.java    License: 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 9
Source Project: atlas   File: OptimizerOptions.java    License: 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 10
@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 11
Source Project: hadoop   File: FileBench.java    License: 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 12
Source Project: codebuff   File: Enums.java    License: 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 13
@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 14
@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 15
Source Project: Dividers   File: SingleItemSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Override public EnumSet<Direction> getDirectionsByPosition(Position position) {
  return EnumSet.allOf(Direction.class);
}
 
Example 16
Source Project: morphia   File: ExperimentalTaglet.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Set<Location> getAllowedLocations() {
    return EnumSet.allOf(Location.class);
}
 
Example 17
@Override
protected Set<Property> getPropertyInfoSet()
{
	return EnumSet.allOf(Property.class);
}
 
Example 18
@Override
protected Set<Property> getPropertyInfoSet()
{
	return EnumSet.allOf(Property.class);
}
 
Example 19
@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
/**
 * 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);
}