List of usage examples for com.google.common.collect ImmutableBiMap containsKey
boolean containsKey(Object key);
From source file:com.github.rinde.rinsim.central.arrays.ArraysSolverValidator.java
private static void validateCurrentSolutions(int v, int n, SolutionObject[] currentSolutions, int[] currentDestinations, Multimap<Integer, Integer> inventoriesMap, ImmutableBiMap<Integer, Integer> servicePairsMap) { checkArgument(currentSolutions.length == v, "The number of currentSolutions (%s) should equal the number of " + "vehicles (%s).", currentSolutions.length, v); for (int i = 0; i < currentSolutions.length; i++) { final List<Integer> route = ImmutableList.copyOf(Ints.asList(currentSolutions[i].route)); checkArgument(route.get(0) == 0, "First item in route should always be 0, it is %s.", route.get(0)); checkArgument(route.get(route.size() - 1) == n - 1, "Last item in route should always be depot (%s), it is %s.", n - 1, route.get(route.size() - 1)); if (currentDestinations[i] > 0) { // there is a current destination checkArgument(currentDestinations[i] == route.get(1), "The vehicle has a current destination (%s) but it is not the " + "first item in its route: %s.", currentDestinations[i], route); }//from w w w . j av a 2 s . c om final Collection<Integer> inventory = inventoriesMap.get(i); checkArgument(ImmutableSet.copyOf(route).containsAll(inventory), "The route should contain all locations in its inventory. Vehicle " + "%s, route: %s, inventory: %s.", i, route, inventory); for (int j = 1; j < route.size() - 1; j++) { final Integer item = route.get(j); final int freq = Collections.frequency(route, item); checkArgument(freq == 1, "Vehicle %s: each location should occur only once, found %s " + "instances of location %s. Route: %s.", i, freq, item, route); if (!inventoriesMap.containsEntry(i, item)) { // not in cargo, so the pair should appear in the route if (servicePairsMap.containsKey(item)) { checkArgument(route.contains(servicePairsMap.get(item)), "Couldn't find %s in regular mapping.", item); } else { checkArgument(route.contains(servicePairsMap.inverse().get(item)), "Couldn't find %s in inverse mapping.", item); } } } } }