source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java@ 7140

Last change on this file since 7140 was 7140, checked in by Don-vip, 10 years ago

fix compilation warnings with JDK8 - equals() and hashcode() must be overriden in pairs

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import java.util.List;
5
6import org.openstreetmap.josm.gui.mappaint.Environment;
7import org.openstreetmap.josm.tools.Utils;
8
9/**
10 * A MapCSS rule.
11 *
12 * A MapCSS style is simply a list of MapCSS rules. Each rule has a selector
13 * and a declaration. Whenever the selector matches the primitive, the
14 * declaration block is executed for this primitive.
15 */
16public class MapCSSRule implements Comparable<MapCSSRule> {
17
18 public final Selector selector;
19 public final Declaration declaration;
20
21 public static class Declaration {
22 public final List<Instruction> instructions;
23 // declarations in the StyleSource are numbered consecutively
24 public final int idx;
25
26 public Declaration(List<Instruction> instructions, int idx) {
27 this.instructions = instructions;
28 this.idx = idx;
29 }
30
31 /**
32 * <p>Executes the instructions against the environment {@code env}</p>
33 *
34 * @param env the environment
35 */
36 public void execute(Environment env) {
37 for (Instruction i : instructions) {
38 i.execute(env);
39 }
40 }
41
42 @Override
43 public int hashCode() {
44 final int prime = 31;
45 int result = 1;
46 result = prime * result + idx;
47 result = prime * result + ((instructions == null) ? 0 : instructions.hashCode());
48 return result;
49 }
50
51 @Override
52 public boolean equals(Object obj) {
53 if (this == obj)
54 return true;
55 if (obj == null)
56 return false;
57 if (!(obj instanceof Declaration))
58 return false;
59 Declaration other = (Declaration) obj;
60 if (idx != other.idx)
61 return false;
62 if (instructions == null) {
63 if (other.instructions != null)
64 return false;
65 } else if (!instructions.equals(other.instructions))
66 return false;
67 return true;
68 }
69 }
70
71 public MapCSSRule(Selector selector, Declaration declaration) {
72 this.selector = selector;
73 this.declaration = declaration;
74 }
75
76 /**
77 * <p>Executes the instructions against the environment {@code env}</p>
78 *
79 * @param env the environment
80 */
81 public void execute(Environment env) {
82 declaration.execute(env);
83 }
84
85 @Override
86 public int compareTo(MapCSSRule o) {
87 return declaration.idx - o.declaration.idx;
88 }
89
90 @Override
91 public String toString() {
92 return selector + " {\n " + Utils.join("\n ", declaration.instructions) + "\n}";
93 }
94}
95
Note: See TracBrowser for help on using the repository browser.