Coverage Summary for Class: ParseRequest (com.google.common.primitives)

Class Class, % Method, % Line, %
ParseRequest 0% (0/1) 0% (0/2) 0% (0/18)


1 /* 2  * Copyright (C) 2011 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.primitives; 16  17 import com.google.common.annotations.GwtCompatible; 18  19 /** A string to be parsed as a number and the radix to interpret it in. */ 20 @GwtCompatible 21 @ElementTypesAreNonnullByDefault 22 final class ParseRequest { 23  final String rawValue; 24  final int radix; 25  26  private ParseRequest(String rawValue, int radix) { 27  this.rawValue = rawValue; 28  this.radix = radix; 29  } 30  31  static ParseRequest fromString(String stringValue) { 32  if (stringValue.length() == 0) { 33  throw new NumberFormatException("empty string"); 34  } 35  36  // Handle radix specifier if present 37  String rawValue; 38  int radix; 39  char firstChar = stringValue.charAt(0); 40  if (stringValue.startsWith("0x") || stringValue.startsWith("0X")) { 41  rawValue = stringValue.substring(2); 42  radix = 16; 43  } else if (firstChar == '#') { 44  rawValue = stringValue.substring(1); 45  radix = 16; 46  } else if (firstChar == '0' && stringValue.length() > 1) { 47  rawValue = stringValue.substring(1); 48  radix = 8; 49  } else { 50  rawValue = stringValue; 51  radix = 10; 52  } 53  54  return new ParseRequest(rawValue, radix); 55  } 56 }