LCOV - code coverage report
Current view: top level - extensions/restapi - IdString.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 9 13 69.2 %
Date: 2022-11-19 15:00:39 Functions: 7 9 77.8 %

          Line data    Source code
       1             : // Copyright (C) 2013 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // 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
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.extensions.restapi;
      16             : 
      17             : /**
      18             :  * Resource identifier split out from a URL.
      19             :  *
      20             :  * <p>Identifiers are URL encoded and usually need to be decoded.
      21             :  */
      22             : public class IdString {
      23             :   /** Construct an identifier from an already encoded string. */
      24             :   public static IdString fromUrl(String id) {
      25         100 :     return new IdString(id);
      26             :   }
      27             : 
      28             :   /** Construct an identifier from an already decoded string. */
      29             :   public static IdString fromDecoded(String id) {
      30         148 :     return new IdString(Url.encode(id));
      31             :   }
      32             : 
      33             :   private final String urlEncoded;
      34             : 
      35         148 :   private IdString(String s) {
      36         148 :     urlEncoded = s;
      37         148 :   }
      38             : 
      39             :   /** Returns the decoded value of the string. */
      40             :   public String get() {
      41         148 :     return Url.decode(urlEncoded);
      42             :   }
      43             : 
      44             :   /** Returns true if the string is the empty string. */
      45             :   public boolean isEmpty() {
      46          27 :     return urlEncoded.isEmpty();
      47             :   }
      48             : 
      49             :   /** Returns the original URL encoding supplied by the client. */
      50             :   public String encoded() {
      51          92 :     return urlEncoded;
      52             :   }
      53             : 
      54             :   @Override
      55             :   public int hashCode() {
      56           0 :     return urlEncoded.hashCode();
      57             :   }
      58             : 
      59             :   @Override
      60             :   public boolean equals(Object other) {
      61           0 :     if (other instanceof IdString) {
      62           0 :       return urlEncoded.equals(((IdString) other).urlEncoded);
      63             :     }
      64           0 :     return false;
      65             :   }
      66             : 
      67             :   @Override
      68             :   public String toString() {
      69           6 :     return encoded();
      70             :   }
      71             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750