Coverage Summary for Class: JdkPattern (com.google.common.base)

Class Method, % Line, %
JdkPattern 40% (2/5) 57.1% (4/7)
JdkPattern$JdkMatcher 28.6% (2/7) 44.4% (4/9)
Total 33.3% (4/12) 50% (8/16)


1 /* 2  * Copyright (C) 2016 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.base; 16  17 import com.google.common.annotations.GwtIncompatible; 18 import java.io.Serializable; 19 import java.util.regex.Matcher; 20 import java.util.regex.Pattern; 21  22 /** A regex pattern implementation which is backed by the {@link Pattern}. */ 23 @ElementTypesAreNonnullByDefault 24 @GwtIncompatible 25 final class JdkPattern extends CommonPattern implements Serializable { 26  private final Pattern pattern; 27  28  JdkPattern(Pattern pattern) { 29  this.pattern = Preconditions.checkNotNull(pattern); 30  } 31  32  @Override 33  public CommonMatcher matcher(CharSequence t) { 34  return new JdkMatcher(pattern.matcher(t)); 35  } 36  37  @Override 38  public String pattern() { 39  return pattern.pattern(); 40  } 41  42  @Override 43  public int flags() { 44  return pattern.flags(); 45  } 46  47  @Override 48  public String toString() { 49  return pattern.toString(); 50  } 51  52  private static final class JdkMatcher extends CommonMatcher { 53  final Matcher matcher; 54  55  JdkMatcher(Matcher matcher) { 56  this.matcher = Preconditions.checkNotNull(matcher); 57  } 58  59  @Override 60  public boolean matches() { 61  return matcher.matches(); 62  } 63  64  @Override 65  public boolean find() { 66  return matcher.find(); 67  } 68  69  @Override 70  public boolean find(int index) { 71  return matcher.find(index); 72  } 73  74  @Override 75  public String replaceAll(String replacement) { 76  return matcher.replaceAll(replacement); 77  } 78  79  @Override 80  public int end() { 81  return matcher.end(); 82  } 83  84  @Override 85  public int start() { 86  return matcher.start(); 87  } 88  } 89  90  private static final long serialVersionUID = 0; 91 }