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

The following examples show how to use java.util.EnumSet#complementOf() . 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: LFGarbageCollectedTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main routine for lambda forms garbage collection test.
 *
 * @param args Accepts no arguments.
 */
public static void main(String[] args) {
    // The "identity", "constant", "arrayElementGetter" and "arrayElementSetter"
    // methods should be removed from this test,
    // because their lambda forms are stored in a static field and are not GC'ed.
    // There can be only a finite number of such LFs for each method,
    // so no memory leak happens.
    EnumSet<TestMethods> testMethods = EnumSet.complementOf(EnumSet.of(
            TestMethods.IDENTITY,
            TestMethods.CONSTANT,
            TestMethods.ARRAY_ELEMENT_GETTER,
            TestMethods.ARRAY_ELEMENT_SETTER,
            TestMethods.EXACT_INVOKER,
            TestMethods.INVOKER));
    LambdaFormTestCase.runTests(LFGarbageCollectedTest::new, testMethods);
}
 
Example 2
Source File: LFGarbageCollectedTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main routine for lambda forms garbage collection test.
 *
 * @param args Accepts no arguments.
 */
public static void main(String[] args) {
    // The "identity", "constant", "arrayElementGetter" and "arrayElementSetter"
    // methods should be removed from this test,
    // because their lambda forms are stored in a static field and are not GC'ed.
    // There can be only a finite number of such LFs for each method,
    // so no memory leak happens.
    EnumSet<TestMethods> testMethods = EnumSet.complementOf(EnumSet.of(
            TestMethods.IDENTITY,
            TestMethods.CONSTANT,
            TestMethods.ARRAY_ELEMENT_GETTER,
            TestMethods.ARRAY_ELEMENT_SETTER,
            TestMethods.EXACT_INVOKER,
            TestMethods.INVOKER));
    LambdaFormTestCase.runTests(LFGarbageCollectedTest::new, testMethods);
}
 
Example 3
Source File: LFGarbageCollectedTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main routine for lambda forms garbage collection test.
 *
 * @param args Accepts no arguments.
 */
public static void main(String[] args) {
    // The "identity", "constant", "arrayElementGetter" and "arrayElementSetter"
    // methods should be removed from this test,
    // because their lambda forms are stored in a static field and are not GC'ed.
    // There can be only a finite number of such LFs for each method,
    // so no memory leak happens.
    EnumSet<TestMethods> testMethods = EnumSet.complementOf(EnumSet.of(
            TestMethods.IDENTITY,
            TestMethods.CONSTANT,
            TestMethods.ARRAY_ELEMENT_GETTER,
            TestMethods.ARRAY_ELEMENT_SETTER,
            TestMethods.EXACT_INVOKER,
            TestMethods.INVOKER));
    LambdaFormTestCase.runTests(LFGarbageCollectedTest::new, testMethods);
}
 
Example 4
Source File: JsonInclusionTest.java    From jackson-datatype-protobuf with Apache License 2.0 6 votes vote down vote up
@Test
public void itOnlyWritesArrayExtensionFieldsWhenSerializationIncludeIsNotAlways() {
  AllFields message = AllFields.getDefaultInstance();

  for (Include inclusion : EnumSet.complementOf(EXCLUDED_VALUES)) {
    JsonNode node = mapper(inclusion, EXTENSION_REGISTRY).valueToTree(message);

    for (String field : allExtensionFields) {
      if (arrayExtensionFields.contains(field)) {
        assertThat(node.has(field)).isTrue();
        assertThat(node.get(field).isArray());
      } else {
        assertThat(node.has(field)).isFalse();
      }
    }
  }
}
 
Example 5
Source File: RBFNetTest.java    From JSAT with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test of train method, of class RBFNet.
 */
@Test
public void testTrain_RegressionDataSet()
{
    System.out.println("train");
    RegressionDataSet trainSet =  FixedProblems.getSimpleRegression1(2000, RandomUtil.getRandom());
    RegressionDataSet testSet =  FixedProblems.getSimpleRegression1(200, RandomUtil.getRandom());
    
    for(RBFNet.Phase1Learner p1l : RBFNet.Phase1Learner.values())
        for(RBFNet.Phase2Learner p2l :  EnumSet.complementOf(EnumSet.of(RBFNet.Phase2Learner.CLOSEST_OPPOSITE_CENTROID)))
        {
            RBFNet net = new RBFNet(25);
            net.setAlpha(1);//CLOSEST_OPPOSITE_CENTROID needs a smaller value, shoudld be fine for others on this data set 
            net.setPhase1Learner(p1l);
            net.setPhase2Learner(p2l);
            net = net.clone();
            net.train(trainSet);
            net = net.clone();
            
            double errors = 0;
            for (int i = 0; i < testSet.size(); i++)
                errors += Math.pow(testSet.getTargetValue(i) - net.regress(testSet.getDataPoint(i)), 2);
            assertTrue(errors/testSet.size() < 1);
        }
    
}
 
Example 6
Source File: LFGarbageCollectedTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main routine for lambda forms garbage collection test.
 *
 * @param args Accepts no arguments.
 */
public static void main(String[] args) {
    // The "identity", "constant", "arrayElementGetter" and "arrayElementSetter"
    // methods should be removed from this test,
    // because their lambda forms are stored in a static field and are not GC'ed.
    // There can be only a finite number of such LFs for each method,
    // so no memory leak happens.
    EnumSet<TestMethods> testMethods = EnumSet.complementOf(EnumSet.of(
            TestMethods.IDENTITY,
            TestMethods.CONSTANT,
            TestMethods.ARRAY_ELEMENT_GETTER,
            TestMethods.ARRAY_ELEMENT_SETTER,
            TestMethods.EXACT_INVOKER,
            TestMethods.INVOKER));
    LambdaFormTestCase.runTests(LFGarbageCollectedTest::new, testMethods);
}
 
Example 7
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 8
Source File: TestAppletLoggerContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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 9
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void createLoaders() {
	// We load the entity loaders for the most common lock modes.

	noneLockLoader = createEntityLoader( LockMode.NONE );
	readLockLoader = createEntityLoader( LockMode.READ );


	// The loaders for the other lock modes are lazily loaded and will later be stored in this map,
	//		unless this setting is disabled
	if ( ! factory.getSessionFactoryOptions().isDelayBatchFetchLoaderCreationsEnabled() ) {
		for ( LockMode lockMode : EnumSet.complementOf( EnumSet.of( LockMode.NONE, LockMode.READ, LockMode.WRITE ) ) ) {
			loaders.put( lockMode, createEntityLoader( lockMode ) );
		}
	}


	// And finally, create the internal merge and refresh load plans

	loaders.put(
			"merge",
			new CascadeEntityLoader( this, CascadingActions.MERGE, getFactory() )
	);
	loaders.put(
			"refresh",
			new CascadeEntityLoader( this, CascadingActions.REFRESH, getFactory() )
	);
}
 
Example 10
Source File: SqlParser.java    From rainbow with Apache License 2.0 5 votes vote down vote up
@Override
public void exitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context)
{
    String identifier = context.IDENTIFIER().getText();
    for (IdentifierSymbol identifierSymbol : EnumSet.complementOf(allowedIdentifierSymbols)) {
        char symbol = identifierSymbol.getSymbol();
        if (identifier.indexOf(symbol) >= 0) {
            throw new ParsingException("identifiers must not contain '" + identifierSymbol.getSymbol() + "'", null, context.IDENTIFIER().getSymbol().getLine(), context.IDENTIFIER().getSymbol().getCharPositionInLine());
        }
    }
}
 
Example 11
Source File: GetBlobOperationTest.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the case where all servers return the same server level error code
 * @throws Exception
 */
@Test
public void testFailureOnServerErrors() throws Exception {
  doPut();
  // set the status to various server level errors (remove all partition level errors or non errors)
  EnumSet<ServerErrorCode> serverErrors = EnumSet.complementOf(
      EnumSet.of(ServerErrorCode.Blob_Deleted, ServerErrorCode.Blob_Expired, ServerErrorCode.No_Error,
          ServerErrorCode.Blob_Authorization_Failure, ServerErrorCode.Blob_Not_Found));
  for (ServerErrorCode serverErrorCode : serverErrors) {
    mockServerLayout.getMockServers().forEach(server -> server.setServerErrorForAllRequests(serverErrorCode));
    GetBlobOperation op = createOperationAndComplete(null);
    RouterErrorCode expectedRouterError;
    switch (serverErrorCode) {
      case Replica_Unavailable:
        expectedRouterError = RouterErrorCode.AmbryUnavailable;
        break;
      case Disk_Unavailable:
        // if all the disks are unavailable (which should be extremely rare), after replacing these disks, the blob is
        // definitely not present.
        expectedRouterError = RouterErrorCode.BlobDoesNotExist;
        break;
      default:
        expectedRouterError = RouterErrorCode.UnexpectedInternalError;
    }
    assertFailureAndCheckErrorCode(op, expectedRouterError);
  }
}
 
Example 12
Source File: EnumSets.java    From tutorials with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    EnumSet<Color> allColors = EnumSet.allOf(Color.class);
    System.out.println(allColors);

    EnumSet<Color> noColors = EnumSet.noneOf(Color.class);
    System.out.println(noColors);

    EnumSet<Color> blackAndWhite = EnumSet.of(Color.BLACK, Color.WHITE);
    System.out.println(blackAndWhite);

    EnumSet<Color> noBlackOrWhite = EnumSet.complementOf(blackAndWhite);
    System.out.println(noBlackOrWhite);

    EnumSet<Color> range = EnumSet.range(Color.YELLOW, Color.BLUE);
    System.out.println(range);

    EnumSet<Color> blackAndWhiteCopy = EnumSet.copyOf(EnumSet.of(Color.BLACK, Color.WHITE));
    System.out.println(blackAndWhiteCopy);

    List<Color> colorsList = new ArrayList<>();
    colorsList.add(Color.RED);
    EnumSet<Color> listCopy = EnumSet.copyOf(colorsList);
    System.out.println(listCopy);

    EnumSet<Color> set = EnumSet.noneOf(Color.class);
    set.add(Color.RED);
    set.add(Color.YELLOW);
    set.contains(Color.RED);
    set.forEach(System.out::println);
    set.remove(Color.RED);
}
 
Example 13
Source File: TestAppletLoggerContext.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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 14
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processCursor(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {

	if (d.size() == 1 && Decoder.genericOneIdent(Cursor.class, d, properties)) {
		return true;
	} else {

		final Set<Cursor> allowedCursors = EnumSet.complementOf(EnumSet
				.of(Cursor.INHERIT));

		TermList list = tf.createList();
		Cursor cur = null;
		for (Term<?> term : d.asList()) {
			if (term instanceof TermURI) {
				list.add(term);
			} else if (term instanceof TermIdent
					&& (cur = Decoder.genericPropertyRaw(Cursor.class,
							allowedCursors, (TermIdent) term)) != null) {
				// this have to be the last cursor in sequence
				// and only one Decoder.generic cursor is allowed
				if (d.indexOf(term) != d.size() - 1)
					return false;

				// passed as last cursor, insert into properties and values
				properties.put("cursor", cur);
				if (!list.isEmpty())
					values.put("cursor", list);
				return true;
			} else
				return false;
		}
		return false;
	}
}
 
Example 15
Source File: VersionParser.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isMatchedBy(Character chr) {
    EnumSet<CharType> itself = EnumSet.of(ILLEGAL);
    for (CharType type : EnumSet.complementOf(itself)) {
        if (type.isMatchedBy(chr)) {
            return false;
        }
    }
    return true;
}
 
Example 16
Source File: TestMutuallyExclusivePlatformPredicates.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    EnumSet<MethodGroup> notIgnoredMethodGroups
            = EnumSet.complementOf(EnumSet.of(MethodGroup.IGNORED));

    notIgnoredMethodGroups.forEach(
            TestMutuallyExclusivePlatformPredicates::verifyPredicates);

    TestMutuallyExclusivePlatformPredicates.verifyCoverage();
}
 
Example 17
Source File: RowGroupSelector.java    From Dividers with Apache License 2.0 5 votes vote down vote up
@Override public EnumSet<Direction> getDirectionsByPosition(Position position) {
  EnumSet<Direction> directions = EnumSet.complementOf(
      EnumSet.of(Direction.WEST, Direction.EAST));

  if (position.isFirstColumn()) {
    directions.add(Direction.WEST);
  }
  if (position.isLastColumn()) {
    directions.add(Direction.EAST);
  }

  return directions;
}
 
Example 18
Source File: TaskVarsTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllVetoGroupsCovered() {
  replayAndBuild();
  for (VetoGroup group : EnumSet.complementOf(EnumSet.of(VetoGroup.EMPTY))) {
    assertNotNull("Unknown VetoGroup value: " + group, VETO_GROUPS_TO_COUNTERS.get(group));
  }
}
 
Example 19
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates an {@code EnumSet} consisting of all enum values that are not in
 * the specified collection. This is equivalent to
 * {@link EnumSet#complementOf}, but can act on any input collection, as long
 * as the elements are of enum type.
 *
 * @param collection the collection whose complement should be stored in the
 *     {@code EnumSet}
 * @param type the type of the elements in the set
 * @return a new, modifiable {@code EnumSet} initially containing all the
 *     values of the enum not present in the given collection
 */


public static <E extends Enum<E>> EnumSet<E> complementOf(Collection<E> collection, Class<E> type) {
  checkNotNull(collection);
  return (collection instanceof EnumSet)
    ? EnumSet.complementOf((EnumSet<E>) collection)
    : makeComplementByHand(collection, type);
}
 
Example 20
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates an {@code EnumSet} consisting of all enum values that are not in
 * the specified collection. If the collection is an {@link EnumSet}, this
 * method has the same behavior as {@link EnumSet#complementOf}. Otherwise,
 * the specified collection must contain at least one element, in order to
 * determine the element type. If the collection could be empty, use
 * {@link #complementOf(Collection, Class)} instead of this method.
 *
 * @param collection the collection whose complement should be stored in the
 *     enum set
 * @return a new, modifiable {@code EnumSet} containing all values of the enum
 *     that aren't present in the given collection
 * @throws IllegalArgumentException if {@code collection} is not an
 *     {@code EnumSet} instance and contains no elements
 */
public static <E extends Enum<E>> EnumSet<E> complementOf(Collection<E> collection) {
  if (collection instanceof EnumSet) {
    return EnumSet.complementOf((EnumSet<E>) collection);
  }
  checkArgument(
      !collection.isEmpty(), "collection is empty; use the other version of this method");
  Class<E> type = collection.iterator().next().getDeclaringClass();
  return makeComplementByHand(collection, type);
}