Skip to contentMethod: getPath()
      1: package model;
2: 
3: import java.nio.file.Paths;
4: 
5: import model.assignment.AssignmentFile;
6: import scanner.ScannerConstants;
7: 
8: /**
9:  * Represents a configured package.
10:  */
11: public class ConfiguredPackage {
12: 
13:         /**
14:          * The associated RouterConfiguration.
15:          */
16:         private final RouterConfiguration rc;
17:         /**
18:          * The associated Package.
19:          */
20:         private final Package pkg;
21:         /**
22:          * The assignment(config) file that is associated with the package.
23:          */
24:         private AssignmentFile assignmentFile;
25: 
26:         /**
27:          * Constructor.
28:          * 
29:          * @param rc
30:          *            The RouterConfiguration.
31:          * @param pkg
32:          *            The package.
33:          */
34:         public ConfiguredPackage(final RouterConfiguration rc, final Package pkg) {
35:                 this.rc = rc;
36:                 this.pkg = pkg;
37:                 this.assignmentFile = new AssignmentFile();
38:         }
39: 
40:         /**
41:          * Constructor.
42:          * 
43:          * @param rc
44:          *            The RouterConfiguration.
45:          * @param pkg
46:          *            The package.
47:          * @param file
48:          *            The assignment file.
49:          */
50:         public ConfiguredPackage(final RouterConfiguration rc, final Package pkg,
51:                         final AssignmentFile file) {
52:                 this.rc = rc;
53:                 this.pkg = pkg;
54:                 this.assignmentFile = file;
55:         }
56: 
57:         @Override
58:         public boolean equals(final Object obj) {
59:                 return obj instanceof ConfiguredPackage
60:                                 && ((ConfiguredPackage) obj).getRouterConfiguration()
61:                                                 .equals(this.getRouterConfiguration())
62:                                 && ((ConfiguredPackage) obj).getPackage().equals(this.getPackage())
63:                                 && ((ConfiguredPackage) obj).getAssignmentFile().equals(this.getAssignmentFile());
64:         }
65: 
66:         @Override
67:         public int hashCode() {
68:                 return this.pkg.hashCode() + this.getAssignmentFile().hashCode();
69:         }
70: 
71:         @Override
72:         public String toString() {
73:                 return this.pkg.toString() + ScannerConstants.COMMASPACE + this.assignmentFile;
74:         }
75: 
76:         /**
77:          * @return the path to the configured package.
78:          */
79:         public String getPath() {
80:                 return Paths.get(this.rc.getPath(), this.getName() + ".txt").toString();
81:         }
82: 
83:         /**
84:          * @return the associated RouterConfiguration
85:          */
86:         public RouterConfiguration getRouterConfiguration() {
87:                 return this.rc;
88:         }
89: 
90:         /**
91:          * @return the associated package.
92:          */
93:         public Package getPackage() {
94:                 return this.pkg;
95:         }
96: 
97:         /**
98:          * @return the package name.
99:          */
100:         public String getName() {
101:                 return this.pkg.getName();
102:         }
103: 
104:         /**
105:          * Returns the field assignmentFile. No side effects.
106:          * 
107:          * @return this.assignmentFile
108:          */
109:         public AssignmentFile getAssignmentFile() {
110:                 return this.assignmentFile;
111:         }
112: 
113:         /**
114:          * Sets the associated assignment file.
115:          * 
116:          * @param assignmentFile
117:          *            The assignment file to set.
118:          */
119:         public void setAssignmentFile(final AssignmentFile assignmentFile) {
120:                 this.assignmentFile = assignmentFile;
121:         }
122: 
123: }