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