1 37 38 package net.sourceforge.cruisecontrol; 39 40 import java.util.Calendar ; 41 import java.util.Date ; 42 import java.util.Map ; 43 44 import net.sourceforge.cruisecontrol.util.PerDayScheduleItem; 45 import net.sourceforge.cruisecontrol.util.ValidationHelper; 46 47 import org.jdom.Element; 48 49 public abstract class Builder extends PerDayScheduleItem implements Comparable { 50 51 private int time = NOT_SET; 52 private int multiple = 1; 53 private boolean multipleSet = false; 54 private String group = "default"; 55 56 public abstract Element build(Map properties) throws CruiseControlException; 58 59 public abstract Element buildWithTarget(Map properties, String target) throws CruiseControlException; 60 61 public void validate() throws CruiseControlException { 62 boolean timeSet = time != NOT_SET; 63 64 ValidationHelper.assertFalse(timeSet && multipleSet, 65 "Only one of 'time' or 'multiple' are allowed on builders."); 66 } 67 68 public int getTime() { 69 return time; 70 } 71 72 76 public void setTime(String timeString) { 77 time = Integer.parseInt(timeString); 78 } 79 80 84 public void setMultiple(int multiple) { 85 multipleSet = multiple != NOT_SET; 86 this.multiple = multiple; 87 } 88 89 public int getMultiple() { 90 boolean timeSet = time != NOT_SET; 91 if (timeSet && !multipleSet) { 92 return NOT_SET; 93 } 94 return multiple; 95 } 96 97 public String getGroup() { 98 return group; 99 } 100 101 public void setGroup(String group) { 102 this.group = group; 103 } 104 105 108 public boolean isValidDay(Date now) { 109 if (getDay() < 0) { 110 return true; 111 } 112 113 Calendar cal = Calendar.getInstance(); 114 cal.setTime(now); 115 return cal.get(Calendar.DAY_OF_WEEK) == getDay(); 116 } 117 118 122 public int compareTo(Object o) { 123 Builder builder = (Builder) o; 124 Integer integer = new Integer (multiple); 125 Integer integer2 = new Integer (builder.getMultiple()); 126 return integer2.compareTo(integer); } 128 129 } 130 | Popular Tags |