• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018, OpenCensus Authors
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 io.opencensus.examples.grpc.helloworld;
18 
19 import java.util.logging.Logger;
20 import javax.annotation.Nullable;
21 
22 /** Util methods. */
23 final class HelloWorldUtils {
24 
25   private static final Logger logger = Logger.getLogger(HelloWorldUtils.class.getName());
26 
getPortOrDefaultFromArgs(String[] args, int index, int defaultPort)27   static int getPortOrDefaultFromArgs(String[] args, int index, int defaultPort) {
28     int portNumber = defaultPort;
29     if (index < args.length) {
30       try {
31         portNumber = Integer.parseInt(args[index]);
32       } catch (NumberFormatException e) {
33         logger.warning(
34             String.format("Port %s is invalid, use default port %d.", args[index], defaultPort));
35       }
36     }
37     return portNumber;
38   }
39 
getStringOrDefaultFromArgs( String[] args, int index, @Nullable String defaultString)40   static String getStringOrDefaultFromArgs(
41       String[] args, int index, @Nullable String defaultString) {
42     String s = defaultString;
43     if (index < args.length) {
44       s = args[index];
45     }
46     return s;
47   }
48 
HelloWorldUtils()49   private HelloWorldUtils() {}
50 }
51