1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.Objects;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.gui.mappaint.Environment;
|
---|
8 | import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
---|
9 | import org.openstreetmap.josm.tools.Utils;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * A declaration is a list of {@link Instruction}s
|
---|
13 | */
|
---|
14 | public class Declaration {
|
---|
15 | /**
|
---|
16 | * The instructions in this declaration
|
---|
17 | */
|
---|
18 | public final List<Instruction> instructions;
|
---|
19 | /**
|
---|
20 | * The index of this declaration
|
---|
21 | * <p>
|
---|
22 | * declarations in the StyleSource are numbered consecutively
|
---|
23 | */
|
---|
24 | public final int idx;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Create a new {@link Declaration}
|
---|
28 | * @param instructions The instructions for this declaration
|
---|
29 | * @param idx The index in the {@link StyleSource}
|
---|
30 | */
|
---|
31 | public Declaration(List<Instruction> instructions, int idx) {
|
---|
32 | this.instructions = Utils.toUnmodifiableList(instructions);
|
---|
33 | this.idx = idx;
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * <p>Executes the instructions against the environment {@code env}</p>
|
---|
38 | *
|
---|
39 | * @param env the environment
|
---|
40 | */
|
---|
41 | public void execute(Environment env) {
|
---|
42 | for (Instruction i : instructions) {
|
---|
43 | i.execute(env);
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public int hashCode() {
|
---|
49 | return Objects.hash(instructions, idx);
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public boolean equals(Object obj) {
|
---|
54 | if (this == obj) return true;
|
---|
55 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
56 | Declaration that = (Declaration) obj;
|
---|
57 | return idx == that.idx &&
|
---|
58 | Objects.equals(instructions, that.instructions);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public String toString() {
|
---|
63 | return "Declaration [instructions=" + instructions + ", idx=" + idx + ']';
|
---|
64 | }
|
---|
65 | }
|
---|