package com.onaro.sanscreen.client.view.changes;
import com.onaro.sanscreen.server.changes.Change;
import com.onaro.sanscreen.server.changes.ChangeConstants;
import com.onaro.sanscreen.types.ChangeType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
/**
* A list of ChangeGroup objects sorted by the change time and type.
*/
public class Changes extends ArrayList {
private static final long serialVersionUID = 1L;
/**
* The logger used by this package.
*/
static Logger logger = LogManager.getLogger(Changes.class);
/**
* A compartor for soring groups.
*/
private final static Comparator groupCompartor = new GroupComparator();
/**
* Builds change groups from a collection of changes. The groups are built to
* contain changes that occurred at the same time and relate to the same entity.
* The grouping is done in three phases:
*
Groups are created. Each change is assigned to a single group.
*
The groups are sorted by change time and type.
*
Redundant groups are merged.
*
*
* In order to determine the group that a change belongs to, the groups are
* held in a map indexed by a unique-key that is derived from the properties
* of the change. All the changes in a group will derive the same unique-key.
* The key generation is a service provided by the ChangeGroup
* class. Note that in order to filter out unwanted changes, the ChangeGroup
* will return a null key for that change.
*
* Because the unique-key based grouping is limited, some redundancy may occur
* among groups of changes that happened at the same time. For example, when
* an adapter is added or removed from a host, the keys for such events will
* differ from the keys regarding the host itself, yet they relate to the same
* entity. Therefore a merging phase takes place after the grouping is donw.
* Following are the kind of merges that are performed:
*
Adapter/Controller add/remove are merged into host/storage changes.
*
Path changes are merged into the violations caused by them (if at all).
*
Unresolve of adapters/controllers
*
* Optionally, a filter can be applied in the end of the process for removing
* groups by some custom cretaria.
*
* @param changes a collection of Change
* objects
* @param filter an optional type filter, may be null if no filter is in use
*/
public Changes(Collection changes, TypeFilter filter) {
/**
* Lists of change groups (not sorted) that occured at the same time.
*/
Map sameTimeGroups = new HashMap();
/**
* Create changes and groups.
*/
Map