/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ package org.opensolaris.os.dtrace; import java.io.*; import java.beans.*; import java.util.*; /** * A formatted string generated by the DTrace {@code printf()} action. *
* Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
*
* @author Tom Erickson
*/
public final class PrintfRecord implements Record, Serializable,
Comparable
* generates a {@code PrintfRecord} with a record count of two.
*
* @return the number of unformatted elements passed to the DTrace
* {@code printf()} action that generated this record.
*/
public int
getRecordCount()
{
return records.size();
}
/**
* Gets the unformatted element passed to the DTrace {@code
* printf()} action at the given offset in the {@code printf()}
* argument list after the format string, starting at offset zero
* for the first unformatted element.
*
* @return non-null record representing the unformatted {@code
* printf()} element at the given index (using the same order that
* they appear in the {@code printf()} argument list)
* @throws ArrayIndexOutOfBoundsException if the given index is
* out of range (index < 0 || index >= getRecordCount())
*/
public ValueRecord
getRecord(int i)
{
return records.get(i);
}
/**
* Compares the specified object with this {@code PrintfRecord} for
* equality. Returns {@code true} if and only if the specified
* object is also a {@code PrintfRecord} and both records have the
* same formatted string and underlying data elements.
*
* @return {@code true} if and only if the specified object is also
* a {@code PrintfRecord} and both the formatted strings and
* the underlying data elements of both records are equal
*/
@Override
public boolean
equals(Object o)
{
if (o instanceof PrintfRecord) {
PrintfRecord r = (PrintfRecord)o;
return (records.equals(r.records) &&
formattedString.equals(r.formattedString));
}
return false;
}
/**
* Overridden to ensure that equal instances have equal hash codes.
*/
@Override
public int
hashCode()
{
int hash = 17;
hash = (37 * hash) + records.hashCode();
hash = (37 * hash) + formattedString.hashCode();
return hash;
}
/**
* Compares the formatted string value of this record with that of
* the given record. Note that ordering {@code printf} records by
* their string values is incompatible with {@link #equals(Object o)
* equals()}, which also checks the underlying data elements for
* equality.
*
* @return a negative number, 0, or a positive number as this
* record's formatted string is lexicographically less than, equal
* to, or greater than the given record's formatted string
*/
public int
compareTo(PrintfRecord r)
{
return formattedString.compareTo(r.formattedString);
}
private void
readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException
{
s.defaultReadObject();
// Defensively copy record list before validating
if (records == null) {
throw new InvalidObjectException("record list is null");
}
List
* printf("%s %d\n", "cat", 9);
*