List of usage examples for java.util Set containsAll
boolean containsAll(Collection<?> c);
From source file:com.github.fge.jsonschema.servlets.SyntaxValidateServlet.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final Set<String> params = Sets.newHashSet(); /*//from w w w. j a v a 2 s.c o m * First, check our parameters */ /* * Why, in 2013, doesn't servlet-api provide an Iterator<String>? * * Well, at least, Jetty's implementation has a generified Enumeration. * Still, that sucks. */ final Enumeration<String> enumeration = req.getParameterNames(); // FIXME: no duplicates, it seems, but I cannot find the spec which // guarantees that while (enumeration.hasMoreElements()) params.add(enumeration.nextElement()); // We have required parameters if (!params.containsAll(Request.required())) { log.warn("Missing parameters! Someone using me as a web service?"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing parameters"); return; } // We don't want extraneous parameters params.removeAll(Request.valid()); if (!params.isEmpty()) { log.warn("Invalid parameters! Someone using me as a web service?"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters"); return; } final String rawSchema = req.getParameter(Request.SCHEMA); // Set correct content type resp.setContentType(MediaType.JSON_UTF_8.toString()); final JsonNode ret; try { ret = buildResult(rawSchema); } catch (ProcessingException e) { // Should not happen! log.error("Uh, syntax validation failed!", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } final OutputStream out = resp.getOutputStream(); try { out.write(ret.toString().getBytes(Charset.forName("UTF-8"))); out.flush(); } finally { Closeables.closeQuietly(out); } }
From source file:com.xtructure.xevolution.genetics.impl.UTestAbstractPopulation.java
@SuppressWarnings("unchecked") public void iteratorReturnsExpectedIterator() { DummyPopulation pop = new DummyPopulation(1); Genome<String> genome0 = new DummyGenome(RandomUtil.nextInteger(100), "data"); Genome<String> genome1 = new DummyGenome(RandomUtil.nextInteger(100) + 100, "data"); Genome<String> genome2 = new DummyGenome(RandomUtil.nextInteger(100) + 200, "data"); pop.addAll(Arrays.asList(genome0, genome1, genome2)); Set<Genome<String>> gotSet = new HashSet<Genome<String>>(); Iterator<Genome<String>> iter = pop.iterator(); while (iter.hasNext()) { gotSet.add(iter.next());//from ww w. ja v a 2 s. c o m } assertThat("", // gotSet.containsAll(pop), isTrue()); assertThat("", // pop.containsAll(gotSet), isTrue()); }
From source file:org.apache.olingo.client.core.edm.EdmClientImpl.java
@Override protected EdmFunction createBoundFunction(final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, final List<String> parameterNames) { EdmFunction result = null;/*from w ww . jav a 2 s . c o m*/ final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace()); if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) { final List<Function> functions = ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema) .getFunctions(functionName.getName()); boolean found = false; for (final Iterator<Function> itor = functions.iterator(); itor.hasNext() && !found;) { final Function function = itor.next(); if (function.isBound()) { final EdmTypeInfo boundParam = new EdmTypeInfo.Builder().setEdm(this) .setTypeExpression(function.getParameters().get(0).getType()).build(); if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) && (isBindingParameterCollection == null || isBindingParameterCollection.booleanValue() == boundParam.isCollection())) { final Set<String> functionParamNames = new HashSet<String>(); for (CommonParameter param : function.getParameters()) { functionParamNames.add(param.getName()); } found = parameterNames == null ? functionParamNames.isEmpty() : functionParamNames.containsAll(parameterNames); result = EdmFunctionImpl.getInstance(this, functionName, function); } } } } else { for (EntityContainer entityContainer : schema.getEntityContainers()) { @SuppressWarnings("unchecked") final List<FunctionImport> functionImports = (List<FunctionImport>) entityContainer .getFunctionImports(functionName.getName()); boolean found = false; for (final Iterator<FunctionImport> itor = functionImports.iterator(); itor.hasNext() && !found;) { final FunctionImport functionImport = itor.next(); if (FunctionImportUtils.canProxyFunction(functionImport) && functionImport.isBindable()) { final EdmTypeInfo boundParam = new EdmTypeInfo.Builder().setEdm(this) .setTypeExpression(functionImport.getParameters().get(0).getType()).build(); if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) && (isBindingParameterCollection == null || isBindingParameterCollection .booleanValue() == boundParam.isCollection())) { final Set<String> functionParamNames = new HashSet<String>(); for (CommonParameter param : functionImport.getParameters()) { functionParamNames.add(param.getName()); } found = parameterNames == null ? functionParamNames.isEmpty() : functionParamNames.containsAll(parameterNames); result = EdmFunctionProxy.getInstance(this, functionName, functionImport); } } } } } return result; }
From source file:org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestFsDatasetImpl.java
@Test public void testAddVolumes() throws IOException { final int numNewVolumes = 3; final int numExistingVolumes = dataset.getVolumes().size(); final int totalVolumes = numNewVolumes + numExistingVolumes; Set<String> expectedVolumes = new HashSet<String>(); List<NamespaceInfo> nsInfos = Lists.newArrayList(); for (String bpid : BLOCK_POOL_IDS) { nsInfos.add(new NamespaceInfo(0, CLUSTER_ID, bpid, 1)); }//from w w w. j a va 2s. co m for (int i = 0; i < numNewVolumes; i++) { String path = BASE_DIR + "/newData" + i; String pathUri = new Path(path).toUri().toString(); expectedVolumes.add(new File(pathUri).toString()); StorageLocation loc = StorageLocation.parse(pathUri); Storage.StorageDirectory sd = createStorageDirectory(new File(path)); DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); when(storage.prepareVolume(eq(datanode), eq(loc.getFile()), anyListOf(NamespaceInfo.class))) .thenReturn(builder); dataset.addVolume(loc, nsInfos); } assertEquals(totalVolumes, dataset.getVolumes().size()); assertEquals(totalVolumes, dataset.storageMap.size()); Set<String> actualVolumes = new HashSet<String>(); for (int i = 0; i < numNewVolumes; i++) { actualVolumes.add(dataset.getVolumes().get(numExistingVolumes + i).getBasePath()); } assertEquals(actualVolumes.size(), expectedVolumes.size()); assertTrue(actualVolumes.containsAll(expectedVolumes)); }
From source file:org.candlepin.policy.js.entitlement.AbstractEntitlementRules.java
public List<Rule> rulesForAttributes(Set<String> attributes, Map<String, Set<Rule>> rules) { Set<Rule> possibleMatches = new HashSet<Rule>(); for (String attribute : attributes) { if (rules.containsKey(attribute)) { possibleMatches.addAll(rules.get(attribute)); }/*from w ww . j a va2s . co m*/ } List<Rule> matches = new LinkedList<Rule>(); for (Rule rule : possibleMatches) { if (attributes.containsAll(rule.getAttributes())) { matches.add(rule); } } // Always run the global rule, and run it first matches.add(new Rule("global", 0, new HashSet<String>())); Collections.sort(matches, new RuleOrderComparator()); return matches; }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcherTest.java
@Test public void testStreamToLastSeenShardStateIsCorrectlySetWhenNotRestoringFromFailure() throws Exception { List<String> fakeStreams = new LinkedList<>(); fakeStreams.add("fakeStream1"); fakeStreams.add("fakeStream2"); fakeStreams.add("fakeStream3"); fakeStreams.add("fakeStream4"); HashMap<String, String> subscribedStreamsToLastSeenShardIdsUnderTest = KinesisDataFetcher .createInitialSubscribedStreamsToLastDiscoveredShardsState(fakeStreams); Map<String, Integer> streamToShardCount = new HashMap<>(); Random rand = new Random(); for (String fakeStream : fakeStreams) { streamToShardCount.put(fakeStream, rand.nextInt(5) + 1); }/* www . j a va 2 s. c o m*/ final TestableKinesisDataFetcher<String> fetcher = new TestableKinesisDataFetcher<>(fakeStreams, new TestSourceContext<>(), TestUtils.getStandardProperties(), new KinesisDeserializationSchemaWrapper<>(new SimpleStringSchema()), 10, 2, new AtomicReference<>(), new LinkedList<>(), subscribedStreamsToLastSeenShardIdsUnderTest, FakeKinesisBehavioursFactory.nonReshardedStreamsBehaviour(streamToShardCount)); final DummyFlinkKinesisConsumer<String> consumer = new DummyFlinkKinesisConsumer<>( TestUtils.getStandardProperties(), fetcher, 1, 0); CheckedThread consumerThread = new CheckedThread() { @Override public void go() throws Exception { consumer.run(new TestSourceContext<>()); } }; consumerThread.start(); fetcher.waitUntilRun(); consumer.cancel(); consumerThread.sync(); // assert that the streams tracked in the state are identical to the subscribed streams Set<String> streamsInState = subscribedStreamsToLastSeenShardIdsUnderTest.keySet(); assertEquals(fakeStreams.size(), streamsInState.size()); assertTrue(streamsInState.containsAll(fakeStreams)); // assert that the last seen shards in state is correctly set for (Map.Entry<String, String> streamToLastSeenShard : subscribedStreamsToLastSeenShardIdsUnderTest .entrySet()) { assertEquals( KinesisShardIdGenerator .generateFromShardOrder(streamToShardCount.get(streamToLastSeenShard.getKey()) - 1), streamToLastSeenShard.getValue()); } }
From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenServices.java
/** * This method is implemented to support older API calls that assume the * presence of a token store//from ww w .jav a2s.c om */ @Override public OAuth2AccessToken readAccessToken(String accessToken) { Map<String, Object> claims = getClaimsForToken(accessToken); // Expiry is verified by check_token OpenIdToken token = new OpenIdToken(accessToken); token.setTokenType(OAuth2AccessToken.BEARER_TYPE); Integer exp = (Integer) claims.get(EXP); if (null != exp) { token.setExpiration(new Date(exp.longValue() * 1000l)); } @SuppressWarnings("unchecked") ArrayList<String> scopes = (ArrayList<String>) claims.get(SCOPE); if (null != scopes && scopes.size() > 0) { token.setScope(new HashSet<String>(scopes)); } String email = (String) claims.get(EMAIL); // Only check user access tokens if (null != email) { String userId = (String) claims.get(USER_ID); UaaUser user = userDatabase.retrieveUserById(userId); Integer accessTokenIssuedAt = (Integer) claims.get(IAT); long accessTokenIssueDate = accessTokenIssuedAt.longValue() * 1000l; // If the user changed their password, expire the access token if (user.getModified().after(new Date(accessTokenIssueDate))) { logger.debug("User was last modified at " + user.getModified() + " access token was issued at " + new Date(accessTokenIssueDate)); throw new InvalidTokenException("Invalid access token (password changed): " + accessToken); } // Check approvals to make sure they're all valid, approved and not // more recent // than the token itself String clientId = (String) claims.get(CLIENT_ID); ClientDetails client = clientDetailsService.loadClientByClientId(clientId); @SuppressWarnings("unchecked") ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE); Set<String> autoApprovedScopes = getAutoApprovedScopes(claims.get(GRANT_TYPE), tokenScopes, client); if (autoApprovedScopes.containsAll(tokenScopes)) { return token; } checkForApproval(userId, clientId, tokenScopes, autoApprovedScopes, new Date(accessTokenIssueDate)); } return token; }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcherTest.java
@Test public void testStreamToLastSeenShardStateIsCorrectlySetWhenNoNewShardsSinceRestoredCheckpoint() throws Exception { List<String> fakeStreams = new LinkedList<>(); fakeStreams.add("fakeStream1"); fakeStreams.add("fakeStream2"); Map<StreamShardHandle, String> restoredStateUnderTest = new HashMap<>(); // fakeStream1 has 3 shards before restore restoredStateUnderTest.put(/*from w ww. j a va 2 s . c o m*/ new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(2))), UUID.randomUUID().toString()); // fakeStream2 has 2 shards before restore restoredStateUnderTest.put( new StreamShardHandle("fakeStream2", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream2", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))), UUID.randomUUID().toString()); Map<String, Integer> streamToShardCount = new HashMap<>(); streamToShardCount.put("fakeStream1", 3); // fakeStream1 will still have 3 shards after restore streamToShardCount.put("fakeStream2", 2); // fakeStream2 will still have 2 shards after restore HashMap<String, String> subscribedStreamsToLastSeenShardIdsUnderTest = KinesisDataFetcher .createInitialSubscribedStreamsToLastDiscoveredShardsState(fakeStreams); final TestableKinesisDataFetcher<String> fetcher = new TestableKinesisDataFetcher<>(fakeStreams, new TestSourceContext<>(), TestUtils.getStandardProperties(), new KinesisDeserializationSchemaWrapper<>(new SimpleStringSchema()), 10, 2, new AtomicReference<>(), new LinkedList<>(), subscribedStreamsToLastSeenShardIdsUnderTest, FakeKinesisBehavioursFactory.nonReshardedStreamsBehaviour(streamToShardCount)); for (Map.Entry<StreamShardHandle, String> restoredState : restoredStateUnderTest.entrySet()) { fetcher.advanceLastDiscoveredShardOfStream(restoredState.getKey().getStreamName(), restoredState.getKey().getShard().getShardId()); fetcher.registerNewSubscribedShardState(new KinesisStreamShardState( KinesisDataFetcher.convertToStreamShardMetadata(restoredState.getKey()), restoredState.getKey(), new SequenceNumber(restoredState.getValue()))); } CheckedThread runFetcherThread = new CheckedThread() { @Override public void go() throws Exception { fetcher.runFetcher(); } }; runFetcherThread.start(); fetcher.waitUntilInitialDiscovery(); fetcher.shutdownFetcher(); runFetcherThread.sync(); // assert that the streams tracked in the state are identical to the subscribed streams Set<String> streamsInState = subscribedStreamsToLastSeenShardIdsUnderTest.keySet(); assertEquals(fakeStreams.size(), streamsInState.size()); assertTrue(streamsInState.containsAll(fakeStreams)); // assert that the last seen shards in state is correctly set for (Map.Entry<String, String> streamToLastSeenShard : subscribedStreamsToLastSeenShardIdsUnderTest .entrySet()) { assertEquals( KinesisShardIdGenerator .generateFromShardOrder(streamToShardCount.get(streamToLastSeenShard.getKey()) - 1), streamToLastSeenShard.getValue()); } }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcherTest.java
@Test public void testStreamToLastSeenShardStateIsCorrectlySetWhenNewShardsFoundSinceRestoredCheckpoint() throws Exception { List<String> fakeStreams = new LinkedList<>(); fakeStreams.add("fakeStream1"); fakeStreams.add("fakeStream2"); Map<StreamShardHandle, String> restoredStateUnderTest = new HashMap<>(); // fakeStream1 has 3 shards before restore restoredStateUnderTest.put(//w ww. ja v a2 s . co m new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(2))), UUID.randomUUID().toString()); // fakeStream2 has 2 shards before restore restoredStateUnderTest.put( new StreamShardHandle("fakeStream2", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream2", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))), UUID.randomUUID().toString()); Map<String, Integer> streamToShardCount = new HashMap<>(); streamToShardCount.put("fakeStream1", 3 + 1); // fakeStream1 had 3 shards before & 1 new shard after restore streamToShardCount.put("fakeStream2", 2 + 3); // fakeStream2 had 2 shards before & 3 new shard after restore HashMap<String, String> subscribedStreamsToLastSeenShardIdsUnderTest = KinesisDataFetcher .createInitialSubscribedStreamsToLastDiscoveredShardsState(fakeStreams); // using a non-resharded streams kinesis behaviour to represent that Kinesis is not resharded AFTER the restore final TestableKinesisDataFetcher<String> fetcher = new TestableKinesisDataFetcher<>(fakeStreams, new TestSourceContext<>(), TestUtils.getStandardProperties(), new KinesisDeserializationSchemaWrapper<>(new SimpleStringSchema()), 10, 2, new AtomicReference<>(), new LinkedList<>(), subscribedStreamsToLastSeenShardIdsUnderTest, FakeKinesisBehavioursFactory.nonReshardedStreamsBehaviour(streamToShardCount)); for (Map.Entry<StreamShardHandle, String> restoredState : restoredStateUnderTest.entrySet()) { fetcher.advanceLastDiscoveredShardOfStream(restoredState.getKey().getStreamName(), restoredState.getKey().getShard().getShardId()); fetcher.registerNewSubscribedShardState(new KinesisStreamShardState( KinesisDataFetcher.convertToStreamShardMetadata(restoredState.getKey()), restoredState.getKey(), new SequenceNumber(restoredState.getValue()))); } CheckedThread runFetcherThread = new CheckedThread() { @Override public void go() throws Exception { fetcher.runFetcher(); } }; runFetcherThread.start(); fetcher.waitUntilInitialDiscovery(); fetcher.shutdownFetcher(); runFetcherThread.sync(); // assert that the streams tracked in the state are identical to the subscribed streams Set<String> streamsInState = subscribedStreamsToLastSeenShardIdsUnderTest.keySet(); assertEquals(fakeStreams.size(), streamsInState.size()); assertTrue(streamsInState.containsAll(fakeStreams)); // assert that the last seen shards in state is correctly set for (Map.Entry<String, String> streamToLastSeenShard : subscribedStreamsToLastSeenShardIdsUnderTest .entrySet()) { assertEquals( KinesisShardIdGenerator .generateFromShardOrder(streamToShardCount.get(streamToLastSeenShard.getKey()) - 1), streamToLastSeenShard.getValue()); } }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcherTest.java
@Test public void testStreamToLastSeenShardStateIsCorrectlySetWhenNoNewShardsSinceRestoredCheckpointAndSomeStreamsDoNotExist() throws Exception { List<String> fakeStreams = new LinkedList<>(); fakeStreams.add("fakeStream1"); fakeStreams.add("fakeStream2"); fakeStreams.add("fakeStream3"); // fakeStream3 will not have any shards fakeStreams.add("fakeStream4"); // fakeStream4 will not have any shards Map<StreamShardHandle, String> restoredStateUnderTest = new HashMap<>(); // fakeStream1 has 3 shards before restore restoredStateUnderTest.put(/*from w w w. j av a 2s.c om*/ new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream1", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(2))), UUID.randomUUID().toString()); // fakeStream2 has 2 shards before restore restoredStateUnderTest.put( new StreamShardHandle("fakeStream2", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))), UUID.randomUUID().toString()); restoredStateUnderTest.put( new StreamShardHandle("fakeStream2", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))), UUID.randomUUID().toString()); Map<String, Integer> streamToShardCount = new HashMap<>(); streamToShardCount.put("fakeStream1", 3); // fakeStream1 has fixed 3 shards streamToShardCount.put("fakeStream2", 2); // fakeStream2 has fixed 2 shards streamToShardCount.put("fakeStream3", 0); // no shards can be found for fakeStream3 streamToShardCount.put("fakeStream4", 0); // no shards can be found for fakeStream4 HashMap<String, String> subscribedStreamsToLastSeenShardIdsUnderTest = KinesisDataFetcher .createInitialSubscribedStreamsToLastDiscoveredShardsState(fakeStreams); // using a non-resharded streams kinesis behaviour to represent that Kinesis is not resharded AFTER the restore final TestableKinesisDataFetcher<String> fetcher = new TestableKinesisDataFetcher<>(fakeStreams, new TestSourceContext<>(), TestUtils.getStandardProperties(), new KinesisDeserializationSchemaWrapper<>(new SimpleStringSchema()), 10, 2, new AtomicReference<>(), new LinkedList<>(), subscribedStreamsToLastSeenShardIdsUnderTest, FakeKinesisBehavioursFactory.nonReshardedStreamsBehaviour(streamToShardCount)); for (Map.Entry<StreamShardHandle, String> restoredState : restoredStateUnderTest.entrySet()) { fetcher.advanceLastDiscoveredShardOfStream(restoredState.getKey().getStreamName(), restoredState.getKey().getShard().getShardId()); fetcher.registerNewSubscribedShardState(new KinesisStreamShardState( KinesisDataFetcher.convertToStreamShardMetadata(restoredState.getKey()), restoredState.getKey(), new SequenceNumber(restoredState.getValue()))); } CheckedThread runFetcherThread = new CheckedThread() { @Override public void go() throws Exception { fetcher.runFetcher(); } }; runFetcherThread.start(); fetcher.waitUntilInitialDiscovery(); fetcher.shutdownFetcher(); runFetcherThread.sync(); // assert that the streams tracked in the state are identical to the subscribed streams Set<String> streamsInState = subscribedStreamsToLastSeenShardIdsUnderTest.keySet(); assertEquals(fakeStreams.size(), streamsInState.size()); assertTrue(streamsInState.containsAll(fakeStreams)); // assert that the last seen shards in state is correctly set assertEquals(KinesisShardIdGenerator.generateFromShardOrder(2), subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream1")); assertEquals(KinesisShardIdGenerator.generateFromShardOrder(1), subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream2")); assertNull(subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream3")); assertNull(subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream4")); }