Path: blob/master/test/jdk/java/util/Calendar/CalendarTestScripts/Variable.java
41152 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.HashMap;24import java.util.Locale;25import java.util.Map;2627public class Variable {28private static Map<String,Variable> vars = new HashMap<String,Variable>();2930private String name;31private long value;3233Variable(String name, long value) {34this.name = name;35this.value = value;36}3738public String getName() {39return name;40}4142public int intValue() {43if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {44throw new RuntimeException("Overflow/Underflow: " + value);45}46return (int) value;47}4849public long longValue() {50return value;51}5253public void setValue(int v) { value = v; }54public void setValue(long v) { value = v; }5556// static methods5758public static Variable newVar(String name, long value) {59if (name.charAt(0) != '$') {60throw new RuntimeException("wrong var name: " + name);61}62String s = name.toLowerCase(Locale.ROOT);63Variable v = new Variable(name, value);64put(name, v);65return v;66}6768static void put(String s, Variable var) {69vars.put(s, var);70}7172public static Variable get(String name) {73return vars.get(name);74}75}767778