1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.io.File ; 32 33 34 35 36 44 45 public class Occurrence implements Comparable { 46 private File _file; 47 private int _line; 48 private int _column; 49 50 public Occurrence(File file, int line, int column) { 51 _file = file; 52 _line = line; 53 _column = column; 54 } 55 56 public Occurrence(SymTabAST node) { 57 _file = node.getFile(); 58 _line = node.getLineNo(); 59 _column = node.getColumnNo(); 60 } 61 62 67 public File getFile() { 68 return _file; 69 } 70 71 76 public int getLine() { 77 return _line; 78 } 79 80 85 public int getColumn() { 86 return _column; 87 } 88 89 public int compareTo(Object o) { 90 if (!(o instanceof Occurrence)) { 91 throw new ClassCastException (getClass().getName()); 92 } 93 94 Occurrence other = (Occurrence)o; 95 96 int result = 0; 97 98 result = getFile().compareTo(other.getFile()); 99 100 if (result == 0) { 101 result = getLine() - other.getLine(); 102 } 103 if (result == 0) { 104 result = getColumn() - other.getColumn(); 105 } 106 107 return result; 108 } 109 110 public boolean equals(Object o) { 111 boolean result = false; 112 113 if (o instanceof Occurrence) { 114 Occurrence occ = (Occurrence)o; 115 result = (getFile().equals(occ.getFile()) 116 && getLine() == occ.getLine() 117 && getColumn() == occ.getColumn()); 118 } 119 120 return result; 121 } 122 123 public int hashCode() { 124 return getFile().hashCode(); 125 } 126 127 public String toString() { 128 return "[" + getFile() + ":" + getLine() + "," + getColumn() + "]"; 129 } 130 131 } 132 | Popular Tags |