001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.nbio.structure.align.client; 022 023import org.biojava.nbio.structure.StructureException; 024 025/** A pair for structure alignment 026 * 027 * @author Andreas Prlic 028 * 029 * name1 is always < name2 030 * 031 */ 032public class PdbPair implements Comparable<PdbPair> { 033 034 StructureName name1; 035 StructureName name2; 036 public PdbPair(String name1, String name2) { 037 this(new StructureName(name1),new StructureName(name2)); 038 } 039 public PdbPair(StructureName name1, StructureName name2) { 040 super(); 041 this.name1 = name1; 042 this.name2 = name2; 043 } 044 045 public String getName1() { 046 return name1.getIdentifier(); 047 } 048 public void setName1(String name1) { 049 this.name1 = new StructureName(name1); 050 } 051 public String getName2() { 052 return name2.getIdentifier(); 053 } 054 public void setName2(String name2) { 055 this.name2 = new StructureName(name2); 056 } 057 058 @Override 059 public String toString() { 060 return "PdbPair [name1=" + name1 + ", name2=" + name2 + "]"; 061 } 062 063 @Override 064 public int hashCode() { 065 final int prime = 31; 066 int result = 1; 067 result = prime * result + ((name1 == null) ? 0 : name1.hashCode()); 068 result = prime * result + ((name2 == null) ? 0 : name2.hashCode()); 069 return result; 070 } 071 072 @Override 073 public boolean equals(Object obj) { 074 if (this == obj) 075 return true; 076 if (obj == null) 077 return false; 078 if (getClass() != obj.getClass()) 079 return false; 080 PdbPair other = (PdbPair) obj; 081 if (name1 == null) { 082 if (other.name1 != null) 083 return false; 084 } else if (!name1.equals(other.name1)) 085 return false; 086 if (name2 == null) { 087 if (other.name2 != null) 088 return false; 089 } else if (!name2.equals(other.name2)) 090 return false; 091 return true; 092 } 093 094 @Override 095 public int compareTo(PdbPair o) { 096 if ( this.equals(o)) 097 return 0; 098 // Use StructureName's compareTo method 099 int c = name1.compareTo(o.name1); 100 if ( c != 0 ) 101 return c; 102 return name2.compareTo(o.name2); 103 } 104 105 public String getPDBCode1() throws StructureException { 106 return name1.getPdbId(); 107 } 108 public String getPDBCode2() throws StructureException{ 109 return name2.getPdbId(); 110 } 111 112 public String getChainId1(){ 113 return name1.getChainId(); 114 } 115 public String getChainId2(){ 116 return name2.getChainId(); 117 } 118 119 public PdbPair getReverse() { 120 PdbPair newPair = new PdbPair(name2, name1); 121 return newPair; 122 } 123}