1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.telephony.tools.sats2;
18 
19 import com.beust.jcommander.JCommander;
20 import com.beust.jcommander.Parameter;
21 import com.beust.jcommander.ParameterException;
22 
23 /** Creates a Sat S2 file from the list of S2 cells. */
24 public final class CreateSatS2File {
25     /**
26      * Usage:
27      * CreateSatS2File <[input] s2 cells file> <[input] s2 level of input data>
28      *     <[input] whether s2 cells is an allowed list> <[output] sat s2 file>
29      */
main(String[] args)30     public static void main(String[] args) throws Exception {
31         Arguments arguments = new Arguments();
32         JCommander.newBuilder()
33                 .addObject(arguments)
34                 .build()
35                 .parse(args);
36         String inputFile = arguments.inputFile;
37         int s2Level = arguments.s2Level;
38         String outputFile = arguments.outputFile;
39         boolean isAllowedList = Arguments.getBooleanValue(arguments.isAllowedList);
40         SatS2FileCreator.create(inputFile, s2Level, isAllowedList, outputFile);
41     }
42 
43     private static class Arguments {
44         @Parameter(names = "--input-file",
45                 description = "s2 cells file",
46                 required = true)
47         public String inputFile;
48 
49         @Parameter(names = "--s2-level",
50                 description = "s2 level of input data",
51                 required = true)
52         public int s2Level;
53 
54         @Parameter(names = "--is-allowed-list",
55                 description = "whether s2 cells file contains an allowed list of cells",
56                 required = true)
57         public String isAllowedList;
58 
59         @Parameter(names = "--output-file",
60                 description = "sat s2 file",
61                 required = true)
62         public String outputFile;
63 
getBooleanValue(String value)64         public static Boolean getBooleanValue(String value) {
65             if ("false".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value)) {
66                 return Boolean.parseBoolean(value);
67             } else {
68                 throw new ParameterException("Invalid boolean string:" + value);
69             }
70         }
71     }
72 }
73