Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/asm/SwitchData.java
38918 views
/*1* Copyright (c) 1994, 2013, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.asm;2627import sun.tools.java.*;28import java.util.Hashtable;29import java.util.Enumeration;30import java.util.Arrays;3132/**33* WARNING: The contents of this source file are not part of any34* supported API. Code that depends on them does so at its own risk:35* they are subject to change or removal without notice.36*/37public final38class SwitchData {39int minValue, maxValue;40Label defaultLabel = new Label();41Hashtable<Integer,Label> tab = new Hashtable<>();42// JCOV43Hashtable<Integer,Long> whereCaseTab = null;44// end JCOV4546/**47* Get a label48*/49public Label get(int n) {50return tab.get(n);51}5253/**54* Get a label55*/56public Label get(Integer n) {57return tab.get(n);58}5960/**61* Add a label62*/63public void add(int n, Label lbl) {64if (tab.size() == 0) {65minValue = n;66maxValue = n;67} else {68if (n < minValue) {69minValue = n;70}71if (n > maxValue) {72maxValue = n;73}74}75tab.put(Integer.valueOf(n), lbl);76}7778/**79* Get the default label80*/81public Label getDefaultLabel() {82return defaultLabel;83}8485/**86* Return the keys of this enumaration sorted in ascending order87*/88public synchronized Enumeration<Integer> sortedKeys() {89return new SwitchDataEnumeration(tab);90}9192// JCOV93public void initTableCase() {94whereCaseTab = new Hashtable<Integer,Long>();95}96public void addTableCase(int index, long where) {97if (whereCaseTab != null)98whereCaseTab.put(Integer.valueOf(index), Long.valueOf(where));99}100// this puts String key into Hashtable<Integer,Long>101@SuppressWarnings("unchecked")102public void addTableDefault(long where) {103if (whereCaseTab != null)104((Hashtable)whereCaseTab).put("default", Long.valueOf(where));105}106public long whereCase(Object key) {107Long i = whereCaseTab.get(key);108return (i == null) ? 0L : i.longValue();109}110public boolean getDefault() {111return (whereCase("default") != 0L);112}113// end JCOV114}115116class SwitchDataEnumeration implements Enumeration<Integer> {117private Integer table[];118private int current_index = 0;119120/**121* Create a new enumeration from the hashtable. Each key in the122* hash table will be an Integer, with the value being a label. The123* enumeration returns the keys in sorted order.124*/125SwitchDataEnumeration(Hashtable<Integer,Label> tab) {126table = new Integer[tab.size()];127int i = 0;128for (Enumeration<Integer> e = tab.keys() ; e.hasMoreElements() ; ) {129table[i++] = e.nextElement();130}131Arrays.sort(table);132current_index = 0;133}134135/**136* Are there more keys to return?137*/138public boolean hasMoreElements() {139return current_index < table.length;140}141142/**143* Return the next key.144*/145public Integer nextElement() {146return table[current_index++];147}148}149150151