source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/LiteralExpression.java@ 15934

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

see #18749 - Intern strings to reduce memory footprint

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import java.util.Arrays;
5
6import org.openstreetmap.josm.gui.mappaint.Environment;
7import org.openstreetmap.josm.tools.CheckParameterUtil;
8
9/**
10 * Simple literal value, that does not depend on other expressions.
11 * @since 5705
12 */
13public class LiteralExpression implements Expression {
14 private final Object literal;
15
16 /**
17 * Constructs a new {@code LiteralExpression}.
18 * @param literal literal
19 */
20 public LiteralExpression(Object literal) {
21 CheckParameterUtil.ensureParameterNotNull(literal);
22 this.literal = literal instanceof String ? ((String) literal).intern() : literal;
23 }
24
25 /**
26 * Returns the literal.
27 * @return the literal
28 * @since 14484
29 */
30 public final Object getLiteral() {
31 return literal;
32 }
33
34 @Override
35 public Object evaluate(Environment env) {
36 return literal;
37 }
38
39 @Override
40 public String toString() {
41 if (literal instanceof float[]) {
42 return Arrays.toString((float[]) literal);
43 }
44 return '<' + literal.toString() + '>';
45 }
46}
Note: See TracBrowser for help on using the repository browser.