source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Declaration.java@ 17765

Last change on this file since 17765 was 15983, checked in by simon04, 4 years ago

see #18802 - Extract org.openstreetmap.josm.gui.mappaint.mapcss.Declaration

File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import java.util.List;
5import java.util.Objects;
6
7import org.openstreetmap.josm.gui.mappaint.Environment;
8import org.openstreetmap.josm.gui.mappaint.StyleSource;
9import org.openstreetmap.josm.tools.Utils;
10
11/**
12 * A declaration is a list of {@link Instruction}s
13 */
14public 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}
Note: See TracBrowser for help on using the repository browser.