Coverage Summary for Class: Capability (org.ethereum.net.client)

Class Class, % Method, % Line, %
Capability 100% (1/1) 42.9% (3/7) 30% (6/20)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.net.client; 21  22 /** 23  * The protocols and versions of those protocols that this peer support 24  */ 25 public class Capability implements Comparable<Capability> { 26  27  public static final String P2P = "p2p"; 28  public static final String RSK = "rsk"; 29  30  private String name; 31  private byte version; 32  33  public Capability(String name, byte version) { 34  this.name = name; 35  this.version = version; 36  } 37  38  public String getName() { 39  return name; 40  } 41  42  public byte getVersion() { 43  return version; 44  } 45  46  public boolean isRSK() { 47  return RSK.equals(name); 48  } 49  50  @Override 51  public boolean equals(Object obj) { 52  if (this == obj) { 53  return true; 54  } 55  56  if (!(obj instanceof Capability)) { 57  return false; 58  } 59  60  Capability other = (Capability) obj; 61  if (this.name == null) { 62  return other.name == null; 63  } else { 64  return this.name.equals(other.name) && this.version == other.version; 65  } 66  } 67  68  @Override 69  public int compareTo(Capability o) { 70  int cmp = this.name.compareTo(o.name); 71  if (cmp != 0) { 72  return cmp; 73  } else { 74  return Byte.valueOf(this.version).compareTo(o.version); 75  } 76  } 77  78  public String toString() { 79  return name + ":" + version; 80  } 81 }