History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/tools/asm/SwitchData.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/tools/asm/SwitchData.java+147−0
@@ -0,0 +1,147 @@
1/*
2 * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package sun.tools.asm;
27
28import sun.tools.java.*;
29import java.util.Hashtable;
30import java.util.Enumeration;
31import java.util.Arrays;
32
33/**
34 * WARNING: The contents of this source file are not part of any
35 * supported API. Code that depends on them does so at its own risk:
36 * they are subject to change or removal without notice.
37 */
38public final
39class SwitchData {
40 int minValue, maxValue;
41 Label defaultLabel = new Label();
42 Hashtable tab = new Hashtable();
43// JCOV
44 Hashtable whereCaseTab = null;
45// end JCOV
46
47 /**
48 * Get a label
49 */
50 public Label get(int n) {
51 return (Label)tab.get(new Integer(n));
52 }
53
54 /**
55 * Get a label
56 */
57 public Label get(Integer n) {
58 return (Label)tab.get(n);
59 }
60
61 /**
62 * Add a label
63 */
64 public void add(int n, Label lbl) {
65 if (tab.size() == 0) {
66 minValue = n;
67 maxValue = n;
68 } else {
69 if (n < minValue) {
70 minValue = n;
71 }
72 if (n > maxValue) {
73 maxValue = n;
74 }
75 }
76 tab.put(new Integer(n), lbl);
77 }
78
79 /**
80 * Get the default label
81 */
82 public Label getDefaultLabel() {
83 return defaultLabel;
84 }
85
86 /**
87 * Return the keys of this enumaration sorted in ascending order
88 */
89 public synchronized Enumeration sortedKeys() {
90 return new SwitchDataEnumeration(tab);
91 }
92
93// JCOV
94 public void initTableCase() {
95 whereCaseTab = new Hashtable();
96 }
97 public void addTableCase(int index, long where) {
98 if (whereCaseTab != null)
99 whereCaseTab.put(new Integer(index), new Long(where));
100 }
101 public void addTableDefault(long where) {
102 if (whereCaseTab != null)
103 whereCaseTab.put("default", new Long(where));
104 }
105 public long whereCase(Object key) {
106 Long i = (Long) whereCaseTab.get(key);
107 return (i == null) ? 0 : i.longValue();
108 }
109 public boolean getDefault() {
110 return (whereCase("default") != 0);
111 }
112// end JCOV
113}
114
115class SwitchDataEnumeration implements Enumeration {
116 private Integer table[];
117 private int current_index = 0;
118
119 /**
120 * Create a new enumeration from the hashtable. Each key in the
121 * hash table will be an Integer, with the value being a label. The
122 * enumeration returns the keys in sorted order.
123 */
124 SwitchDataEnumeration(Hashtable tab) {
125 table = new Integer[tab.size()];
126 int i = 0;
127 for (Enumeration e = tab.keys() ; e.hasMoreElements() ; ) {
128 table[i++] = (Integer)e.nextElement();
129 }
130 Arrays.sort(table);
131 current_index = 0;
132 }
133
134 /**
135 * Are there more keys to return?
136 */
137 public boolean hasMoreElements() {
138 return current_index < table.length;
139 }
140
141 /**
142 * Return the next key.
143 */
144 public Object nextElement() {
145 return table[current_index++];
146 }
147}