xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexedSymlink.java (revision 5d9f3aa0ca3da3a714233f987fa732f62c0965f6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * See LICENSE.txt included in this distribution for the specific
9  * language governing permissions and limitations under the License.
10  *
11  * When distributing Covered Code, include this CDDL HEADER in each
12  * file and include the License file at LICENSE.txt.
13  * If applicable, add the following below this CDDL HEADER, with the
14  * fields enclosed by brackets "[]" replaced with your own identifying
15  * information: Portions Copyright [yyyy] [name of copyright owner]
16  *
17  * CDDL HEADER END
18  */
19 
20 /*
21  * Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
22  */
23 package org.opengrok.indexer.index;
24 
25 import java.io.File;
26 
27 /**
28  * Represents the associated data of a symlink indexed by {@link IndexDatabase}.
29  */
30 public class IndexedSymlink {
31 
32     private final String absolute;
33     private final String canonical;
34     private final boolean isLocal;
35 
36     private final String canonicalSeparated;
37 
38     /**
39      * Initializes an instance with the required arguments.
40      * @param absolute a defined instance
41      * @param canonical a defined instance
42      * @param isLocal a value indicating if the symlink was local to a project.
43      */
IndexedSymlink(String absolute, String canonical, boolean isLocal)44     IndexedSymlink(String absolute, String canonical, boolean isLocal) {
45         if (absolute == null) {
46             throw new IllegalArgumentException("absolute is null");
47         }
48         if (canonical == null) {
49             throw new IllegalArgumentException("canonical is null");
50         }
51         this.absolute = absolute;
52         this.canonical = canonical;
53         this.isLocal = isLocal;
54         this.canonicalSeparated = canonical + File.separator;
55     }
56 
getAbsolute()57     public String getAbsolute() {
58         return absolute;
59     }
60 
getCanonical()61     public String getCanonical() {
62         return canonical;
63     }
64 
isLocal()65     public boolean isLocal() {
66         return isLocal;
67     }
68 
69     /**
70      * Gets the value of {@link #getCanonical()} with a {@link File#separator}
71      * appended.
72      * @return a defined instance
73      */
getCanonicalSeparated()74     public String getCanonicalSeparated() {
75         return canonicalSeparated;
76     }
77 
78     /**
79      * Compares {@link #getAbsolute()}, {@link #getCanonical()}, and
80      * {@link #isLocal()} to determine equality. (Generated by IntelliJ.)
81      */
82     @Override
equals(Object o)83     public boolean equals(Object o) {
84         if (this == o) {
85             return true;
86         }
87         if (o == null || getClass() != o.getClass()) {
88             return false;
89         }
90 
91         IndexedSymlink that = (IndexedSymlink) o;
92 
93         if (isLocal != that.isLocal) {
94             return false;
95         }
96         if (!absolute.equals(that.absolute)) {
97             return false;
98         }
99         return canonical.equals(that.canonical);
100     }
101 
102     /**
103      * Gets a hashcode derived from {@link #getAbsolute()},
104      * {@link #getCanonical()}, and {@link #isLocal()}. (Generated by IntelliJ.)
105      */
106     @Override
hashCode()107     public int hashCode() {
108         int result = absolute.hashCode();
109         result = 31 * result + canonical.hashCode();
110         result = 31 * result + (isLocal ? 1 : 0);
111         return result;
112     }
113 }
114