List of usage examples for java.util List containsAll
boolean containsAll(Collection<?> c);
From source file:hudson.plugins.jobConfigHistory.FileHistoryDaoTest.java
@Test public void getNodes() { List<File> slaves = new ArrayList<File>(); slaves.add(new File(sutWithUserAndNoDuplicateHistory.getNodeHistoryRootDir(), "slave1")); slaves.add(new File(sutWithUserAndNoDuplicateHistory.getNodeHistoryRootDir(), "slave2")); slaves.add(new File(sutWithUserAndNoDuplicateHistory.getNodeHistoryRootDir(), "slave3")); File[] files = sutWithUserAndNoDuplicateHistory.getNodes("nodes"); assertTrue("All directories of saved slaves should be returned.", slaves.containsAll(Arrays.asList(files))); }
From source file:jp.aegif.nemaki.cmis.aspect.impl.ExceptionServiceImpl.java
private void constraintChoicesRestriction(PropertyDefinition<?> update, PropertyDefinition<?> old) { String msg = update.getId() + ":"; List<?> updateValues = flattenChoiceValues(update.getChoices()); List<?> oldValues = flattenChoiceValues(old.getChoices()); if (!updateValues.containsAll(oldValues)) { msg += "'choices' values must not be removed if 'openChoice' is false"; constraint(msg);//from w w w. j av a2 s . c o m } }
From source file:org.apache.rya.indexing.smarturi.duplication.DuplicateDataDetector.java
/** * Compares two entities to determine if they have nearly identical data. * @param entity1 the first {@link Entity}. (not {@code null}) * @param entity2 the second {@link Entity}. (not {@code null}) * @return {@code true} if the two entities have nearly identical data. * {@code false} otherwise./*from www .j a v a 2 s. com*/ * @throws SmartUriException */ public boolean compareEntities(final Entity entity1, final Entity entity2) throws SmartUriException { requireNonNull(entity1); requireNonNull(entity2); boolean allValuesNearlyEqual = true; final List<RyaURI> types1 = entity1.getExplicitTypeIds(); final List<RyaURI> types2 = entity2.getExplicitTypeIds(); final boolean doBothHaveSameTypes = types1.containsAll(types2); if (!doBothHaveSameTypes) { return false; } for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> entry : entity1.getProperties().entrySet()) { final RyaURI typeIdUri = entry.getKey(); for (final Entry<RyaURI, Property> typeProperty : entry.getValue().entrySet()) { final RyaURI propertyNameUri = typeProperty.getKey(); final Property property1 = typeProperty.getValue(); final Optional<Property> p2 = entity2.lookupTypeProperty(typeIdUri, propertyNameUri); if (p2.isPresent()) { final Property property2 = p2.get(); final RyaType value1 = property1.getValue(); final RyaType value2 = property2.getValue(); final String data1 = value1.getData(); final String data2 = value2.getData(); final URI xmlSchemaUri1 = value1.getDataType(); final ApproxEqualsDetector<?> approxEqualsDetector = uriMap.get(xmlSchemaUri1); if (approxEqualsDetector == null) { throw new SmartUriException("No appropriate detector found for the type: " + xmlSchemaUri1); } final boolean approxEquals = approxEqualsDetector.areApproxEquals(data1, data2); if (!approxEquals) { allValuesNearlyEqual = false; break; } } else { allValuesNearlyEqual = false; break; } } if (!allValuesNearlyEqual) { break; } } return allValuesNearlyEqual; }
From source file:org.apache.hadoop.hbase.client.TestAsyncAdmin.java
@Test(timeout = 300000) public void testEnableTableRetainAssignment() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); byte[][] splitKeys = { new byte[] { 1, 1, 1 }, new byte[] { 2, 2, 2 }, new byte[] { 3, 3, 3 }, new byte[] { 4, 4, 4 }, new byte[] { 5, 5, 5 }, new byte[] { 6, 6, 6 }, new byte[] { 7, 7, 7 }, new byte[] { 8, 8, 8 }, new byte[] { 9, 9, 9 } }; int expectedRegions = splitKeys.length + 1; HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, splitKeys).join(); try (RegionLocator l = TEST_UTIL.getConnection().getRegionLocator(tableName)) { List<HRegionLocation> regions = l.getAllRegionLocations(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), expectedRegions, regions.size()); // Disable table. admin.disableTable(tableName).join(); // Enable table, use retain assignment to assign regions. admin.enableTable(tableName).join(); List<HRegionLocation> regions2 = l.getAllRegionLocations(); // Check the assignment. assertEquals(regions.size(), regions2.size()); assertTrue(regions2.containsAll(regions)); }//from w w w. j a v a 2s.c o m }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.test.internal.collections.TestListUtil.java
/** * Test method for {@link org.ebayopensource.turmeric.eclipse.mavenapi.internal.collections.ListUtil#transformed(org.ebayopensource.turmeric.eclipse.mavenapi.internal.collections.Transformer, java.util.List)}. *//*from w w w. ja va 2 s .co m*/ @Test public void testTransformedTransformerOfTListOfQ() { List<String> collection = new ArrayList<String>(); collection.add("S3"); collection.add("Nvidia"); collection.add("ATI"); final Transformer<String> transformer = new Transformer<String>() { private static final long serialVersionUID = 1631027078150099602L; @Override public String transform(final Object input) { return ObjectUtils.toString(input).toLowerCase(); } }; List<String> list = ListUtil.transformed(transformer, collection); for (int i = 0; i < collection.size(); i++) { String expected = collection.get(i); String actual = list.get(i); Assert.assertNotSame(expected, actual); Assert.assertTrue(expected.equalsIgnoreCase(actual)); } String item = "3dfx"; list.add(item); Assert.assertTrue(list.contains(item)); list.remove(item); Assert.assertFalse(list.contains(item)); list.add(0, item); Assert.assertTrue(list.indexOf(item) == 0); Assert.assertTrue(list.lastIndexOf(item) == 0); list.remove(0); list.set(0, item); Assert.assertTrue(list.indexOf(item) == 0); Collection<String> data = new ArrayList<String>(2); data.add("Voodoo"); data.add("Radeon"); list.addAll(data); Assert.assertTrue(list.containsAll(data)); list.removeAll(data); Assert.assertFalse(list.containsAll(data)); list.addAll(0, data); list.retainAll(data); }
From source file:org.apache.hadoop.mapred.TestBadRecords.java
private void validateOutput(JobConf conf, RunningJob runningJob, List<String> mapperBadRecords, List<String> redBadRecords) throws Exception { LOG.info(runningJob.getCounters().toString()); assertTrue(runningJob.isSuccessful()); //validate counters Counters counters = runningJob.getCounters(); assertEquals(counters.findCounter(Task.Counter.MAP_SKIPPED_RECORDS).getCounter(), mapperBadRecords.size()); int mapRecs = input.size() - mapperBadRecords.size(); assertEquals(counters.findCounter(Task.Counter.MAP_INPUT_RECORDS).getCounter(), mapRecs); assertEquals(counters.findCounter(Task.Counter.MAP_OUTPUT_RECORDS).getCounter(), mapRecs); int redRecs = mapRecs - redBadRecords.size(); assertEquals(counters.findCounter(Task.Counter.REDUCE_SKIPPED_RECORDS).getCounter(), redBadRecords.size()); assertEquals(counters.findCounter(Task.Counter.REDUCE_SKIPPED_GROUPS).getCounter(), redBadRecords.size()); assertEquals(counters.findCounter(Task.Counter.REDUCE_INPUT_GROUPS).getCounter(), redRecs); assertEquals(counters.findCounter(Task.Counter.REDUCE_INPUT_RECORDS).getCounter(), redRecs); assertEquals(counters.findCounter(Task.Counter.REDUCE_OUTPUT_RECORDS).getCounter(), redRecs); //validate skipped records Path skipDir = SkipBadRecords.getSkipOutputPath(conf); Path[] skips = FileUtil.stat2Paths(getFileSystem().listStatus(skipDir)); List<String> mapSkipped = new ArrayList<String>(); List<String> redSkipped = new ArrayList<String>(); for (Path skipPath : skips) { LOG.info("skipPath: " + skipPath); SequenceFile.Reader reader = new SequenceFile.Reader(getFileSystem(), skipPath, conf); Object key = ReflectionUtils.newInstance(reader.getKeyClass(), conf); Object value = ReflectionUtils.newInstance(reader.getValueClass(), conf); key = reader.next(key);// w w w . j ava 2s .c o m while (key != null) { value = reader.getCurrentValue(value); LOG.debug("key:" + key + " value:" + value.toString()); if (skipPath.getName().contains("_r_")) { redSkipped.add(value.toString()); } else { mapSkipped.add(value.toString()); } key = reader.next(key); } reader.close(); } assertTrue(mapSkipped.containsAll(mapperBadRecords)); assertTrue(redSkipped.containsAll(redBadRecords)); Path[] outputFiles = FileUtil.stat2Paths( getFileSystem().listStatus(getOutputDir(), new Utils.OutputFileUtils.OutputFilesFilter())); List<String> mapperOutput = getProcessed(input, mapperBadRecords); LOG.debug("mapperOutput " + mapperOutput.size()); List<String> reducerOutput = getProcessed(mapperOutput, redBadRecords); LOG.debug("reducerOutput " + reducerOutput.size()); if (outputFiles.length > 0) { InputStream is = getFileSystem().open(outputFiles[0]); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = reader.readLine(); int counter = 0; while (line != null) { counter++; StringTokenizer tokeniz = new StringTokenizer(line, "\t"); String key = tokeniz.nextToken(); String value = tokeniz.nextToken(); LOG.debug("Output: key:" + key + " value:" + value); assertTrue(value.contains("hello")); assertTrue(reducerOutput.contains(value)); line = reader.readLine(); } reader.close(); assertEquals(reducerOutput.size(), counter); } }
From source file:org.finra.herd.service.helper.StorageFileHelper.java
/** * Validates S3 files per storage unit information. * * @param storageUnit the storage unit that contains S3 files to be validated * @param actualS3Files the list of the actual S3 files * @param s3KeyPrefix the S3 key prefix that was prepended to the S3 file paths, when they were uploaded to S3 *///from www . j a v a 2 s . c o m public void validateStorageUnitS3Files(StorageUnit storageUnit, List<String> actualS3Files, String s3KeyPrefix) { // Validate that all files match the expected S3 key prefix and build a list of registered S3 files. List<String> registeredS3Files = new ArrayList<>(); if (!CollectionUtils.isEmpty(storageUnit.getStorageFiles())) { for (StorageFile storageFile : storageUnit.getStorageFiles()) { Assert.isTrue(storageFile.getFilePath().startsWith(s3KeyPrefix), String.format( "Storage file S3 key prefix \"%s\" does not match the expected S3 key prefix \"%s\".", storageFile.getFilePath(), s3KeyPrefix)); registeredS3Files.add(storageFile.getFilePath()); } } // Validate that all files exist in S3 managed bucket. if (!actualS3Files.containsAll(registeredS3Files)) { registeredS3Files.removeAll(actualS3Files); throw new IllegalStateException( String.format("Registered file \"%s\" does not exist in \"%s\" storage.", registeredS3Files.get(0), storageUnit.getStorage().getName())); } // Validate that no other files in S3 managed bucket have the same S3 key prefix. if (!registeredS3Files.containsAll(actualS3Files)) { actualS3Files.removeAll(registeredS3Files); throw new IllegalStateException(String.format( "Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.", actualS3Files.get(0), storageUnit.getStorage().getName())); } }
From source file:de.damdi.fitness.activity.create_workout.ExerciseTypeListFragment.java
/** * Filters the list of exercises for muscles and equipment. *//*from www .j av a 2 s .c o m*/ private void filterExercisesForMusclesAndEquipment() { IDataProvider dataProvider = new DataProvider(getActivity()); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); List<Muscle> acceptedMuscles = new ArrayList<Muscle>(); for (Muscle m : dataProvider.getMuscles()) { if (sharedPrefs.getBoolean(m.toString(), true)) { acceptedMuscles.add(m); } } List<SportsEquipment> acceptedEquipment = new ArrayList<SportsEquipment>(); for (SportsEquipment e : dataProvider.getEquipment()) { if (sharedPrefs.getBoolean(e.toString(), true)) { acceptedEquipment.add(e); } } mExericseList = dataProvider.getExercises(); for (ExerciseType ex : dataProvider.getExercises()) { boolean accepted = false; for (Muscle m : acceptedMuscles) { if (ex.getActivatedMuscles().contains(m)) accepted = true; } if (ex.getActivatedMuscles().isEmpty()) accepted = true; if (!accepted) { Log.d(TAG, "Exercise: " + ex.toString() + " will not be shown. Muscles do not fit."); mExericseList.remove(ex); continue; } if (!acceptedEquipment.containsAll(ex.getRequiredEquipment())) { Log.d(TAG, "Exercise: " + ex.toString() + " will not be shown. Equipment does not fit"); mExericseList.remove(ex); continue; } } setListAdapter(new ExerciseTypeListAdapter(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mExericseList)); }
From source file:org.apache.tinkerpop.gremlin.server.GremlinDriverIntegrateTest.java
@Test public void shouldAvoidDeadlockOnCallToResultSetDotAll() throws Exception { // This test arose from this issue: https://github.org/apache/tinkerpop/tinkerpop3/issues/515 //// ww w.ja v a 2 s . c o m // ResultSet.all returns a CompletableFuture that blocks on the worker pool until isExhausted returns false. // isExhausted in turn needs a thread on the worker pool to even return. So its totally possible to consume all // threads on the worker pool waiting for .all to finish such that you can't even get one to wait for // isExhausted to run. // // Note that all() doesn't work as described above anymore. It waits for callback on readComplete rather // than blocking on isExhausted. final int workerPoolSizeForDriver = 2; // the number of requests 4 times the size of the worker pool as this originally did produce the problem // described above in the javadoc of the test (though an equivalent number also produced it), but this has // been tested to much higher multiples and passes. note that the maxWaitForConnection setting is high so // that the client doesn't timeout waiting for an available connection. obviously this can also be fixed // by increasing the maxConnectionPoolSize. final int requests = workerPoolSizeForDriver * 4; final Cluster cluster = Cluster.build().workerPoolSize(workerPoolSizeForDriver).maxWaitForConnection(300000) .create(); final Client client = cluster.connect(); final CountDownLatch latch = new CountDownLatch(requests); final AtomicReference[] refs = new AtomicReference[requests]; IntStream.range(0, requests).forEach(ix -> { refs[ix] = new AtomicReference(); client.submitAsync("Thread.sleep(5000);[1,2,3,4,5,6,7,8,9]") .thenAccept(rs -> rs.all().thenAccept(refs[ix]::set).thenRun(latch::countDown)); }); // countdown should have reached zero as results should have eventually been all returned and processed assertTrue(latch.await(20, TimeUnit.SECONDS)); final List<Integer> expected = IntStream.range(1, 10).boxed().collect(Collectors.toList()); IntStream.range(0, requests).forEach(r -> assertTrue(expected.containsAll(((List<Result>) refs[r].get()) .stream().map(resultItem -> new Integer(resultItem.getInt())).collect(Collectors.toList())))); }
From source file:org.ebayopensource.turmeric.eclipse.utils.test.collections.TestListUtil.java
/** * Test method for {@link org.ebayopensource.turmeric.maveneclipseapi.internal.collections.ListUtil#transformed(org.ebayopensource.turmeric.maveneclipseapi.internal.collections.Transformer, java.util.List)}. *///ww w . ja v a 2s. co m @Test public void testTransformedTransformerOfTListOfQ() { List<String> collection = new ArrayList<String>(); collection.add("Arc' Terryx"); collection.add("Mountain Hardwear"); collection.add("Black Diamond"); final Transformer<String> transformer = new Transformer<String>() { private static final long serialVersionUID = 1631027078150099602L; @Override public String transform(final Object input) { return ObjectUtils.toString(input).toLowerCase(); } }; List<String> list = ListUtil.transformed(transformer, collection); for (int i = 0; i < collection.size(); i++) { String expected = collection.get(i); String actual = list.get(i); Assert.assertNotSame(expected, actual); Assert.assertTrue(expected.equalsIgnoreCase(actual)); } String item = "3dfx"; list.add(item); Assert.assertTrue(list.contains(item)); list.remove(item); Assert.assertFalse(list.contains(item)); list.add(0, item); Assert.assertTrue(list.indexOf(item) == 0); Assert.assertTrue(list.lastIndexOf(item) == 0); list.remove(0); list.set(0, item); Assert.assertTrue(list.indexOf(item) == 0); Collection<String> data = new ArrayList<String>(2); data.add("Voodoo"); data.add("Radeon"); list.addAll(data); Assert.assertTrue(list.containsAll(data)); list.removeAll(data); Assert.assertFalse(list.containsAll(data)); list.addAll(0, data); list.retainAll(data); }