Coverage Report - com.jcabi.github.Coordinates
 
Classes in this File Line Coverage Branch Coverage Complexity
Coordinates
N/A
N/A
1.25
Coordinates$Simple
94%
17/18
44%
8/18
1.25
 
 1  2
 /**
 2  
  * Copyright (c) 2013-2015, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import javax.validation.constraints.NotNull;
 34  
 import lombok.EqualsAndHashCode;
 35  
 import org.apache.commons.lang3.builder.CompareToBuilder;
 36  
 
 37  
 /**
 38  
  * Repository coordinates.
 39  
  *
 40  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 41  
  * @version $Id$
 42  
  * @since 0.1
 43  
  */
 44  
 @Immutable
 45  
 public interface Coordinates extends Comparable<Coordinates> {
 46  
 
 47  
     /**
 48  
      * Get usr name.
 49  
      * @return User name
 50  
      */
 51  
     @NotNull(message = "user is never NULL")
 52  
     String user();
 53  
 
 54  
     /**
 55  
      * Get rpo name.
 56  
      * @return Repo name
 57  
      */
 58  
     @NotNull(message = "repo is never NULL")
 59  
     String repo();
 60  
 
 61  
     /**
 62  
      * Jcabi.http implementation.
 63  
      */
 64  3
     @Immutable
 65  20
     @EqualsAndHashCode(of = { "usr", "rpo" })
 66  
     final class Simple implements Coordinates {
 67  
         /**
 68  
          * User name.
 69  
          */
 70  
         private final transient String usr;
 71  
         /**
 72  
          * Repository name.
 73  
          */
 74  
         private final transient String rpo;
 75  
         /**
 76  
          * Public ctor.
 77  
          * @param user User name
 78  
          * @param repo Repository name
 79  
          */
 80  
         public Simple(
 81  
             @NotNull(message = "user can't be NULL") final String user,
 82  305
             @NotNull(message = "repo can't be NULL") final String repo) {
 83  305
             this.usr = user;
 84  305
             this.rpo = repo;
 85  305
         }
 86  
         /**
 87  
          * Public ctor.
 88  
          * @param mnemo Mnemo name
 89  
          */
 90  
         public Simple(@NotNull(message = "mnemo can't be NULL")
 91  6
             final String mnemo) {
 92  6
             final String[] parts = mnemo.split("/", 2);
 93  6
             if (parts.length != 2) {
 94  0
                 throw new IllegalArgumentException(
 95  
                     String.format("invalid coordinates '%s'", mnemo)
 96  
                 );
 97  
             }
 98  6
             this.usr = parts[0];
 99  6
             this.rpo = parts[1];
 100  6
         }
 101  
         @Override
 102  
         public String toString() {
 103  2226
             return String.format("%s/%s", this.usr, this.rpo);
 104  
         }
 105  
         @Override
 106  
         @NotNull(message = "user is never NULL")
 107  
         public String user() {
 108  237
             return this.usr;
 109  
         }
 110  
         @Override
 111  
         @NotNull(message = "repo is never NULL")
 112  
         public String repo() {
 113  237
             return this.rpo;
 114  
         }
 115  
         @Override
 116  
         public int compareTo(
 117  
             @NotNull(message = "other can't be NULL") final Coordinates other
 118  
         ) {
 119  3
             return new CompareToBuilder()
 120  
                 .append(this.usr, other.user())
 121  
                 .append(this.rpo, other.repo())
 122  
                 .build();
 123  
         }
 124  
     }
 125  
 }