Remove exported everywhere.
[SquirrelJME.git] / modules / tool-classfile / src / main / java / net / multiphasicapps / classfile / InstructionAddressRange.java
blobf1efd9d78bf714ec798493536b729517b40293b7
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package net.multiphasicapps.classfile;
12 import java.lang.ref.Reference;
13 import java.lang.ref.WeakReference;
15 /**
16 * This represents a range of instruction addresses, the start is inclusive
17 * and the end is exclusive.
19 * @since 2019/03/21
21 public final class InstructionAddressRange
22 implements Comparable<InstructionAddressRange>
24 /** The start address. */
25 protected final int start;
27 /** The end address. */
28 protected final int end;
30 /** String representation. */
31 private Reference<String> _string;
33 /**
34 * Initializes the address range.
36 * @param __s The start address.
37 * @param __e The end address.
38 * @since 2019/03/21
40 public InstructionAddressRange(int __s, int __e)
42 this.start = __s;
43 this.end = __e;
46 /**
47 * {@inheritDoc}
48 * @since 2019/03/21
50 @Override
51 public final int compareTo(InstructionAddressRange __b)
53 int rv = this.start - __b.start;
54 if (rv != 0)
55 return rv;
57 return this.end - __b.end;
60 /**
61 * {@inheritDoc}
62 * @since 2019/03/21
64 @Override
65 public final boolean equals(Object __o)
67 if (__o == this)
68 return true;
70 if (!(__o instanceof InstructionAddressRange))
71 return false;
73 InstructionAddressRange o = (InstructionAddressRange)__o;
74 return this.start == o.start &&
75 this.end == o.end;
78 /**
79 * {@inheritDoc}
80 * @since 2019/03/21
82 @Override
83 public final int hashCode()
85 return this.start ^ (~this.end);
88 /**
89 * Checks if the given address is in the range of this range.
91 * @param __pc The address to check.
92 * @return If the address is in range.
93 * @since 2019/03/22
95 public final boolean inRange(int __pc)
97 return __pc >= this.start && __pc < this.end;
101 * {@inheritDoc}
102 * @since 2019/03/21
104 @Override
105 public final String toString()
107 Reference<String> ref = this._string;
108 String rv;
110 if (ref == null || null == (rv = ref.get()))
111 this._string = new WeakReference<>((rv = "@[" + this.start +
112 "-" + this.end + ")"));
114 return rv;