001package org.javasimon; 002 003import org.javasimon.utils.SimonUtils; 004 005import java.io.Serializable; 006 007/** 008 * Sample contains all relevant values of the Simon that are obtained by the 009 * {@link org.javasimon.Simon#sample()} and {@link org.javasimon.Simon#sampleIncrement(Object)} methods. 010 * Returned object contains consistent set of Simon values as both operations are synchronized. 011 * However Sample is a Java Bean and it can be modified afterwards so no consistency is guaranteed 012 * when the object is used in an inappropriate context. As a Java Bean object can be 013 * used directly as the data transfer object without need to create another DTO with the same data. 014 * Sample generally doesn't have any behavior. 015 * 016 * @author <a href="mailto:virgo47@gmail.com">Richard "Virgo" Richter</a> 017 */ 018public abstract class Sample implements Serializable { 019 020 private String name; 021 private String note; 022 private long firstUsage; 023 private long lastUsage; 024 025 /** 026 * Name of the sampled Simon. 027 * 028 * @return Simon's name 029 */ 030 public final String getName() { 031 return name; 032 } 033 034 /** 035 * Sets the name of the sampled Simon - mostly not used directly. 036 * 037 * @param name Simon's name 038 */ 039 public final void setName(String name) { 040 this.name = name; 041 } 042 043 /** 044 * Note from the sampled Simon. 045 * 046 * @return Simon's note 047 */ 048 public final String getNote() { 049 return note; 050 } 051 052 /** 053 * Sets the note for the sample, typically note from the sampled Simon. 054 * 055 * @param note Simon's note 056 */ 057 public final void setNote(String note) { 058 this.note = note; 059 } 060 061 /** 062 * Timestamp of the first usage from the sampled Simon. 063 * 064 * @return Simon's first usage timestamp 065 */ 066 public long getFirstUsage() { 067 return firstUsage; 068 } 069 070 /** 071 * Sets the timestamp of the first usage from the sampled Simon. 072 * 073 * @param firstUsage Simon's first usage timestamp 074 */ 075 public void setFirstUsage(long firstUsage) { 076 this.firstUsage = firstUsage; 077 } 078 079 /** 080 * Timestamp of the last usage from the sampled Simon. 081 * 082 * @return Simon's last usage timestamp 083 */ 084 public long getLastUsage() { 085 return lastUsage; 086 } 087 088 /** 089 * Sets the timestamp of the last usage from the sampled Simon. 090 * 091 * @param lastUsage Simon's last usage timestamp 092 */ 093 public void setLastUsage(long lastUsage) { 094 this.lastUsage = lastUsage; 095 } 096 097 // common part of the toString method 098 void toStringCommon(StringBuilder sb) { 099 sb.append(", firstUsage=").append(SimonUtils.presentTimestamp(getFirstUsage())); 100 sb.append(", lastUsage=").append(SimonUtils.presentTimestamp(getLastUsage())); 101 sb.append(", note=").append(getNote()); 102 sb.append('}'); 103 } 104 105 /** Similar to {@link org.javasimon.AbstractSimon#toString()} except for the state missing in the output. */ 106 public abstract String simonToString(); 107 108 String simonToStringCommon() { 109 return " [" + name + (getNote() != null && getNote().length() != 0 ? " \"" + getNote() + "\"]" : "]"); 110 } 111}