Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) OSGi Alliance (2002, 2013). All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.osgi.util.measurement;

Groups a state name, value and timestamp.

The state itself is represented as an integer and the time is measured in milliseconds since midnight, January 1, 1970 UTC.

A State object is immutable so that it may be easily shared.

Author(s):
$Id: 415613f3925b2d69f27517c1ef2fc389507b62dc $
Immutable:
 
 public class State {
 	private final int		value;
 	private final long		time;
 	private final String	name;

Create a new State object.

Parameters:
value The value of the state.
name The name of the state.
time The time measured in milliseconds since midnight, January 1, 1970 UTC.
 
 	public State(int valueString namelong time) {
 		this. = value;
 		this. = name;
 		this. = time;
 	}

Create a new State object with a time of 0.

Parameters:
value The value of the state.
name The name of the state.
 
 	public State(int valueString name) {
 		this(valuename, 0);
 	}

Returns the value of this State.

Returns:
The value of this State object.
 
 	public final int getValue() {
 		return ;
 	}

Returns the time with which this State was created.

Returns:
The time with which this State was created. The time is measured in milliseconds since midnight, January 1, 1970 UTC.
 
 	public final long getTime() {
 		return ;
 	}

Returns the name of this State.

Returns:
The name of this State object.
 
 	public final String getName() {
 		return ;
 	}

Returns a String object representing this object.

Returns:
a String object representing this object.
 
 	public String toString() {
 		StringBuffer sb = new StringBuffer();
 		sb.append();
 		if ( != null) {
 			sb.append(" \"");
 			sb.append();
			sb.append("\"");
		}
		return sb.toString();
	}

Returns a hash code value for this object.

Returns:
A hash code value for this object.
	public int hashCode() {
		int hash = 31 * 17 + ;
		if ( != null) {
			hash = 31 * hash + .hashCode();
		}
		return hash;
	}

Return whether the specified object is equal to this object. Two State objects are equal if they have same value and name.

Parameters:
obj The object to compare with this object.
Returns:
true if this object is equal to the specified object; false otherwise.
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof State)) {
			return false;
		}
		State that = (Stateobj;
		if ( != that.value) {
			return false;
		}
		if ( == that.name) {
			return true;
		}
		if ( == null) {
			return false;
		}
		return .equals(that.name);
	}
New to GrepCode? Check out our FAQ X