Major cleanup of Utils class.
[trakem2.git] / ini / trakem2 / display / TransformationStep.java
blobc6582d4b0c7dc72cc29d37f4b7442ba402596aaa
1 package ini.trakem2.display;
3 import ini.trakem2.utils.History;
4 import java.util.HashMap;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.ArrayList;
9 import java.awt.geom.AffineTransform;
11 public class TransformationStep implements History.Step<Displayable> {
12 final HashMap<Displayable,AffineTransform> ht;
13 TransformationStep(final HashMap<Displayable,AffineTransform> ht) {
14 this.ht = ht;
16 public List<Displayable> remove(final long id) {
17 final List<Displayable> al = new ArrayList<Displayable>();
18 for (Iterator<Displayable> it = ht.keySet().iterator(); it.hasNext(); ) {
19 final Displayable d = it.next();
20 if (d.getId() == id) {
21 it.remove();
23 al.add(d);
25 return al;
27 public boolean isEmpty() {
28 return ht.isEmpty();
30 public boolean isIdentical(final History.Step step) {
31 if (step.getClass() != TransformationStep.class) return false;
32 final HashMap<Displayable,AffineTransform> m = ((TransformationStep)step).ht;
33 // cheap test:
34 if (m.size() != this.ht.size()) return false;
35 // Check each:
36 for (final Map.Entry<Displayable,AffineTransform> e : m.entrySet()) {
37 final AffineTransform aff = this.ht.get(e.getKey());
38 if (null == aff) return false; // at least one Displayable is missing
39 if (!aff.equals(e.getValue())) return false; // at least one Displayable has a different AffineTransform
41 return true;