1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * ident "%Z%%M% %I% %E% SMI" 27 */ 28 package org.opensolaris.os.dtrace; 29 30 import java.io.Serializable; 31 import java.beans.*; 32 33 /** 34 * A numeric value generated by a D aggregating action such as {@code 35 * count()} or {@code sum()}. 36 * <p> 37 * Immutable. 38 * 39 * @author Tom Erickson 40 */ 41 abstract class AbstractAggregationValue 42 implements AggregationValue, Serializable 43 { 44 static final long serialVersionUID = 2340811719178724026L; 45 46 /** @serial */ 47 private final Number value; 48 49 public 50 AbstractAggregationValue(long v) 51 { 52 value = new Long(v); 53 } 54 55 public 56 AbstractAggregationValue(double v) 57 { 58 value = new Double(v); 59 } 60 61 public Number 62 getValue() 63 { 64 return value; 65 } 66 67 /** 68 * Compares the specified object with this aggregation value for 69 * equality. Defines equality as having the same type and the same 70 * numeric value. 71 * 72 * @return {@code true} if and only if the specified object is an 73 * aggregation value of the same {@code Class} as this value, and 74 * both values return equal numbers from {@link #getValue()}. 75 */ 76 public boolean 77 equals(Object o) 78 { 79 if (o instanceof AbstractAggregationValue) { 80 AbstractAggregationValue v = (AbstractAggregationValue)o; 81 return (value.equals(v.value) && 82 (getClass() == v.getClass())); 83 } 84 return false; 85 } 86 87 /** 88 * Overridden to ensure that equal instances have equal hash codes. 89 */ 90 @Override 91 public int 92 hashCode() 93 { 94 return value.hashCode(); 95 } 96 97 /** 98 * Gets the string representation of {@link #getValue()}. 99 * 100 * @return the string representation of {@link #getValue()} returned 101 * by {@link Object#toString()} 102 */ 103 public String 104 toString() 105 { 106 return value.toString(); 107 } 108 } 109