Java Code Examples for java.util.List#containsAll()

The following examples show how to use java.util.List#containsAll() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Test
public void testUsesUnexportedButProvidedService(Path base) throws Exception {
    Path src = base.resolve("src");
    tb.writeJavaFiles(src.resolve("m1x"),
            "module m1x { provides p.C with p.C; }",
            "package p; public class C { }");
    tb.writeJavaFiles(src.resolve("m2x"),
            "module m2x { requires m1x; uses p.C; }");

    List<String> output = new JavacTask(tb)
            .options("-XDrawDiagnostics", "--module-source-path", src.toString())
            .outdir(Files.createDirectories(base.resolve("modules")))
            .files(findJavaFiles(src))
            .run(Task.Expect.FAIL)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    List<String> expected = Arrays.asList("module-info.java:1:33: compiler.err.package.not.visible: p, (compiler.misc.not.def.access.not.exported: p, m1x)",
            "1 error");
    if (!output.containsAll(expected)) {
        throw new Exception("Expected output not found");
    }
}
 
Example 2
private boolean checkConsistencyOfForwardChanges(List<ViolationContext> forwardContexts, List<ViolationContext> backwardContexts, EquivalenceClassForEGD equivalenceClass) {
    //After a context has been forward chased, the conflict of those values has been removed.
    for (ViolationContext forwardContext : forwardContexts) {
        List<ViolationContext> contextsWithSameConclusionGroups = findContextsWithSameConclusionGroups(forwardContext, forwardContexts);
        if (!forwardContexts.containsAll(contextsWithSameConclusionGroups)) {
            return false;
        }
    }
    //Check that after enriching cell groups, forward changes do not interfear with backward changes
    Set<Cell> forwardCells = extractForwardCells(forwardContexts);
    for (ViolationContext backwardContext : backwardContexts) {
        Set<Cell> forwardCellsForBackwardContext = extractForwardCells(Arrays.asList(new ViolationContext[]{backwardContext}));
        if (forwardCells.containsAll(forwardCellsForBackwardContext)) {
            return false;
        }
    }
    return true;
}
 
Example 3
Source Project: delion   File: AccountSigninView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Refresh the list of available system account.
 * @return Whether any new accounts were added (the first newly added account will now be
 *         selected).
 */
private boolean updateAccounts() {
    if (mSignedIn || mProfileData == null) return false;

    List<String> oldAccountNames = mAccountNames;
    mAccountNames = mAccountManagerHelper.getGoogleAccountNames();
    int accountToSelect = 0;
    if (isInForcedAccountMode()) {
        accountToSelect = mAccountNames.indexOf(mForcedAccountName);
        if (accountToSelect < 0) {
            mListener.onFailedToSetForcedAccount(mForcedAccountName);
            return false;
        }
    } else {
        accountToSelect = getIndexOfNewElement(
                oldAccountNames, mAccountNames, mSigninChooseView.getSelectedAccountPosition());
    }

    mSigninChooseView.updateAccounts(mAccountNames, accountToSelect, mProfileData);
    if (mAccountNames.isEmpty()) {
        setUpSigninButton(false);
        return false;
    }
    setUpSigninButton(true);

    mProfileData.update();

    return oldAccountNames != null
            && !(oldAccountNames.size() == mAccountNames.size()
                && oldAccountNames.containsAll(mAccountNames));
}
 
Example 4
@Override
public Boolean act() throws Exception {
    final List<String> tokensFromFile = tokensFromFile();
    final List<String> tokensOfNode = new CassandraTokens(cassandraJMXService).act();

    return tokensFromFile.size() == tokensOfNode.size() && tokensFromFile.containsAll(tokensOfNode);
}
 
Example 5
private boolean verifyAllocateAll(List<String> cidAll, List<MessageQueue> mqAll,
    List<MessageQueue> allocatedResAll) {
    if (cidAll.isEmpty()) {
        return allocatedResAll.isEmpty();
    }
    return mqAll.containsAll(allocatedResAll) && allocatedResAll.containsAll(mqAll);
}
 
Example 6
Source Project: streamline   File: TopologyTestRunner.java    License: Apache License 2.0 5 votes vote down vote up
private boolean equalsOutputRecords(Map<String, List<Map<String, Object>>> expectedOutputRecordsMap,
                                    Map<String, List<Map<String, Object>>> actualOutputRecordsMap) {
    if (expectedOutputRecordsMap.size() != actualOutputRecordsMap.size()) {
        return false;
    }

    for (Map.Entry<String, List<Map<String, Object>>> expectedEntry : expectedOutputRecordsMap.entrySet()) {
        String sinkName = expectedEntry.getKey();

        if (!actualOutputRecordsMap.containsKey(sinkName)) {
            return false;
        }

        List<Map<String, Object>> expectedRecords = expectedEntry.getValue();
        List<Map<String, Object>> actualRecords = actualOutputRecordsMap.get(sinkName);

        // both should be not null
        if (expectedRecords == null || actualRecords == null) {
            return false;
        } else if (expectedRecords.size() != actualRecords.size()) {
            return false;
        } else if (!expectedRecords.containsAll(actualRecords)) {
            return false;
        }
    }

    return true;
}
 
Example 7
private static void checkAttributes(LoggingMXBean mxbean1,
                                    PlatformLoggingMXBean mxbean2) {
    // verify logger names
    List<String> loggers1 = mxbean1.getLoggerNames();
    System.out.println("Loggers: " + loggers1);

    // Retrieve the named loggers to prevent them from being
    // spontaneously gc'ed.
    Map<String, Logger> loggersMap = new HashMap<>();
    for (String n : loggers1) {
        loggersMap.put(n, Logger.getLogger(n));
    }

    List<String> loggers2 = mxbean2.getLoggerNames();

    // loggers1 and loggers2 should be identical - no new logger should
    // have been created in between (at least no new logger name)
    //
    if (loggers1.size() != loggers2.size())
        throw new RuntimeException("LoggerNames: unmatched number of entries");
    if (!loggers2.containsAll(loggersMap.keySet()))
        throw new RuntimeException("LoggerNames: unmatched loggers");


    // verify logger's level  and parent
    for (String logger : loggers1) {
        String level1 = mxbean1.getLoggerLevel(logger);
        String level2 = mxbean2.getLoggerLevel(logger);
        if (!java.util.Objects.equals(level1, level2)) {
            throw new RuntimeException(
                    "LoggerLevel: unmatched level for " + logger
                    + ", " + level1 + ", " + level2);
        }

        if (!mxbean1.getParentLoggerName(logger)
                .equals(mxbean2.getParentLoggerName(logger)))
            throw new RuntimeException(
                "ParentLoggerName: unmatched parent logger's name for " + logger);
    }
}
 
Example 8
Source Project: che   File: KeyBindings.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Waits the 'key bindings form' is loaded and checked text in 'key bindings' lines
 *
 * @param keyBindingsList is expected list binding keys
 */
public boolean checkAvailabilityAllKeyBindings(List<String> keyBindingsList) {

  List<String> itemsFromWidget =
      getListElementsKeyBindingById(Locators.ID_KEY_BY_KEY_BINDINGS)
          .stream()
          .map(WebElement::getText)
          .map(e -> e.replace("\n", " "))
          .collect(Collectors.toList());
  return itemsFromWidget.containsAll(keyBindingsList);
}
 
Example 9
Source Project: storm   File: MesosNimbusTest.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasResources(String role, List<Protos.Resource> resourceList, Double cpus, Double mem, Long port) {
  Double actualCpu = 0.0d, actualMem = 0.0d;
  List<Long> expectedPorts = new ArrayList<>();
  expectedPorts.add(port);

  List<Long> actualPorts = new ArrayList<>();
  for (Protos.Resource resource : resourceList) {
    if (!resource.getRole().equals(role)) {
      continue;
    }
    ResourceType r = ResourceType.of(resource.getName());
    switch (r) {
      case CPU:
        actualCpu += resource.getScalar().getValue();
        break;
      case MEM:
        actualMem += resource.getScalar().getValue();
        break;
      case PORTS:
        Protos.Value.Ranges ranges = resource.getRanges();
        for (Protos.Value.Range range : ranges.getRangeList()) {
          long endValue = range.getEnd();
          long beginValue = range.getBegin();
          while (endValue >= beginValue) {
            actualPorts.add(beginValue);
            ++beginValue;
          }
        }
    }
  }

  boolean hasExpectedPorts = (expectedPorts.size() == actualPorts.size()) && expectedPorts.containsAll(actualPorts);
  return actualCpu.equals(cpus) && actualMem.equals(mem) && hasExpectedPorts;
}
 
Example 10
Source Project: light-4j   File: ConsulUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check if two lists have the same urls.
 *
 * @param urls1 first url list
 * @param urls2 second url list
 * @return boolean true when they are the same
 */
public static boolean isSame(List<URL> urls1, List<URL> urls2) {
    if(urls1 == null && urls2 == null) {
        return true;
    }
    if (urls1 == null || urls2 == null) {
        return false;
    }
    if (urls1.size() != urls2.size()) {
        return false;
    }
    return urls1.containsAll(urls2);
}
 
Example 11
/** When unpacking, undo the effect of minimizeLocalICs.
 *  Must return negative if any IC tuples may have been deleted.
 *  Otherwise, return positive if any IC tuples were added.
 */
int expandLocalICs() {
    List<InnerClass> localICs = innerClasses;
    List<InnerClass> actualICs;
    int changed;
    if (localICs == null) {
        // Diff was empty.  (Common case.)
        List<InnerClass> impliedICs = computeGloballyImpliedICs();
        if (impliedICs.isEmpty()) {
            actualICs = null;
            changed = 0;
        } else {
            actualICs = impliedICs;
            changed = 1;  // added more tuples
        }
    } else if (localICs.isEmpty()) {
        // It was a non-empty diff, but the local ICs were absent.
        actualICs = null;
        changed = 0;  // [] => null, no tuple change
    } else {
        // Non-trivial diff was transmitted.
        actualICs = computeICdiff();
        // If we only added more ICs, return +1.
        changed = actualICs.containsAll(localICs)? +1: -1;
    }
    setInnerClasses(actualICs);
    return changed;
}
 
Example 12
public RelationType getLinkWithIds(List<String> ids) {
	if (relations==null || ids == null) {
		return null;
	}
	
	for (RelationType r : relations.getRelation()) {
		List<String> regionRefIds = getRegionRefsIds(r.getRegionRef());
		if (regionRefIds.size()==ids.size() && regionRefIds.containsAll(ids)) {
			return r;
		}
	}
	return null;
}
 
Example 13
private boolean matchCondition(
        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path
                .attributes.attributes.Communities> communities,
        final String communitySetName,
        final MatchSetOptionsType matchSetOptions) {

    final String setKey = StringUtils
            .substringBetween(communitySetName, "=\"", "\"");
    final List<Communities> communityFilter = this.communitySets.getUnchecked(setKey);

    if (communityFilter == null || communityFilter.isEmpty()) {
        return false;
    }

    List<Communities> commAttributeList;
    if (communities == null) {
        commAttributeList = Collections.emptyList();
    } else {
        commAttributeList = communities;
    }

    if (matchSetOptions.equals(MatchSetOptionsType.ALL)) {
        return commAttributeList.containsAll(communityFilter)
                && communityFilter.containsAll(commAttributeList);
    }
    final boolean noneInCommon = Collections.disjoint(commAttributeList, communityFilter);

    if (matchSetOptions.equals(MatchSetOptionsType.ANY)) {
        return !noneInCommon;
    }
    //(matchSetOptions.equals(MatchSetOptionsType.INVERT))
    return noneInCommon;
}
 
Example 14
private boolean compareArrVals(Annotation[] actualAnnos, String[] expectedAnnos) {
    // Look if test case was run.
    if (actualAnnos == specialAnnoArray) {
        return false; // no testcase matches
    }
    if (actualAnnos.length != expectedAnnos.length) {
        System.out.println("Length not same. "
                + " actualAnnos length = " + actualAnnos.length
                + " expectedAnnos length = " + expectedAnnos.length);
        printArrContents(actualAnnos);
        printArrContents(expectedAnnos);
        return false;
    } else {
        int i = 0;
        String[] actualArr = new String[actualAnnos.length];
        for (Annotation a : actualAnnos) {
            actualArr[i++] = a.toString();
        }
        List<String> actualList = Arrays.asList(actualArr);
        List<String> expectedList = Arrays.asList(expectedAnnos);

        if (!actualList.containsAll(expectedList)) {
            System.out.println("Array values are not same");
            printArrContents(actualAnnos);
            printArrContents(expectedAnnos);
            return false;
        }
    }
    return true;
}
 
Example 15
private static void checkAttributes(LoggingMXBean mxbean1,
                                    PlatformLoggingMXBean mxbean2) {
    // verify logger names
    List<String> loggers1 = mxbean1.getLoggerNames();
    System.out.println("Loggers: " + loggers1);

    // Retrieve the named loggers to prevent them from being
    // spontaneously gc'ed.
    Map<String, Logger> loggersMap = new HashMap<>();
    for (String n : loggers1) {
        loggersMap.put(n, Logger.getLogger(n));
    }

    List<String> loggers2 = mxbean2.getLoggerNames();

    // loggers1 and loggers2 should be identical - no new logger should
    // have been created in between (at least no new logger name)
    //
    if (loggers1.size() != loggers2.size())
        throw new RuntimeException("LoggerNames: unmatched number of entries");
    if (!loggers2.containsAll(loggersMap.keySet()))
        throw new RuntimeException("LoggerNames: unmatched loggers");


    // verify logger's level  and parent
    for (String logger : loggers1) {
        String level1 = mxbean1.getLoggerLevel(logger);
        String level2 = mxbean2.getLoggerLevel(logger);
        if (!java.util.Objects.equals(level1, level2)) {
            throw new RuntimeException(
                    "LoggerLevel: unmatched level for " + logger
                    + ", " + level1 + ", " + level2);
        }

        if (!mxbean1.getParentLoggerName(logger)
                .equals(mxbean2.getParentLoggerName(logger)))
            throw new RuntimeException(
                "ParentLoggerName: unmatched parent logger's name for " + logger);
    }
}
 
Example 16
private static void checkAttributes(LoggingMXBean mxbean1,
                                    PlatformLoggingMXBean mxbean2) {
    // verify logger names
    List<String> loggers1 = mxbean1.getLoggerNames();
    System.out.println("Loggers: " + loggers1);

    // Retrieve the named loggers to prevent them from being
    // spontaneously gc'ed.
    Map<String, Logger> loggersMap = new HashMap<>();
    for (String n : loggers1) {
        loggersMap.put(n, Logger.getLogger(n));
    }

    List<String> loggers2 = mxbean2.getLoggerNames();

    // loggers1 and loggers2 should be identical - no new logger should
    // have been created in between (at least no new logger name)
    //
    if (loggers1.size() != loggers2.size())
        throw new RuntimeException("LoggerNames: unmatched number of entries");
    if (!loggers2.containsAll(loggersMap.keySet()))
        throw new RuntimeException("LoggerNames: unmatched loggers");


    // verify logger's level  and parent
    for (String logger : loggers1) {
        String level1 = mxbean1.getLoggerLevel(logger);
        String level2 = mxbean2.getLoggerLevel(logger);
        if (!java.util.Objects.equals(level1, level2)) {
            throw new RuntimeException(
                    "LoggerLevel: unmatched level for " + logger
                    + ", " + level1 + ", " + level2);
        }

        if (!mxbean1.getParentLoggerName(logger)
                .equals(mxbean2.getParentLoggerName(logger)))
            throw new RuntimeException(
                "ParentLoggerName: unmatched parent logger's name for " + logger);
    }
}
 
Example 17
/**
 * Check to see if the list contains the values passed in.
 *
 * <p>In the SpringEL call values can be single item or array due to the way the EL converts values.
 * The values can be string or numeric and should match
 * the content type being stored in the list.  If the list is String and the values passed in are not string,
 * toString() conversion will be used.  Returns true if the values are in the list and both lists are non-empty,
 * false otherwise.
 * </p>
 *
 * @param list the list to be evaluated
 * @param values the values to be to check for in the list
 * @return true if all values exist in the list and both values and list are non-null/not-empty, false otherwise
 */
public static boolean listContains(List<?> list, Object[] values) {
    if (list != null && values != null && values.length > 0 && !list.isEmpty()) {
        //conversion for if the values are non-string but the list is string (special case)
        if (list.get(0) instanceof String && !(values[0] instanceof String)) {
            String[] stringValues = new String[values.length];
            for (int i = 0; i < values.length; i++) {
                stringValues[i] = values[i].toString();
            }
            return list.containsAll(Arrays.asList(stringValues));
        } else if (list.get(0) instanceof Date && values[0] instanceof String) {
            //TODO date conversion
            return false;
        } else if (!(list.get(0) instanceof String) && values[0] instanceof String) {
            //values passed in are string but the list is of objects, use object's toString method
            List<String> stringList = new ArrayList<String>();
            for (Object value : list) {
                stringList.add(value.toString());
            }
            return stringList.containsAll(Arrays.asList(values));
        } else {
            //no conversion for if neither list is String, assume matching types (numeric case)
            return list.containsAll(Arrays.asList(values));
        }
    }

    //no cases satisfied, return false
    return false;

}
 
Example 18
Source Project: webtester2-core   File: SelectedValues.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean test(MultiSelect select) {
    List<String> selectionValues = select.getSelectionValues();
    return expectedValues.containsAll(selectionValues) && selectionValues.containsAll(expectedValues);
}
 
Example 19
Source Project: Box   File: DebugUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static void checkPHI(MethodNode mth) {
	for (BlockNode block : mth.getBasicBlocks()) {
		List<PhiInsn> phis = new ArrayList<>();
		for (InsnNode insn : block.getInstructions()) {
			if (insn.getType() == InsnType.PHI) {
				PhiInsn phi = (PhiInsn) insn;
				phis.add(phi);
				if (phi.getArgsCount() == 0) {
					throw new JadxRuntimeException("No args and binds in PHI");
				}
				for (InsnArg arg : insn.getArguments()) {
					if (arg instanceof RegisterArg) {
						BlockNode b = phi.getBlockByArg((RegisterArg) arg);
						if (b == null) {
							throw new JadxRuntimeException("Predecessor block not found");
						}
					} else {
						throw new JadxRuntimeException("Not register in phi insn");
					}
				}
			}
		}
		PhiListAttr phiListAttr = block.get(AType.PHI_LIST);
		if (phiListAttr == null) {
			if (!phis.isEmpty()) {
				throw new JadxRuntimeException("Missing PHI list attribute");
			}
		} else {
			List<PhiInsn> phiList = phiListAttr.getList();
			if (phiList.isEmpty()) {
				throw new JadxRuntimeException("Empty PHI list attribute");
			}
			if (!phis.containsAll(phiList) || !phiList.containsAll(phis)) {
				throw new JadxRuntimeException("Instructions not match");
			}
		}
	}
	for (SSAVar ssaVar : mth.getSVars()) {
		for (PhiInsn usedInPhi : ssaVar.getUsedInPhi()) {
			boolean found = false;
			for (RegisterArg useArg : ssaVar.getUseList()) {
				InsnNode parentInsn = useArg.getParentInsn();
				if (parentInsn != null && parentInsn == usedInPhi) {
					found = true;
				}
			}
			if (!found) {
				throw new JadxRuntimeException("Used in phi incorrect");
			}
		}
	}
}
 
Example 20
private static boolean compareAnnotations(Annotation[] actualAnnos,
        String[] expectedAnnos) {
    boolean compOrder = false;

    // Length is different
    if (actualAnnos.length != expectedAnnos.length) {
        error("Length not same, Actual length = " + actualAnnos.length
                + " Expected length = " + expectedAnnos.length);
        printArrContents(actualAnnos);
        printArrContents(expectedAnnos);
        return false;
    } else {
        int i = 0;
        // Length is same and 0
        if (actualAnnos.length == 0) {
            // Expected/actual lengths already checked for
            // equality; no more checks do to
            return true;
        }
        // Expected annotation should be NULL
        if (actualAnnos[0] == null) {
            if (expectedAnnos[0].equals("NULL")) {
                debugPrint("Arr values are NULL as expected");
                return true;
            } else {
                error("Array values are not NULL");
                printArrContents(actualAnnos);
                printArrContents(expectedAnnos);
                return false;
            }
        }
        // Lengths are same, compare array contents
        String[] actualArr = new String[actualAnnos.length];
        for (Annotation a : actualAnnos) {
            if (a.annotationType().getSimpleName().contains("Expected"))
            actualArr[i++] = a.annotationType().getSimpleName();
             else if (a.annotationType().getName().contains(TESTPKG)) {
                String replaced = a.toString().replaceAll(Pattern.quote("testpkg."),"");
                actualArr[i++] = replaced;
            } else
                actualArr[i++] = a.toString();
        }
        List<String> actualList = new ArrayList<String>(Arrays.asList(actualArr));
        List<String> expectedList = new ArrayList<String>(Arrays.asList(expectedAnnos));
        if (!actualList.containsAll(expectedList)) {
            error("Array values are not same");
            printArrContents(actualAnnos);
            printArrContents(expectedAnnos);
            return false;
        } else {
            debugPrint("Arr values are same as expected");
            if (CHECKORDERING) {
                debugPrint("Checking if annotation ordering is as expected..");
                compOrder = compareOrdering(actualList, expectedList);
                if (compOrder)
                    debugPrint("Arr values ordering is as expected");
                else
                    error("Arr values ordering is not as expected! actual values: "
                        + actualList + " expected values: " + expectedList);
            } else
                compOrder = true;
        }
    }
    return compOrder;
}