|
1 |
| -package org.kitteh.catcher; |
2 |
| - |
3 |
| -/* |
4 |
| - Based on CompactHashSet Copyright 2011 Ontopia Project |
5 |
| -
|
6 |
| - Licensed under the Apache License, Version 2.0 (the "License"); |
7 |
| - you may not use this file except in compliance with the License. |
8 |
| - You may obtain a copy of the License at |
9 |
| -
|
10 |
| - http://www.apache.org/licenses/LICENSE-2.0 |
11 |
| -
|
12 |
| - Unless required by applicable law or agreed to in writing, software |
13 |
| - distributed under the License is distributed on an "AS IS" BASIS, |
14 |
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 |
| - See the License for the specific language governing permissions and |
16 |
| - limitations under the License. |
17 |
| -*/ |
18 |
| - |
19 |
| -import java.lang.reflect.Field; |
20 |
| -import java.util.Iterator; |
21 |
| - |
22 |
| -import org.bukkit.craftbukkit.v1_4_5.util.LongHash; |
23 |
| -import org.bukkit.craftbukkit.v1_4_5.util.LongHashSet; |
24 |
| - |
25 |
| -public class LongHugSet extends LongHashSet { |
26 |
| - //Ah, the... |
27 |
| - public static void olBukkitSwitcharoo(LongHashSet mommy, LongHashSet baby) { |
28 |
| - try { |
29 |
| - Field fe = LongHashSet.class.getDeclaredField("freeEntries"); |
30 |
| - fe.setAccessible(true); |
31 |
| - fe.setInt(baby, fe.getInt(mommy)); |
32 |
| - fe = LongHashSet.class.getDeclaredField("elements"); |
33 |
| - fe.setAccessible(true); |
34 |
| - fe.setInt(baby, fe.getInt(mommy)); |
35 |
| - fe = LongHashSet.class.getDeclaredField("values"); |
36 |
| - fe.setAccessible(true); |
37 |
| - fe.set(baby, fe.get(mommy)); |
38 |
| - fe = LongHashSet.class.getDeclaredField("modCount"); |
39 |
| - fe.setAccessible(true); |
40 |
| - fe.setInt(baby, fe.getInt(mommy)); |
41 |
| - } catch (final Exception e) { |
42 |
| - e.printStackTrace(); |
43 |
| - } |
44 |
| - } |
45 |
| - private final Thread thread; |
46 |
| - |
47 |
| - private final Plugin plugin; |
48 |
| - |
49 |
| - public LongHugSet(LongHashSet mommy, Plugin plugin) { |
50 |
| - super(mommy.size()); |
51 |
| - |
52 |
| - this.thread = Thread.currentThread(); |
53 |
| - this.plugin = plugin; |
54 |
| - } |
55 |
| - |
56 |
| - @Override |
57 |
| - public boolean add(int msw, int lsw) { |
58 |
| - this.check(); |
59 |
| - return super.add(msw, lsw); |
60 |
| - } |
61 |
| - |
62 |
| - public boolean add(long value) { |
63 |
| - this.check(); |
64 |
| - return super.add(LongHash.msw(value), LongHash.lsw(value)); |
65 |
| - } |
66 |
| - |
67 |
| - @Override |
68 |
| - public void clear() { |
69 |
| - this.check(); |
70 |
| - super.clear(); |
71 |
| - } |
72 |
| - |
73 |
| - @Override |
74 |
| - public boolean contains(int msw, int lsw) { |
75 |
| - this.check(); |
76 |
| - return this.contains(LongHash.toLong(msw, lsw)); |
77 |
| - } |
78 |
| - |
79 |
| - public boolean contains(long value) { |
80 |
| - this.check(); |
81 |
| - return super.contains(LongHash.msw(value), LongHash.lsw(value)); |
82 |
| - } |
83 |
| - |
84 |
| - @Override |
85 |
| - public boolean isEmpty() { |
86 |
| - this.check(); |
87 |
| - return super.isEmpty(); |
88 |
| - } |
89 |
| - |
90 |
| - @Override |
91 |
| - @SuppressWarnings("rawtypes") |
92 |
| - public Iterator iterator() { |
93 |
| - this.check(); |
94 |
| - return super.iterator(); |
95 |
| - } |
96 |
| - |
97 |
| - @Override |
98 |
| - public long[] popAll() { |
99 |
| - this.check(); |
100 |
| - return super.popAll(); |
101 |
| - } |
102 |
| - |
103 |
| - @Override |
104 |
| - public long popFirst() { |
105 |
| - this.check(); |
106 |
| - return super.popFirst(); |
107 |
| - } |
108 |
| - |
109 |
| - @Override |
110 |
| - public void remove(int msw, int lsw) { |
111 |
| - this.check(); |
112 |
| - super.remove(msw, lsw); |
113 |
| - } |
114 |
| - |
115 |
| - public void remove(long value) { |
116 |
| - this.check(); |
117 |
| - super.remove(LongHash.msw(value), LongHash.lsw(value)); |
118 |
| - } |
119 |
| - |
120 |
| - @Override |
121 |
| - public int size() { |
122 |
| - this.check(); |
123 |
| - return super.size(); |
124 |
| - } |
125 |
| - |
126 |
| - @Override |
127 |
| - public long[] toArray() { |
128 |
| - this.check(); |
129 |
| - return super.toArray(); |
130 |
| - } |
131 |
| - |
132 |
| - private void check() { |
133 |
| - if (!Thread.currentThread().equals(this.thread)) { |
134 |
| - this.plugin.list.add(new Throwable().fillInStackTrace()); |
135 |
| - } |
136 |
| - } |
137 |
| -} |
| 1 | +package org.kitteh.catcher; |
| 2 | + |
| 3 | +/* |
| 4 | + Based on CompactHashSet Copyright 2011 Ontopia Project |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +import java.lang.reflect.Field; |
| 20 | +import java.util.Iterator; |
| 21 | + |
| 22 | +import org.bukkit.craftbukkit.v1_4_5.util.LongHash; |
| 23 | +import org.bukkit.craftbukkit.v1_4_5.util.LongHashSet; |
| 24 | + |
| 25 | +public class LongHugSet extends LongHashSet { |
| 26 | + //Ah, the... |
| 27 | + public static void olBukkitSwitcharoo(LongHashSet mommy, LongHashSet baby) { |
| 28 | + try { |
| 29 | + Field fe = LongHashSet.class.getDeclaredField("freeEntries"); |
| 30 | + fe.setAccessible(true); |
| 31 | + fe.setInt(baby, fe.getInt(mommy)); |
| 32 | + fe = LongHashSet.class.getDeclaredField("elements"); |
| 33 | + fe.setAccessible(true); |
| 34 | + fe.setInt(baby, fe.getInt(mommy)); |
| 35 | + fe = LongHashSet.class.getDeclaredField("values"); |
| 36 | + fe.setAccessible(true); |
| 37 | + fe.set(baby, fe.get(mommy)); |
| 38 | + fe = LongHashSet.class.getDeclaredField("modCount"); |
| 39 | + fe.setAccessible(true); |
| 40 | + fe.setInt(baby, fe.getInt(mommy)); |
| 41 | + } catch (final Exception e) { |
| 42 | + e.printStackTrace(); |
| 43 | + } |
| 44 | + } |
| 45 | + private final Thread thread; |
| 46 | + |
| 47 | + private final Plugin plugin; |
| 48 | + |
| 49 | + public LongHugSet(LongHashSet mommy, Plugin plugin) { |
| 50 | + super(mommy.size()); |
| 51 | + |
| 52 | + this.thread = Thread.currentThread(); |
| 53 | + this.plugin = plugin; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public boolean add(int msw, int lsw) { |
| 58 | + this.check(); |
| 59 | + return super.add(msw, lsw); |
| 60 | + } |
| 61 | + |
| 62 | + public boolean add(long value) { |
| 63 | + this.check(); |
| 64 | + return super.add(LongHash.msw(value), LongHash.lsw(value)); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public void clear() { |
| 69 | + this.check(); |
| 70 | + super.clear(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public boolean contains(int msw, int lsw) { |
| 75 | + this.check(); |
| 76 | + return this.contains(LongHash.toLong(msw, lsw)); |
| 77 | + } |
| 78 | + |
| 79 | + public boolean contains(long value) { |
| 80 | + this.check(); |
| 81 | + return super.contains(LongHash.msw(value), LongHash.lsw(value)); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public boolean isEmpty() { |
| 86 | + this.check(); |
| 87 | + return super.isEmpty(); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + @SuppressWarnings("rawtypes") |
| 92 | + public Iterator iterator() { |
| 93 | + this.check(); |
| 94 | + return super.iterator(); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public long[] popAll() { |
| 99 | + this.check(); |
| 100 | + return super.popAll(); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public long popFirst() { |
| 105 | + this.check(); |
| 106 | + return super.popFirst(); |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public void remove(int msw, int lsw) { |
| 111 | + this.check(); |
| 112 | + super.remove(msw, lsw); |
| 113 | + } |
| 114 | + |
| 115 | + public void remove(long value) { |
| 116 | + this.check(); |
| 117 | + super.remove(LongHash.msw(value), LongHash.lsw(value)); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public int size() { |
| 122 | + this.check(); |
| 123 | + return super.size(); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public long[] toArray() { |
| 128 | + this.check(); |
| 129 | + return super.toArray(); |
| 130 | + } |
| 131 | + |
| 132 | + private void check() { |
| 133 | + if (!Thread.currentThread().equals(this.thread)) { |
| 134 | + this.plugin.list.add(new Throwable().fillInStackTrace()); |
| 135 | + } |
| 136 | + } |
| 137 | +} |
0 commit comments