extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/activity/CountedActivity2.java

Code
Comments
Other
Rev Date Author Line
7144 05 May 23 nicklas 1 package net.sf.basedb.reggie.activity;
7144 05 May 23 nicklas 2
7144 05 May 23 nicklas 3
7144 05 May 23 nicklas 4 /**
7144 05 May 23 nicklas 5   An activity entry that contains two counter that can be merged with
7144 05 May 23 nicklas 6   other activities of the same ActivityDef and name.
7144 05 May 23 nicklas 7   The message is created from the message template in the ActivityDef
7144 05 May 23 nicklas 8   where the string {COUNT} and {COUNT2} is replaced with the current value 
7144 05 May 23 nicklas 9   of the counters.
7144 05 May 23 nicklas 10   
7144 05 May 23 nicklas 11   Merging is done by adding the counters together.
7144 05 May 23 nicklas 12   
7144 05 May 23 nicklas 13   @author nicklas
7144 05 May 23 nicklas 14   @since 4.47
7144 05 May 23 nicklas 15 */
7144 05 May 23 nicklas 16 public class CountedActivity2
7144 05 May 23 nicklas 17   extends CountedActivity
7144 05 May 23 nicklas 18 {
7144 05 May 23 nicklas 19
7144 05 May 23 nicklas 20   private static final long serialVersionUID = -3743595567018151463L;
7144 05 May 23 nicklas 21
7144 05 May 23 nicklas 22   private int count2;
7144 05 May 23 nicklas 23   
7144 05 May 23 nicklas 24   /**
7144 05 May 23 nicklas 25     Creates an activity event for the given activity without a name.
7144 05 May 23 nicklas 26     This activity can be merged with other activities having the
7144 05 May 23 nicklas 27     same definition and no name.
7144 05 May 23 nicklas 28   */
7144 05 May 23 nicklas 29   public CountedActivity2(ActivityDef activity, int count, int count2, String user, String project) 
7144 05 May 23 nicklas 30   {
7144 05 May 23 nicklas 31     this(activity, null, count, count2, user, project);
7144 05 May 23 nicklas 32   }
7144 05 May 23 nicklas 33   
7144 05 May 23 nicklas 34   /**
7144 05 May 23 nicklas 35     Creates an activity event for the given activity with a name.
7144 05 May 23 nicklas 36     This activity can be merged with other activities having the
7144 05 May 23 nicklas 37     same name and definition.
7144 05 May 23 nicklas 38   */
7144 05 May 23 nicklas 39   public CountedActivity2(ActivityDef activity, String name, int count, int count2, String user, String project) 
7144 05 May 23 nicklas 40   {
7144 05 May 23 nicklas 41     super(activity, name, count, user, project);
7144 05 May 23 nicklas 42     this.count2 = count2;
7144 05 May 23 nicklas 43   }
7144 05 May 23 nicklas 44   
7144 05 May 23 nicklas 45   @Override
7144 05 May 23 nicklas 46   public String getMessage() 
7144 05 May 23 nicklas 47   {
7144 05 May 23 nicklas 48     return super.getMessage().replace("{COUNT2}", Integer.toString(count2));
7144 05 May 23 nicklas 49   }
7144 05 May 23 nicklas 50   
7144 05 May 23 nicklas 51   /**
7144 05 May 23 nicklas 52     Merge with the other activity if it is a CountedActivity and
7144 05 May 23 nicklas 53     it has the same 'activity', 'name', 'project' and 'user' value.
7144 05 May 23 nicklas 54     If so, the counter of this activity is increased with the value of the counter
7144 05 May 23 nicklas 55     from the other activity. The other activity is not modified.
7144 05 May 23 nicklas 56   */
7144 05 May 23 nicklas 57   @Override
7144 05 May 23 nicklas 58   public boolean merge(ActivityEntry other)
7144 05 May 23 nicklas 59   {
7144 05 May 23 nicklas 60     if (this == other) return true; // Should not happen, but if it does we should not increase the count
7144 05 May 23 nicklas 61     if (!super.merge(other)) return false;
7144 05 May 23 nicklas 62     
7144 05 May 23 nicklas 63     if (!(other instanceof CountedActivity2)) return false;
7144 05 May 23 nicklas 64     CountedActivity2 merge = (CountedActivity2)other;
7144 05 May 23 nicklas 65     
7144 05 May 23 nicklas 66     this.count2 += merge.count2;
7144 05 May 23 nicklas 67     return true;
7144 05 May 23 nicklas 68   }
7144 05 May 23 nicklas 69   
7144 05 May 23 nicklas 70 }