001: /*
002: * $Id: Enlistment.java 503 2005-08-23 06:04:12Z hengels $
003: * (c) Copyright 2004 con:cern development team.
004: *
005: * This file is part of con:cern (http://concern.sf.net).
006: *
007: * con:cern is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU Lesser General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014: package org.concern.controller;
015:
016: import java.sql.Timestamp;
017: import java.util.*;
018:
019: /**
020: * @hibernate.query name="enlistment.byActivity"
021: * query="FROM org.concern.controller.Enlistment AS enlistment WHERE enlistment.activity = :activity"
022: */
023: public class Enlistment implements Comparable {
024: private Integer id;
025:
026: private long timeout;
027: private String command;
028: private String activity;
029: private int trials;
030: private String lockedBy;
031: private Timestamp lockedUntil;
032: private Set assignments;
033:
034: public Enlistment() {
035: }
036:
037: public Enlistment(String command, long timeout) {
038: this .command = command;
039: this .activity = "-";
040: this .timeout = timeout;
041: }
042:
043: public Enlistment(String command, String activity, long timeout) {
044: this .command = command;
045: this .activity = activity;
046: this .timeout = timeout;
047: }
048:
049: public Integer getId() {
050: return id;
051: }
052:
053: public void setId(Integer id) {
054: this .id = id;
055: }
056:
057: public long getTimeout() {
058: return timeout;
059: }
060:
061: public void setTimeout(long timeout) {
062: this .timeout = timeout;
063: }
064:
065: public String getCommand() {
066: return command;
067: }
068:
069: public void setCommand(String command) {
070: this .command = command;
071: }
072:
073: public String getActivity() {
074: return activity;
075: }
076:
077: public void setActivity(String activity) {
078: this .activity = activity;
079: }
080:
081: public int getTrials() {
082: return trials;
083: }
084:
085: public void setTrials(int trials) {
086: this .trials = trials;
087: }
088:
089: public String getLockedBy() {
090: return lockedBy;
091: }
092:
093: public void setLockedBy(String lockedBy) {
094: this .lockedBy = lockedBy;
095: }
096:
097: public Timestamp getLockedUntil() {
098: return lockedUntil;
099: }
100:
101: public void setLockedUntil(Timestamp lockedUntil) {
102: this .lockedUntil = lockedUntil;
103: }
104:
105: public Set getAssignments() {
106: if (assignments == null)
107: assignments = new HashSet();
108: return assignments;
109: }
110:
111: public void setAssignments(Set assignments) {
112: this .assignments = assignments;
113: }
114:
115: public String toString() {
116: return command + ": " + activity + " " + timeout;
117: }
118:
119: public int compareTo(Object o) {
120: Enlistment enlistment = (Enlistment) o;
121: long diff = timeout - enlistment.timeout;
122: if (diff != 0)
123: return diff < 0 ? -1 : 1;
124: diff = command.compareTo(enlistment.command);
125: if (diff != 0)
126: return (int) diff;
127: diff = activity.compareTo(enlistment.activity);
128: if (diff != 0)
129: return (int) diff;
130: diff = trials - enlistment.trials;
131: return (int) diff;
132: }
133:
134: public boolean equals(Object o) {
135: if (this == o)
136: return true;
137: if (!(o instanceof Enlistment))
138: return false;
139:
140: final Enlistment enlistment = (Enlistment) o;
141:
142: if (timeout != enlistment.timeout)
143: return false;
144: if (trials != enlistment.trials)
145: return false;
146: if (!activity.equals(enlistment.activity))
147: return false;
148: if (!command.equals(enlistment.command))
149: return false;
150:
151: return true;
152: }
153:
154: public int hashCode() {
155: int result;
156: result = (int) (timeout ^ (timeout >>> 32));
157: result = 29 * result + command.hashCode();
158: result = 29 * result + activity.hashCode();
159: result = 29 * result + trials;
160: return result;
161: }
162: }
|