Indentations break the feed.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / suite / SuiteIdentifier.java
blobcea5251ed8a32bb9a0bac14a238a4e1c1428ce6b
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 Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.jvm.suite;
12 import java.lang.ref.Reference;
13 import java.lang.ref.WeakReference;
15 /**
16 * This is the identity for a midlet suite which contains a name, vendor,
17 * and version.
19 * @since 2016/10/12
21 public final class SuiteIdentifier
22 implements Comparable<SuiteIdentifier>
24 /** The suite name. */
25 protected final SuiteName name;
27 /** The suite vendor. */
28 protected final SuiteVendor vendor;
30 /** The suite version. */
31 protected final SuiteVersion version;
33 /** String representation. */
34 private Reference<String> _string;
36 /**
37 * Initializes the suite identifier.
39 * @param __name The name of the suite.
40 * @param __ven The vendor of the suite.
41 * @param __ver The version of the suite.
42 * @throws NullPointerException On null arguments.
43 * @since 2017/02/22
45 public SuiteIdentifier(SuiteName __name, SuiteVendor __ven,
46 SuiteVersion __ver)
47 throws NullPointerException
49 this(__ven, __name, __ver);
52 /**
53 * Initializes the suite identifier.
55 * @param __ven The vendor of the suite.
56 * @param __name The name of the suite.
57 * @param __ver The version of the suite.
58 * @throws NullPointerException On null arguments.
59 * @since 2016/10/12
61 public SuiteIdentifier(SuiteVendor __ven, SuiteName __name,
62 SuiteVersion __ver)
63 throws NullPointerException
65 // Check
66 if (__ven == null || __name == null || __ver == null)
67 throw new NullPointerException("NARG");
69 // Set
70 this.name = __name;
71 this.vendor = __ven;
72 this.version = __ver;
75 /**
76 * {@inheritDoc}
77 * @since 2016/10/12
79 @Override
80 public int compareTo(SuiteIdentifier __o)
82 if (this == __o)
83 return 0;
85 // Compare name
86 int rv = this.name.compareTo(__o.name);
87 if (rv != 0)
88 return rv;
90 // Then vendor
91 rv = this.vendor.compareTo(__o.vendor);
92 if (rv != 0)
93 return rv;
95 // Then the version last
96 return this.version.compareTo(__o.version);
99 /**
100 * {@inheritDoc}
101 * @since 2016/10/12
103 @Override
104 public boolean equals(Object __o)
106 if (this == __o)
107 return true;
109 // Check
110 if (!(__o instanceof SuiteIdentifier))
111 return false;
113 return 0 == (this.compareTo((SuiteIdentifier)__o));
117 * {@inheritDoc}
118 * @since 2016/10/12
120 @Override
121 public int hashCode()
123 return this.name.hashCode() ^ this.vendor.hashCode() ^
124 this.version.hashCode();
128 * Returns the suite name.
130 * @return The suite name.
131 * @since 2016/10/12
133 public SuiteName name()
135 return this.name;
139 * {@inheritDoc}
140 * @since 2016/10/12
142 @Override
143 public String toString()
145 // Get
146 Reference<String> ref = this._string;
147 String rv;
149 // Cache?
150 if (ref == null || null == (rv = ref.get()))
151 this._string = new WeakReference<>((rv = this.vendor + ";" +
152 this.name + ";" + this.version));
154 // Return it
155 return rv;
159 * Returns the suite vendor.
161 * @return The suite vendor.
162 * @since 2016/10/12
164 public SuiteVendor vendor()
166 return this.vendor;
170 * Returns the suite version.
172 * @return The suite version.
173 * @since 2016/10/12
175 public SuiteVersion version()
177 return this.version;