001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.mappaint.mapcss; 003 004import java.util.Arrays; 005 006import org.openstreetmap.josm.gui.mappaint.Environment; 007import org.openstreetmap.josm.tools.CheckParameterUtil; 008 009/** 010 * Simple literal value, that does not depend on other expressions. 011 * @since 5705 012 */ 013public class LiteralExpression implements Expression { 014 private final Object literal; 015 016 /** 017 * Constructs a new {@code LiteralExpression}. 018 * @param literal literal 019 */ 020 public LiteralExpression(Object literal) { 021 CheckParameterUtil.ensureParameterNotNull(literal); 022 this.literal = literal; 023 } 024 025 /** 026 * Returns the literal. 027 * @return the literal 028 * @since 14484 029 */ 030 public final Object getLiteral() { 031 return literal; 032 } 033 034 @Override 035 public Object evaluate(Environment env) { 036 return literal; 037 } 038 039 @Override 040 public String toString() { 041 if (literal instanceof float[]) { 042 return Arrays.toString((float[]) literal); 043 } 044 return '<' + literal.toString() + '>'; 045 } 046}