@Override public boolean equals(Object inputO) { if (this == inputO) { return true; } if (!(inputO instanceof AdvancedState)) { return false; } AdvancedState compare = (AdvancedState) inputO; if (!((names.containsAll(compare.getNames()) && (compare.getNames().containsAll(names))))) { return false; } if (acceptanceState != compare.isAcceptanceState()) { return false; } if (initialState != compare.isInitialState()) { return false; } return true; }
/** * Add providing bundles from the <code>deps</code> list that provides at least one of the * packages in <code>pkgs</code>. Try to avoid having multiple providers of the same package. * * @param res The selected providers to make dependencies of. * @param pkgs The set of packages that shall be provided by the providers added to res. * @param deps Provider bundles that are dependency candidates. */ private void selectProviders( final Map<BundleArchive, SortedSet<String>> res, final Set<String> pkgs, final List<Entry<BundleArchive, SortedSet<String>>> deps) { // Iterate over dependency candidates that exports packages, // Add bundles that contributes at least one package to res. for (final Iterator<Entry<BundleArchive, SortedSet<String>>> itDeps = deps.iterator(); 0 < pkgs.size() && itDeps.hasNext(); ) { final Entry<BundleArchive, SortedSet<String>> entry = itDeps.next(); final BundleArchives.BundleArchive ba = entry.getKey(); final SortedSet<String> pPkgs = entry.getValue(); log( " Trying provider: " + ba + ": exporting " + pPkgs + " looking for: " + pkgs, Project.MSG_DEBUG); if (pkgs.removeAll(pPkgs)) { // entry provides needed packages, add its bundle to the result. log(" Selecting provider: " + ba + " exporting " + pPkgs, Project.MSG_VERBOSE); // Remove any provider that will not provide any unique // package after the addition of ba. for (final Iterator<Entry<BundleArchive, SortedSet<String>>> itRes = res.entrySet().iterator(); itRes.hasNext(); ) { final Entry<BundleArchive, SortedSet<String>> resEntry = itRes.next(); final BundleArchives.BundleArchive resBa = resEntry.getKey(); final SortedSet<String> resPkgs = resEntry.getValue(); if (pPkgs.containsAll(resPkgs)) { log(" Removing redundant provider: " + resBa, Project.MSG_VERBOSE); itRes.remove(); } } res.put(ba, pPkgs); } } }
@Override public boolean containsAll(Collection<?> c) { return attributes.containsAll(c); }
private static Evidence checkShuffleMisbehavior( Map<Integer, VerificationKey> players, Map<VerificationKey, DecryptionKey> decryptionKeys, Map<VerificationKey, Packet> shuffleMessages, Map<VerificationKey, Packet> broadcastMessages) throws FormatException { if (players == null || decryptionKeys == null || shuffleMessages == null || broadcastMessages == null) throw new NullPointerException(); SortedSet<String> outputs = new TreeSet<>(); // Go through the steps of shuffling messages. for (int i = 1; i < players.size(); i++) { Packet packet = shuffleMessages.get(players.get(i + 1)); if (packet == null) { // TODO Blame a player for lying. return null; } Message message = packet.payload(); // Grab the correct number of addresses and decrypt them. SortedSet<String> decrypted = new TreeSet<>(); for (int j = 0; j < i; j++) { if (message.isEmpty()) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(i), decryptionKeys, shuffleMessages, broadcastMessages); } String address = message.readString(); message = message.rest(); for (int k = i + 1; k <= players.size(); k++) { address = decryptionKeys.get(players.get(k)).decrypt(address); } // There shouldn't be duplicates. if (decrypted.contains(address)) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(i), decryptionKeys, shuffleMessages, broadcastMessages); } decrypted.add(address); } // Does this contain all the previous addresses? if (!decrypted.containsAll(outputs)) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(i), decryptionKeys, shuffleMessages, broadcastMessages); } decrypted.removeAll(outputs); // There should be one new address. if (decrypted.size() != 1) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(i), decryptionKeys, shuffleMessages, broadcastMessages); } outputs.add(decrypted.first()); } // Now check the last set of messages from player N. // All broadcast messages should have the same content and we should // have already checked for this. Therefore we just look for the first // one that is available. // (The message for player 1 should always be available, so theoretically // we don't need to loop through everybody, but who knows what might have happened.) Packet packet = null; for (int j = 1; j <= players.size(); j++) { packet = broadcastMessages.get(players.get(j)); if (packet != null) { break; } } if (packet == null) { // TODO blame someone. return null; } Message message = packet.payload(); // Grab the correct number of addresses and decrypt them. SortedSet<String> addresses = new TreeSet<>(); for (int j = 0; j < players.size(); j++) { if (message.isEmpty()) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(players.size()), decryptionKeys, shuffleMessages, broadcastMessages); } Address address = message.readAddress(); // There shouldn't be duplicates. if (addresses.contains(address.toString())) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(players.size()), decryptionKeys, shuffleMessages, broadcastMessages); } addresses.add(address.toString()); } // Does this contain all the previous addresses? if (!addresses.containsAll(outputs)) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(players.size()), decryptionKeys, shuffleMessages, broadcastMessages); } addresses.removeAll(outputs); // There should be one new address. if (addresses.size() != 1) { return Evidence.ShuffleMisbehaviorDropAddress( players.get(players.size()), decryptionKeys, shuffleMessages, broadcastMessages); } return null; }
private <T> void verify(SortedSet<T> immutableSet, SortedSet<T> mutableSet, T value1, T value2) { try { immutableSet.add(value1); Assert.fail(); } catch (UnsupportedOperationException e) { } try { immutableSet.addAll(java.util.Collections.singleton(value1)); Assert.fail(); } catch (UnsupportedOperationException e) { } try { immutableSet.clear(); Assert.assertTrue(mutableSet.isEmpty()); } catch (UnsupportedOperationException e) { Assert.assertFalse(mutableSet.isEmpty()); } Assert.assertEquals(immutableSet.contains(value1), mutableSet.contains(value1)); Assert.assertEquals(immutableSet.contains(value2), mutableSet.contains(value2)); Assert.assertEquals( immutableSet.containsAll(java.util.Collections.emptySet()), mutableSet.containsAll(java.util.Collections.emptySet())); Assert.assertEquals( immutableSet.containsAll(java.util.Collections.singleton(0)), mutableSet.containsAll(java.util.Collections.singleton(0))); Assert.assertEquals( immutableSet.containsAll(java.util.Collections.singleton(1)), mutableSet.containsAll(java.util.Collections.singleton(1))); Iterator<T> iterator = immutableSet.iterator(); if (!mutableSet.isEmpty()) { Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(iterator.next(), mutableSet.iterator().next()); } Assert.assertFalse(iterator.hasNext()); try { iterator.next(); Assert.fail(); } catch (NoSuchElementException e) { } Assert.assertEquals(immutableSet.isEmpty(), mutableSet.isEmpty()); try { immutableSet.remove(value1); } catch (UnsupportedOperationException e) { } try { immutableSet.removeAll(java.util.Collections.singleton(value1)); } catch (UnsupportedOperationException e) { } try { immutableSet.retainAll(java.util.Collections.singleton(value1)); } catch (UnsupportedOperationException e) { } Assert.assertEquals(immutableSet.size(), mutableSet.size()); Assert.assertArrayEquals(immutableSet.toArray(), mutableSet.toArray()); Assert.assertSame(immutableSet.comparator(), mutableSet.comparator()); if (!mutableSet.isEmpty()) { Assert.assertEquals(immutableSet.first(), mutableSet.first()); Assert.assertEquals(immutableSet.last(), mutableSet.last()); } else { try { immutableSet.first(); Assert.fail(); } catch (NoSuchElementException e) { } try { immutableSet.last(); Assert.fail(); } catch (NoSuchElementException e) { } } Assert.assertEquals(immutableSet.headSet(value1), mutableSet.headSet(value1)); Assert.assertEquals(immutableSet.headSet(value2), mutableSet.headSet(value2)); Assert.assertEquals(immutableSet.subSet(value1, value2), mutableSet.subSet(value1, value2)); Assert.assertEquals(immutableSet.tailSet(value1), mutableSet.tailSet(value1)); Assert.assertEquals(immutableSet.tailSet(value2), mutableSet.tailSet(value2)); }