History

Added GridSolutionsFramework.sln to source control.

StephenCWills committed 14 years ago

Commit c5f7ca6No parent (first commit)915 files · +335125 −-73Browse files

Showing the changes to Source/Libraries/TSFJavaLibrary/src/org/gpa/tsf/MeasurementKey.java (1 of 915 files). Show all

Unified · Split

Source/Libraries/TSFJavaLibrary/src/org/gpa/tsf/MeasurementKey.java+143−0
@@ -0,0 +1,143 @@
1+//******************************************************************************************************
2+// MeasurementKey.java - Gbtc
3+//
4+// Copyright � 2010, Grid Protection Alliance. All Rights Reserved.
5+//
6+// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7+// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8+// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
9+// not use this file except in compliance with the License. You may obtain a copy of the License at:
10+//
11+// http://www.opensource.org/licenses/eclipse-1.0.php
12+//
13+// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14+// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15+// License for the specific language governing permissions and limitations.
16+//
17+// Code Modification History:
18+// ----------------------------------------------------------------------------------------------------
19+// 04/12/2012 - Stephen C. Wills
20+// Generated original version of source code.
21+//
22+//******************************************************************************************************
23+
24+package org.gpa.tsf;
25+
26+import java.util.UUID;
27+
28+import org.gpa.tsf.util.StringExtensions;
29+
30+/**
31+ * Represents a grouping of a measurement's globally unique identifier
32+ * and the alternate human-readable identifier {@code SOURCE:ID}.
33+ * @see Measurement
34+ */
35+public class MeasurementKey
36+{
37+ private UUID m_signalId;
38+ private String m_source;
39+ private int m_id;
40+
41+ /**
42+ * Constructs a measurement key by grouping the given parameters.
43+ *
44+ * @param signalId the measurement's globally unique identifier
45+ * @param source the measurement's source
46+ * @param id the measurement's ID
47+ * @throws IllegalArgumentException if the given {@code signalID} is {@code null}
48+ * or the given {@code source} is {@code null} or empty
49+ */
50+ public MeasurementKey(UUID signalId, String source, int id)
51+ {
52+ if (signalId == null)
53+ throw new IllegalArgumentException("signalId must not be null");
54+
55+ if (StringExtensions.isNullOrWhitespace(source))
56+ throw new IllegalArgumentException("source must not be null or empty");
57+
58+ m_signalId = signalId;
59+ m_source = source;
60+ m_id = id;
61+ }
62+
63+ /**
64+ * Gets the globally unique identifier of the measurement.
65+ *
66+ * @return the measurement's globally unique identifier
67+ * @see Measurement#getSignalId()
68+ */
69+ public UUID getSignalId()
70+ {
71+ return m_signalId;
72+ }
73+
74+ /**
75+ * Gets the source of the measurement.
76+ *
77+ * @return the measurement's source
78+ * @see Measurement#getSource()
79+ */
80+ public String getSource()
81+ {
82+ return m_source;
83+ }
84+
85+ /**
86+ * Gets the simple numeric identifier of the measurement.
87+ *
88+ * @return the measurement's simple numeric identifier
89+ * @see Measurement#getId()
90+ */
91+ public int getId()
92+ {
93+ return m_id;
94+ }
95+
96+ /**
97+ * Compares this object to the specified object. The result is
98+ * true if and only if the argument is not {@code null} and is
99+ * a {@code MeasurementKey} that contains the same signal ID as
100+ * this object.
101+ */
102+ @Override
103+ public boolean equals(Object obj)
104+ {
105+ MeasurementKey key;
106+
107+ if(obj == null || !(obj instanceof MeasurementKey))
108+ return false;
109+
110+ key = (MeasurementKey)obj;
111+ return m_signalId.equals(key.m_signalId);
112+ }
113+
114+ /**
115+ * Returns a hash code for this {@code MeasurementKey}.
116+ */
117+ @Override
118+ public int hashCode()
119+ {
120+ return m_signalId.hashCode();
121+ }
122+
123+ /**
124+ * Creates a measurement key for the given measurement, if it has one.
125+ * This method returns null if either the measurement's signal ID
126+ * is null or the source is null or empty.
127+ *
128+ * @param measurement the measurement whose key is to be created
129+ * @return the key for the given measurement
130+ */
131+ public static MeasurementKey getKey(Measurement measurement)
132+ {
133+ UUID signalId = measurement.getSignalId();
134+ String source = measurement.getSource();
135+ int id = measurement.getId();
136+ MeasurementKey key = null;
137+
138+ if (signalId != null && StringExtensions.isNullOrWhitespace(source))
139+ key = new MeasurementKey(signalId, source, id);
140+
141+ return key;
142+ }
143+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t