author | sspitsyn |
Mon, 22 Jan 2018 14:14:26 -0800 | |
changeset 48803 | 6738bf669314 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
48803
6738bf669314
8194143: remove unneeded casts in LocationImpl and MirrorImpl classes
sspitsyn
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.jdi; |
|
27 |
||
28 |
import java.util.Collection; |
|
29 |
||
45714 | 30 |
import com.sun.jdi.Mirror; |
31 |
import com.sun.jdi.VMMismatchException; |
|
32 |
import com.sun.jdi.VirtualMachine; |
|
33 |
||
2 | 34 |
abstract class MirrorImpl extends Object implements Mirror { |
35 |
||
36 |
protected VirtualMachineImpl vm; |
|
37 |
||
38 |
MirrorImpl(VirtualMachine aVm) { |
|
39 |
super(); |
|
40 |
||
41 |
// Yes, its a bit of a hack. But by doing it this |
|
42 |
// way, this is the only place we have to change |
|
43 |
// typing to substitute a new impl. |
|
44 |
vm = (VirtualMachineImpl)aVm; |
|
45 |
} |
|
46 |
||
47 |
public VirtualMachine virtualMachine() { |
|
48 |
return vm; |
|
49 |
} |
|
50 |
||
51 |
public boolean equals(Object obj) { |
|
52 |
if ((obj != null) && (obj instanceof Mirror)) { |
|
53 |
Mirror other = (Mirror)obj; |
|
54 |
return vm.equals(other.virtualMachine()); |
|
55 |
} else { |
|
56 |
return false; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
public int hashCode() { |
|
61 |
return vm.hashCode(); |
|
62 |
} |
|
63 |
||
64 |
/** |
|
65 |
* Throw NullPointerException on null mirror. |
|
66 |
* Throw VMMismatchException on wrong VM. |
|
67 |
*/ |
|
68 |
void validateMirror(Mirror mirror) { |
|
69 |
if (!vm.equals(mirror.virtualMachine())) { |
|
70 |
throw new VMMismatchException(mirror.toString()); |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* Allow null mirror. |
|
76 |
* Throw VMMismatchException on wrong VM. |
|
77 |
*/ |
|
78 |
void validateMirrorOrNull(Mirror mirror) { |
|
79 |
if ((mirror != null) && !vm.equals(mirror.virtualMachine())) { |
|
80 |
throw new VMMismatchException(mirror.toString()); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Throw NullPointerException on null mirrors. |
|
86 |
* Throw VMMismatchException on wrong VM. |
|
87 |
*/ |
|
11277 | 88 |
void validateMirrors(Collection<? extends Mirror> mirrors) { |
48803
6738bf669314
8194143: remove unneeded casts in LocationImpl and MirrorImpl classes
sspitsyn
parents:
47216
diff
changeset
|
89 |
for (Mirror mirror : mirrors) { |
6738bf669314
8194143: remove unneeded casts in LocationImpl and MirrorImpl classes
sspitsyn
parents:
47216
diff
changeset
|
90 |
validateMirror(mirror); |
2 | 91 |
} |
92 |
} |
|
45714 | 93 |
|
2 | 94 |
/** |
95 |
* Allow null mirrors. |
|
96 |
* Throw VMMismatchException on wrong VM. |
|
97 |
*/ |
|
11277 | 98 |
void validateMirrorsOrNulls(Collection<? extends Mirror> mirrors) { |
48803
6738bf669314
8194143: remove unneeded casts in LocationImpl and MirrorImpl classes
sspitsyn
parents:
47216
diff
changeset
|
99 |
for (Mirror mirror : mirrors) { |
6738bf669314
8194143: remove unneeded casts in LocationImpl and MirrorImpl classes
sspitsyn
parents:
47216
diff
changeset
|
100 |
validateMirrorOrNull(mirror); |
2 | 101 |
} |
102 |
} |
|
103 |
} |