All of the fields must be filled.
You cannot swap a section with a page.
You must first select a group before adding a user to it.

Extracting unique values from a list is a common problem and the goal is to do it in as little operations as possible. The memory used is negligeable and this can be done in linear time.
The goal is to use a map who's keys are the values. We can therefore test to see if the element is already in the list in O(1) and insure linear time of the algorithm.
|
public static <T extends Object> List<T> getUniques(List<T> list) {
//Initiate the necessary variables.
final List<T> uniques = new ArrayList<T>();
//We declare the map to be final and it will be garbage
//collected at the end of this method's execution, making //the space used by the map temporary.
final HashMap<T,T> hm = new HashMap<T,T>(); //Loop through all of the elements.
for (T t : list) {
//If you don't find the object in the map, it is
//unique and we add it to the uniques list.
if (hm.get(t) == null) {
hm.put(t,t);
uniques.add(t);
}
}
return uniques;
}
|
The above example shows a method that will accept a list of any extension of Objects using generic templates. However, it should be noted that HashMap uses the Object's hash code for a unique identifier. If this method is overridden, it is possible that HashMaps may not work properly with those Objects.
Note that it would be possible to check for unique on insert of the list, making this method unecessary, but it would mean having to store the map along with the list. The trade off of space and memory depends on the size of the list and the need for a live list of uniques.