List of usage examples for org.apache.commons.collections4 FactoryUtils prototypeFactory
public static <T> Factory<T> prototypeFactory(final T prototype)
From source file:uniol.apt.analysis.synthesize.SynthesizePN.java
/** * Calculate the set of states which aren't separated by the given regions. * @param states The states to separate/* w ww .ja v a2 s .c om*/ * @param regions The regions that are used for separation * @return All states which have for at least one other state the same marking in all regions. */ static public Set<State> calculateUnseparatedStates(Set<State> states, Set<Region> regions) { Set<State> result = new HashSet<>(); Set<Set<State>> partition = new HashSet<>(); partition.add(new HashSet<>(states)); debug("Calculating unseparated states"); for (Region region : regions) { int discarded = 0; Set<Set<State>> newPartition = new HashSet<>(); for (Set<State> family : partition) { InterrupterRegistry.throwIfInterruptRequestedForCurrentThread(); // Separate this family by the given region: States to which this region assigns // different markings are separated. Map<Integer, Set<State>> markings = LazyMap.lazyMap(new HashMap<Integer, Set<State>>(), FactoryUtils.prototypeFactory(new HashSet<State>())); for (State state : family) { try { markings.get(region.getMarkingForState(state)).add(state); } catch (UnreachableException e) { // SSP with any unreachable state is unsolvable return states; } } // Now collect families of not-yet-separated states for (Map.Entry<Integer, Set<State>> entry : markings.entrySet()) { if (entry.getValue().size() > 1) newPartition.add(entry.getValue()); else discarded++; } } partition = newPartition; debugFormat("After region %s, still have %d families " + "(%d resulting singular families discarded)", region, partition.size(), discarded); if (partition.isEmpty()) break; } // All remaining states are not yet separated. Throw away the family information and return them all. for (Set<State> family : partition) result.addAll(family); return result; }