Coverage Summary for Class: Resources (com.acciente.oacc)

Class Method, % Line, %
Resources 75% (3/ 4) 60% (3/ 5)
Resources$1
Resources$ResourceImpl 100% (8/ 8) 96.6% (28/ 29)
total 91.7% (11/ 12) 91.2% (31/ 34)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * License. You may obtain a copy of the License at 8  * 9  * http://www.apache.org/licenses/LICENSE-2.0 10  * 11  * Unless required by applicable law or agreed to in 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18 package com.acciente.oacc; 19  20 import java.io.Serializable; 21  22 public class Resources { 23  public static Resource getInstance(long resourceId) { 24  return new ResourceImpl(resourceId, null); 25  } 26  27  public static Resource getInstance(long resourceId, String externalId) { 28  return new ResourceImpl(resourceId, externalId); 29  } 30  31  public static Resource getInstance(String externalId) { 32  return new ResourceImpl(externalId); 33  } 34  35  private static class ResourceImpl implements Resource, Serializable { 36  private static final long serialVersionUID = 1L; 37  38  private final Long resourceId; 39  private final String externalId; 40  41  private ResourceImpl(long resourceId, 42  String externalId) { 43  this.resourceId = resourceId; 44  this.externalId = externalId; 45  } 46  47  private ResourceImpl(String externalId) { 48  this.resourceId = null; 49  this.externalId = externalId; 50  } 51  52  @Override 53  public Long getId() { 54  return resourceId; 55  } 56  57  @Override 58  public String getExternalId() { 59  return externalId; 60  } 61  62  @Override 63  public boolean equals(Object other) { 64  if (this == other) { 65  return true; 66  } 67  if (other == null || getClass() != other.getClass()) { 68  return false; 69  } 70  71  ResourceImpl otherResource = (ResourceImpl) other; 72  73  if (resourceId != null ? !resourceId.equals(otherResource.resourceId) : otherResource.resourceId != null) { 74  return false; 75  } 76  return !(externalId != null ? !externalId.equals(otherResource.externalId) : otherResource.externalId != null); 77  } 78  79  @Override 80  public int hashCode() { 81  int result = resourceId != null ? resourceId.hashCode() : 0; 82  result = 31 * result + (externalId != null ? externalId.hashCode() : 0); 83  return result; 84  } 85  86  @Override 87  /** 88  * sample output: 89  * | externalId != null | externalId == null 90  * -------------------|---------------------------------------|-------------------- 91  * resourceId != null | {resourceId: 1234, externalId: "007"} | {resourceId: 1234} 92  * resourceId == null | {externalId: "007"} | {} 93  */ 94  public String toString() { 95  if (resourceId != null && externalId != null) { 96  return "{resourceId: " + String.valueOf(resourceId) + ", externalId: \"" + externalId + "\"}"; 97  } 98  99  if (resourceId != null) { 100  return "{resourceId: " + String.valueOf(resourceId) + "}"; 101  } 102  103  if (externalId != null) { 104  return "{externalId: \"" + externalId + "\"}"; 105  } 106  107  return "{}"; 108  } 109  } 110 }