Skip to content

Method: hashCode()

1: package migration.difffile;
2:
3: import java.util.ArrayList;
4:
5: /**
6: * DiffFile-Klasse in die eine unified-diff Datei geparsed wird.
7: *
8: * @author admin
9: *
10: */
11: public class DiffFile {
12:         /**
13:          * the Hunks.
14:          */
15:         private final ArrayList<DiffPartFile> partFiles;
16:
17:         /**
18:          * Creates a DIffFile with the given parts.
19:          *
20:          * @param partFiles
21:          * DiffPartFiles
22:          */
23:         public DiffFile(final ArrayList<DiffPartFile> partFiles) {
24:                 this.partFiles = partFiles;
25:         }
26:
27:         /**
28:          * @return ArrayList DiffPartFile
29:          */
30:         public ArrayList<DiffPartFile> getPartFiles() {
31:                 return partFiles;
32:         }
33:
34:         /**
35:          * @param firstLine
36:          * the first line
37:          * @param secondLine
38:          * the second line
39:          * @return true if and only if the lines are in the same context
40:          */
41:         public boolean isRenameInTheSameContext(final DiffPartFileLine firstLine,
42:                         final DiffPartFileLine secondLine) {
43:                 for (DiffPartFile diffPartFile : partFiles) {
44:                         if (diffPartFile.isRenameInTheSameContext(firstLine, secondLine)) {
45:                                 return true;
46:                         }
47:                 }
48:                 return false;
49:         }
50:
51:         @Override
52:         public int hashCode() {
53:                 final int prime = 31;
54:                 int result = 1;
55:•                result = prime * result + ((partFiles == null)
56:                                 ? 0
57:                                 : partFiles.hashCode());
58:                 return result;
59:         }
60:
61:         @Override
62:         public boolean equals(final Object obj) {
63:                 if (this == obj) {
64:                         return true;
65:                 }
66:                 if (obj == null) {
67:                         return false;
68:                 }
69:                 if (getClass() != obj.getClass()) {
70:                         return false;
71:                 }
72:                 final DiffFile other = (DiffFile) obj;
73:                 if (partFiles == null) {
74:                         if (other.partFiles != null) {
75:                                 return false;
76:                         }
77:                 } else if (!partFiles.equals(other.partFiles)) {
78:                         return false;
79:                 }
80:                 return true;
81:         }
82:
83: }