NumberValue.java revision 56ed4167b942ec265f9cee70ac4d71d10b3835ce
1/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.clearsilver.jsilver.values;
18
19import com.google.clearsilver.jsilver.autoescape.EscapeMode;
20
21/**
22 * A simple numeric value.
23 *
24 * @see Value
25 */
26class NumberValue extends Value {
27
28  private final int value;
29
30  public NumberValue(int value, EscapeMode escapeMode, boolean partiallyEscaped) {
31    super(escapeMode, partiallyEscaped);
32    this.value = value;
33  }
34
35  @Override
36  public boolean asBoolean() {
37    return value != 0;
38  }
39
40  @Override
41  public String asString() {
42    return Integer.toString(value);
43  }
44
45  @Override
46  public int asNumber() {
47    return value;
48  }
49
50  @Override
51  public boolean exists() {
52    return true;
53  }
54
55  @Override
56  public boolean isEmpty() {
57    return value == 0;
58  }
59
60}
61