xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/index/NumLinesLOCUtil.java (revision fb4fc4bcc2970158c11a79b4070ebcd0797d96d6)
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) 2020, Chris Fraire <cfraire@me.com>.
22  */
23 package org.opengrok.indexer.index;
24 
25 import org.apache.lucene.document.Document;
26 import org.opengrok.indexer.analysis.NullableNumLinesLOC;
27 import org.opengrok.indexer.analysis.NumLinesLOC;
28 import org.opengrok.indexer.search.QueryBuilder;
29 import org.opengrok.indexer.util.NumberUtil;
30 
31 /**
32  * Represents a utility class for handling related to {@link NumLinesLOC}.
33  */
34 public class NumLinesLOCUtil {
35 
36     /**
37      * Reads data, if they exist, from the specified document.
38      * @return a defined instance
39      */
read(Document doc)40     public static NullableNumLinesLOC read(Document doc) {
41         String path = doc.get(QueryBuilder.D);
42         if (path == null) {
43             path = doc.get(QueryBuilder.PATH);
44         }
45         Long numLines = NumberUtil.tryParseLong(doc.get(QueryBuilder.NUML));
46         Long loc = NumberUtil.tryParseLong(doc.get(QueryBuilder.LOC));
47         return new NullableNumLinesLOC(path, numLines, loc);
48     }
49 
50     /* private to enforce static */
NumLinesLOCUtil()51     private NumLinesLOCUtil() {
52     }
53 }
54