View Javadoc

1   /*
2    * #%L
3    * Bitrepository Service
4    * %%
5    * Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 2.1 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package org.bitrepository.service.workflow;
23  
24  /**
25   * Class to identify a workflow instance, based on the collection it belongs to and the workflow name/type 
26   */
27  public class JobID {
28      private final String collectionID;
29      private final String workflowName;
30      
31      public JobID(String workflowName, String collectionID) {
32          this.collectionID = collectionID;
33          this.workflowName = workflowName;
34      }
35      
36      public String getWorkflowName() {
37          return workflowName;
38      }
39      
40      public String getCollectionID() {
41          return collectionID;
42      }
43  
44      @Override
45      public int hashCode() {
46          final int prime = 31;
47          int result = 1;
48          result = prime * result
49                  + ((collectionID == null) ? 0 : collectionID.hashCode());
50          result = prime * result
51                  + ((workflowName == null) ? 0 : workflowName.hashCode());
52          return result;
53      }
54  
55      @Override
56      public boolean equals(Object obj) {
57          if (this == obj)
58              return true;
59          if (obj == null)
60              return false;
61          if (getClass() != obj.getClass())
62              return false;
63          JobID other = (JobID) obj;
64          if (collectionID == null) {
65              if (other.collectionID != null)
66                  return false;
67          } else if (!collectionID.equals(other.collectionID))
68              return false;
69          if (workflowName == null) {
70              if (other.workflowName != null)
71                  return false;
72          } else if (!workflowName.equals(other.workflowName))
73              return false;
74          return true;
75      }
76      
77      @Override 
78      public String toString() {
79          return workflowName + "-" + collectionID;
80      }
81  }