Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSList.java @ 4006:436b4a3231bf
7098194: integrate macosx-port changes
Summary: Integrate bsd-port/hotspot and macosx-port/hotspot changes as of 2011.09.29.
Reviewed-by: kvn, dholmes, never, phh
Contributed-by: Christos Zoulas <christos@zoulas.com>, Greg Lewis <glewis@eyesbeyond.com>, Kurt Miller <kurt@intricatesoftware.com>, Alexander Strange <astrange@apple.com>, Mike Swingler <swingler@apple.com>, Roger Hoover <rhoover@apple.com>, Victor Hernandez <vhernandez@apple.com>, Pratik Solanki <psolanki@apple.com>
author | dcubed |
---|---|
date | Thu, 13 Oct 2011 09:35:42 -0700 |
parents | c18cbe5936b8 |
children |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved. |
0 | 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.utilities.soql; | |
26 | |
27 import java.util.*; | |
28 import sun.jvm.hotspot.oops.*; | |
29 | |
30 /** | |
31 This is JavaScript wrapper for Java List. | |
32 */ | |
33 | |
34 public class JSList extends DefaultScriptObject { | |
35 public JSList(List list, JSJavaFactory fac) { | |
36 this.list = list; | |
37 this.factory = fac; | |
38 } | |
39 | |
40 public Object get(String name) { | |
41 if (name.equals("length")) { | |
42 return new Integer(list.size()); | |
43 } else { | |
44 return super.get(name); | |
45 } | |
46 } | |
47 | |
48 public Object get(int index) { | |
49 if (isInRange(index)) { | |
50 Object item = list.get(index); | |
51 return wrapObject(item); | |
52 } else { | |
53 return super.get(index); | |
54 } | |
55 } | |
56 | |
57 public Object[] getIds() { | |
58 Object[] superIds = super.getIds(); | |
59 final int size = list.size(); | |
60 Object[] res = new Object[superIds.length + size]; | |
61 for (int i = 0; i < size; i++) { | |
62 res[i] = new Integer(i); | |
63 } | |
64 System.arraycopy(superIds, 0, res, size, superIds.length); | |
65 return res; | |
66 } | |
67 | |
68 public boolean has(String name) { | |
69 if (name.equals("length")) { | |
70 return true; | |
71 } else { | |
72 return super.has(name); | |
73 } | |
74 } | |
75 | |
76 public boolean has(int index) { | |
77 if (isInRange(index)) { | |
78 return true; | |
79 } else { | |
80 return super.has(index); | |
81 } | |
82 } | |
83 | |
84 public void put(String name, Object value) { | |
85 if (! name.equals("length")) { | |
86 super.put(name, value); | |
87 } | |
88 } | |
89 | |
90 public void put(int index, Object value) { | |
91 if (! isInRange(index)) { | |
92 super.put(index, value); | |
93 } | |
94 } | |
95 | |
96 public String toString() { | |
97 StringBuffer buf = new StringBuffer(); | |
98 buf.append('['); | |
99 for (Iterator itr = list.iterator(); itr.hasNext();) { | |
100 buf.append(wrapObject(itr.next())); | |
101 if (itr.hasNext()) { | |
102 buf.append(", "); | |
103 } | |
104 } | |
105 buf.append(']'); | |
106 return buf.toString(); | |
107 } | |
108 | |
109 //-- Internals only below this point | |
110 private boolean isInRange(int index) { | |
111 return index >= 0 && index < list.size(); | |
112 } | |
113 | |
114 private Object wrapObject(Object obj) { | |
115 return factory.newJSJavaWrapper(obj); | |
116 } | |
117 | |
118 private final List list; | |
119 private final JSJavaFactory factory; | |
120 } |