List of usage examples for java.util List containsAll
boolean containsAll(Collection<?> c);
From source file:org.broadleafcommerce.admin.server.service.handler.SkuCustomPersistenceHandler.java
/** * Ensures that the given list of {@link ProductOptionValue} IDs is unique for the given {@link Product}. * // ww w .j a v a 2 s .c o m * If sku browsing is enabled, then it is assumed that a single combination of {@link ProductOptionValue} IDs * is not unique and more than one {@link Sku} could have the exact same combination of {@link ProductOptionValue} IDs. * In this case, the following validation is skipped. * * @param product * @param productOptionValueIds * @param currentSku - for update operations, this is the current Sku that is being updated; should be excluded from * attempting validation * @return <b>null</b> if successfully validation, the error entity otherwise */ protected Entity validateUniqueProductOptionValueCombination(Product product, List<Property> productOptionProperties, Sku currentSku) { if (useSku) { return null; } //do not attempt POV validation if no PO properties were passed in if (CollectionUtils.isNotEmpty(productOptionProperties)) { List<Long> productOptionValueIds = new ArrayList<Long>(); for (Property property : productOptionProperties) { productOptionValueIds.add(Long.parseLong(property.getValue())); } boolean validated = true; for (Sku sku : product.getAdditionalSkus()) { if (currentSku == null || !sku.getId().equals(currentSku.getId())) { List<Long> testList = new ArrayList<Long>(); for (ProductOptionValue optionValue : sku.getProductOptionValues()) { testList.add(optionValue.getId()); } if (CollectionUtils.isNotEmpty(testList) && productOptionValueIds.containsAll(testList) && productOptionValueIds.size() == testList.size()) { validated = false; break; } } } if (!validated) { Entity errorEntity = new Entity(); for (Property productOptionProperty : productOptionProperties) { errorEntity.addValidationError(productOptionProperty.getName(), "uniqueSkuError"); } return errorEntity; } } return null; }
From source file:org.telscenter.sail.webapp.presentation.web.controllers.BridgeController.java
/** * Checks whether all the elements in the idsAccessing array are * found in the idsAllowed Collection/*from w w w. ja v a 2 s . c o m*/ * @param idsAccessing the ids the user is trying to access * @param idsAllowed the ids the user is allowed to access * @return whether all the elements are in the Collection */ private boolean elementsInCollection(String[] idsAccessing, Collection<Workgroup> idsAllowed) { //convert the accessing array to a list List<String> idsAccessingList = Arrays.asList(idsAccessing); //convert the allowed Collection to a list List<String> idsAllowedList = new ArrayList<String>(); //obtain an iterator for the Collection Iterator<Workgroup> idsAllowedIter = idsAllowed.iterator(); //loop through all the Workgroups in the Collection while (idsAllowedIter.hasNext()) { //obtain the workgroup id from the Workgroup String idAllowed = idsAllowedIter.next().getId().toString(); //add the workgroup id string to the list of allowed ids idsAllowedList.add(idAllowed); } //see if all the elements in the accessing list are in the allowed list return idsAllowedList.containsAll(idsAccessingList); }
From source file:org.eclipse.wb.internal.core.model.variable.LazyVariableSupportUtils.java
/** * Conversion for {@link FieldVariableSupport}. *///w ww .j a va 2s. c o m private static LazyVariableInformation convertAsField(JavaInfo javaInfo) throws Exception { FieldVariableSupport fieldVariableSupport = (FieldVariableSupport) javaInfo.getVariableSupport(); String fieldName = fieldVariableSupport.getName(); Expression creation = (Expression) javaInfo.getCreationSupport().getNode(); // add method by template MethodDeclaration accessor = addMethod(javaInfo, AstNodeUtils.getEnclosingType(creation), fieldName); // initialize variable and creation Assignment assignment; { IfStatement ifStatement = (IfStatement) accessor.getBody().statements().get(0); Block thenBlock = (Block) ifStatement.getThenStatement(); ExpressionStatement expressionStatement = (ExpressionStatement) thenBlock.statements().get(0); assignment = (Assignment) expressionStatement.getExpression(); } AstEditor editor = javaInfo.getEditor(); StatementTarget target = new StatementTarget(assignment, false); // process related nodes List<Statement> moveStatements = Lists.newArrayList(); List<ASTNode> replaceNodes = Lists.newArrayList(); // prepare node lists... collectNodesToEdit(javaInfo, moveStatements, replaceNodes, target); moveStatements.remove(AstNodeUtils.getEnclosingStatement(creation)); replaceNodes.remove(creation); // move creation directly { // check Assert.isTrue(canMoveNode(target, javaInfo, creation)); // remove creation at old location String replacementSource = editor.getSource(creation); { // replace by "null" and remove statement NullLiteral newNullLiteral = creation.getAST().newNullLiteral(); AstEditor.replaceNode(creation, newNullLiteral); editor.removeEnclosingStatement(newNullLiteral); } // replace "null" expression in template by creation ASTNode originalNode = assignment.getRightHandSide(); int startPosition = originalNode.getStartPosition(); editor.replaceExpression((Expression) originalNode, replacementSource); AstNodeUtils.moveNode(creation, startPosition); assignment.setRightHandSide(creation); } // replace statements with blocks { // prepare unique list of blocks List<Block> blocks = Lists.newArrayList(); for (Statement statement : moveStatements) { Block block = AstNodeUtils.getEnclosingBlock(statement); if (!blocks.contains(block)) { blocks.add(block); } } // replace statements with blocks Collections.sort(blocks, AstNodeUtils.SORT_BY_REVERSE_POSITION); for (Block block : blocks) { List<Statement> blockStatements = DomGenerics.statements(block); if (moveStatements.containsAll(blockStatements) && block.getParent() instanceof Block) { moveStatements.removeAll(blockStatements); moveStatements.add(block); } } } // sort the resulting list of statements { Statement[] statements = moveStatements.toArray(new Statement[moveStatements.size()]); Arrays.sort(statements, AstNodeUtils.SORT_BY_POSITION); moveStatements = Lists.newArrayList(statements); } // move statements for (Statement moveStatement : moveStatements) { editor.moveStatement(moveStatement, target); target = new StatementTarget(moveStatement, false); } // replace field access nodes to access by invocation nodes String invocationSource = accessor.getName().getIdentifier() + "()"; List<ASTNode> relatedNodes = javaInfo.getRelatedNodes(); for (ASTNode replaceNode : replaceNodes) { if (relatedNodes.contains(replaceNode)) { Expression replaceExpression = editor.replaceExpression((Expression) replaceNode, invocationSource); relatedNodes.remove(replaceNode); javaInfo.addRelatedNode(replaceExpression); } } // ready return new LazyVariableInformation(accessor, assignment.getLeftHandSide(), creation); }
From source file:org.agnitas.web.NewImportWizardAction.java
/** * Method checks if profile has key column in its column mappings * * @param aForm a form/*from ww w .java 2s.co m*/ * @param errors errors to add error to if key column is not imported * @return true if key column is contained in one of column mappings */ private boolean isProfileKeyColumnValid(NewImportWizardForm aForm, ActionMessages errors) { ImportProfile profile = aForm.getImportWizardHelper().getImportProfile(); List<ColumnMapping> columns = profile.getColumnMapping(); List<String> keyColumns = profile.getKeyColumns(); List<String> dbColumns = new ArrayList<String>(); for (ColumnMapping column : columns) { dbColumns.add(column.getDatabaseColumn()); } if (keyColumns.isEmpty()) { if (dbColumns.contains(profile.getKeyColumn())) { return true; } } else { if (dbColumns.containsAll(keyColumns)) { return true; } } errors.add("profile", new ActionMessage("error.import.keycolumn_not_imported")); return false; }
From source file:org.apache.hadoop.hbase.client.TestAdmin1.java
/** * Test retain assignment on enableTable. * * @throws IOException// ww w . ja v a 2s .c om */ @Test(timeout = 300000) public void testEnableTableRetainAssignment() throws IOException { final TableName tableName = TableName.valueOf("testEnableTableAssignment"); 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); 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); // Enable table, use retain assignment to assign regions. admin.enableTable(tableName); List<HRegionLocation> regions2 = l.getAllRegionLocations(); // Check the assignment. assertEquals(regions.size(), regions2.size()); assertTrue(regions2.containsAll(regions)); } }
From source file:org.apache.atlas.service.DefaultMetadataServiceTest.java
@Test public void testDeleteEntityByUniqueAttribute() throws Exception { // Create a table entity, with 3 composite column entities Referenceable dbEntity = createDBEntity(); String dbGuid = TestUtils.createInstance(metadataService, dbEntity); Referenceable table1Entity = createTableEntity(dbGuid); Referenceable col1 = createColumnEntity(); Referenceable col2 = createColumnEntity(); Referenceable col3 = createColumnEntity(); table1Entity.set(COLUMNS_ATTR_NAME, ImmutableList.of(col1, col2, col3)); TestUtils.createInstance(metadataService, table1Entity); // to get their guids and the composite column guids. String entityJson = metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table1Entity.get(NAME)); Assert.assertNotNull(entityJson);/* w ww. j a v a 2s. c o m*/ table1Entity = InstanceSerialization.fromJsonReferenceable(entityJson, true); List<IReferenceableInstance> table1Columns = (List<IReferenceableInstance>) table1Entity .get(COLUMNS_ATTR_NAME); // Register an EntityChangeListener to verify the notification mechanism // is working for deleteEntityByUniqueAttribute(). EntitiesChangeListener listener = new EntitiesChangeListener(); metadataService.registerListener(listener); // Delete the table entities. The deletion should cascade // to their composite columns. List<String> deletedGuids = metadataService .deleteEntityByUniqueAttribute(TestUtils.TABLE_TYPE, NAME, (String) table1Entity.get(NAME)) .getDeletedEntities(); // Verify that deleteEntities() response has guids for tables and their composite columns. Assert.assertTrue(deletedGuids.contains(table1Entity.getId()._getId())); for (IReferenceableInstance column : table1Columns) { Assert.assertTrue(deletedGuids.contains(column.getId()._getId())); } // Verify that tables and their composite columns have been deleted from the repository. // Verify that tables and their composite columns have been deleted from the repository. assertEntityDeleted(TABLE_TYPE, NAME, table1Entity.get(NAME)); assertEntityDeleted(COLUMN_TYPE, NAME, col1.get(NAME)); assertEntityDeleted(COLUMN_TYPE, NAME, col2.get(NAME)); assertEntityDeleted(COLUMN_TYPE, NAME, col3.get(NAME)); // Verify that the listener was notified about the deleted entities. List<String> deletedEntitiesFromListener = listener.getDeletedEntities(); Assert.assertNotNull(deletedEntitiesFromListener); assertEquals(deletedEntitiesFromListener.size(), deletedGuids.size()); Assert.assertTrue(deletedEntitiesFromListener.containsAll(deletedGuids)); }
From source file:org.onosproject.dhcprelay.DhcpRelayManagerTest.java
/** * Ignores specific vlans from specific devices if config. * * @throws Exception the exception from this test *///from w ww . ja v a2 s . c om @Test public void testIgnoreVlan() throws Exception { ObjectMapper om = new ObjectMapper(); JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH)); IgnoreDhcpConfig config = new IgnoreDhcpConfig(); json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY); config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null); Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL); flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1)); expectLastCall().times(DHCP_SELECTORS.size()); Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL); flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2)); expectLastCall().times(DHCP_SELECTORS.size()); replay(flowObjectiveService); manager.updateConfig(config); verify(flowObjectiveService); List<Objective> objectivesFromDev1 = capturedFromDev1.getValues(); List<Objective> objectivesFromDev2 = capturedFromDev2.getValues(); assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2)); assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1)); for (int index = 0; index < objectivesFromDev1.size(); index++) { TrafficSelector selector = DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index)) .matchVlanId(IGNORED_VLAN).build(); ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index); assertEquals(selector, fwd.selector()); assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment()); assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority()); assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag()); assertEquals(Objective.Operation.ADD, fwd.op()); fwd.context().ifPresent(ctx -> { ctx.onSuccess(fwd); }); } objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj))); assertEquals(2, v4Handler.ignoredVlans.size()); assertEquals(2, v6Handler.ignoredVlans.size()); }
From source file:org.onosproject.dhcprelay.DhcpRelayManagerTest.java
/** * "IgnoreVlan" policy should be removed when the config removed. *///from w ww. j a va 2 s.c om @Test public void testRemoveIgnoreVlan() { v4Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN); v4Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN); v6Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN); v6Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN); IgnoreDhcpConfig config = new IgnoreDhcpConfig(); Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL); flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1)); expectLastCall().times(DHCP_SELECTORS.size()); Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL); flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2)); expectLastCall().times(DHCP_SELECTORS.size()); replay(flowObjectiveService); manager.removeConfig(config); verify(flowObjectiveService); List<Objective> objectivesFromDev1 = capturedFromDev1.getValues(); List<Objective> objectivesFromDev2 = capturedFromDev2.getValues(); assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2)); assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1)); for (int index = 0; index < objectivesFromDev1.size(); index++) { TrafficSelector selector = DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index)) .matchVlanId(IGNORED_VLAN).build(); ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index); assertEquals(selector, fwd.selector()); assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment()); assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority()); assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag()); assertEquals(Objective.Operation.REMOVE, fwd.op()); fwd.context().ifPresent(ctx -> { ctx.onSuccess(fwd); }); } objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj))); assertEquals(0, v4Handler.ignoredVlans.size()); assertEquals(0, v6Handler.ignoredVlans.size()); }
From source file:org.apache.geode.internal.cache.IncrementalBackupDUnitTest.java
/** * Successful if a member performs a full backup when its backup data is not present in the * baseline (for whatever reason). This also tests what happens when a member is offline during * the baseline backup.//from www.ja v a 2 s. co m * * The test is regarded as successful when all of the missing members oplog files are backed up * during an incremental backup. This means that the member peformed a full backup because its * oplogs were missing in the baseline. */ @Test public void testMissingMemberInBaseline() throws Exception { // Simulate the missing member by forcing a persistent member // to go offline. final PersistentID missingMember = disconnect(Host.getHost(0).getVM(0), Host.getHost(0).getVM(1)); /* * Perform baseline and make sure that the list of offline disk stores contains our missing * member. */ BackupStatus baselineStatus = performBaseline(); assertBackupStatus(baselineStatus); assertNotNull(baselineStatus.getOfflineDiskStores()); assertEquals(2, baselineStatus.getOfflineDiskStores().size()); // Find all of the member's oplogs in the missing member's diskstore directory structure // (*.crf,*.krf,*.drf) Collection<File> missingMemberOplogFiles = FileUtils.listFiles(new File(missingMember.getDirectory()), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY); assertFalse(missingMemberOplogFiles.isEmpty()); /* * Restart our missing member and make sure it is back online and part of the distributed system */ openCache(Host.getHost(0).getVM(0)); /* * After reconnecting make sure the other members agree that the missing member is back online. */ final Set<PersistentID> missingMembers = new HashSet<>(); Wait.waitForCriterion(new WaitCriterion() { @Override public boolean done() { missingMembers.clear(); missingMembers.addAll(getMissingMembers(Host.getHost(0).getVM(1))); return !missingMembers.contains(missingMember); } @Override public String description() { return "[testMissingMemberInBasline] Wait for missing member."; } }, 10000, 500, false); assertEquals(0, missingMembers.size()); /* * Peform incremental and make sure we have no offline disk stores. */ BackupStatus incrementalStatus = performIncremental(); assertBackupStatus(incrementalStatus); assertNotNull(incrementalStatus.getOfflineDiskStores()); assertEquals(0, incrementalStatus.getOfflineDiskStores().size()); // Get the missing member's member id which is different from the PersistentID String memberId = getMemberId(Host.getHost(0).getVM(0)); assertNotNull(memberId); // Get list of backed up oplog files in the incremental backup for the missing member File incrementalMemberDir = getBackupDirForMember(getIncrementalDir(), memberId); Collection<File> backupOplogFiles = FileUtils.listFiles(incrementalMemberDir, new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY); assertFalse(backupOplogFiles.isEmpty()); // Transform missing member oplogs to just their file names. List<String> missingMemberOplogNames = new LinkedList<>(); TransformUtils.transform(missingMemberOplogFiles, missingMemberOplogNames, TransformUtils.fileNameTransformer); // Transform missing member's incremental backup oplogs to just their file names. List<String> backupOplogNames = new LinkedList<>(); TransformUtils.transform(backupOplogFiles, backupOplogNames, TransformUtils.fileNameTransformer); /* * Make sure that the incremental backup for the missing member contains all of the operation * logs for that member. This proves that a full backup was performed for that member. */ assertTrue(backupOplogNames.containsAll(missingMemberOplogNames)); }
From source file:org.apache.hadoop.hdfs.FastCopySetupUtil.java
public boolean verifyBlockLocations(String src, String destination, NameNode srcNameNode, NameNode dstNameNode, boolean hardlink) throws IOException { LocatedBlocksWithMetaInfo srcLocatedBlocks = srcNameNode.openAndFetchMetaInfo(src, 0, Long.MAX_VALUE); List<LocatedBlock> srcblocks = srcLocatedBlocks.getLocatedBlocks(); LocatedBlocksWithMetaInfo dstLocatedBlocks = dstNameNode.openAndFetchMetaInfo(destination, 0, Long.MAX_VALUE);/*from w w w.j a v a 2 s .c om*/ List<LocatedBlock> dstblocks = dstLocatedBlocks.getLocatedBlocks(); assertEquals(srcblocks.size(), dstblocks.size()); Iterator<LocatedBlock> srcIt = srcblocks.iterator(); Iterator<LocatedBlock> dstIt = dstblocks.iterator(); while (srcIt.hasNext()) { LocatedBlock srcBlock = srcIt.next(); LocatedBlock dstBlock = dstIt.next(); List<DatanodeInfo> srcLocations = Arrays.asList(srcBlock.getLocations()); List<DatanodeInfo> dstLocations = Arrays.asList(dstBlock.getLocations()); System.out.println("Locations for src block : " + srcBlock.getBlock() + " file : " + src); for (DatanodeInfo info : srcLocations) { System.out.println("Datanode : " + info.toString() + " rack: " + info.getNetworkLocation()); } System.out.println("Locations for dst block : " + dstBlock.getBlock() + " file : " + destination); for (DatanodeInfo info : dstLocations) { System.out.println("Datanode : " + info.toString() + " rack: " + info.getNetworkLocation()); } assertEquals(srcLocations.size(), dstLocations.size()); if (srcNameNode.getNameNodeAddress().equals(dstNameNode.getNameNodeAddress())) { // Same FS copy, verify blocks are machine local. assertTrue(srcLocations.containsAll(dstLocations)); assertTrue(dstLocations.containsAll(srcLocations)); } else { // Since all datanodes are on the same host in a unit test, the inter // filesystem copy can have blocks end up on any datanode. Iterator<DatanodeInfo> sit = srcLocations.iterator(); while (sit.hasNext()) { DatanodeInfo srcInfo = sit.next(); // Verify location. Iterator<DatanodeInfo> dit = dstLocations.iterator(); while (dit.hasNext()) { DatanodeInfo dstInfo = dit.next(); if (dstInfo.getHost().equals(srcInfo.getHost())) { verifyHardLinks(srcInfo, dstInfo, srcLocatedBlocks.getNamespaceID(), srcBlock.getBlock(), dstLocatedBlocks.getNamespaceID(), dstBlock.getBlock(), hardlink); } } } } } return true; }