Hit.java revision 345
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
407N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
1054N/A * Copyright 2005 Trond Norbye. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.search;
0N/A
335N/Aimport java.io.File;
335N/A
335N/A/**
335N/A * The hit class represents a single search hit
335N/A *
509N/A * @author Trond Norbye
335N/A */
335N/Apublic class Hit implements Comparable {
335N/A /**
1327N/A * Holds value of property filename.
335N/A */
1327N/A private String filename;
335N/A
335N/A /**
335N/A * Holds value of property directory
271N/A */
99N/A private String directory;
1195N/A
0N/A /**
0N/A * Holds value of property line.
0N/A */
0N/A private String line;
0N/A
0N/A /**
0N/A * Holds value of property lineno.
0N/A */
0N/A private String lineno;
0N/A
0N/A /**
0N/A * Holds value of property binary.
0N/A */
0N/A private boolean binary;
0N/A
0N/A /**
0N/A * Holds value of property alt used to hightlight alternating files.
656N/A */
1327N/A private boolean alt;
271N/A
202N/A /**
202N/A * path relative to source root.
0N/A */
0N/A private String path;
0N/A
0N/A /**
1185N/A * Creates a new instance of Hit
1185N/A */
1185N/A public Hit() {
1185N/A this(null, null, null, false, false);
1185N/A }
1185N/A
1185N/A /**
1185N/A * Creates a new instance of Hit
1185N/A *
1185N/A * @param filename The name of the file this hit represents
1185N/A * @param line The line containing the match
1185N/A * @param lineno The line number in the file the match was found
1185N/A * @param binary If this is a binary file or not
1185N/A */
1185N/A public Hit(String filename, String line, String lineno, boolean binary, boolean alt) {
1190N/A File file = new File(filename);
1185N/A this.path = filename;
1185N/A this.filename = file.getName();
1185N/A this.directory = file.getParent();
1185N/A if (directory == null) {
1185N/A directory = "";
1185N/A }
1185N/A this.line = line;
1190N/A this.lineno = lineno;
1185N/A this.binary = binary;
1185N/A this.alt = alt;
1185N/A }
1185N/A
1185N/A /**
1185N/A * Getter for property filename.
1185N/A *
1185N/A * @return Value of property filename.
1185N/A */
1185N/A public String getFilename() {
1185N/A return this.filename;
1185N/A }
1185N/A
1185N/A /**
1185N/A * Getter for property path.
1185N/A *
1185N/A * @return Value of property path.
656N/A */
656N/A public String getPath() {
656N/A return this.path;
656N/A }
656N/A
0N/A /**
202N/A * Getter for property directory
922N/A *
922N/A * @return Value of property directory
922N/A */
922N/A public String getDirectory() {
202N/A return this.directory;
202N/A }
202N/A
202N/A /**
202N/A * Setter for property filename.
202N/A *
202N/A * @param filename New value of property filename.
202N/A */
0N/A public void setFilename(String filename) {
202N/A this.filename = filename;
0N/A }
656N/A
202N/A /**
0N/A * Getter for property line.
202N/A *
202N/A * @return Value of property line.
656N/A */
0N/A public String getLine() {
656N/A return this.line;
889N/A }
456N/A
0N/A /**
656N/A * Setter for property line.
1054N/A *
0N/A * @param line New value of property line.
656N/A */
656N/A public void setLine(String line) {
656N/A this.line = line;
656N/A }
58N/A
1327N/A /**
656N/A * Getter for property lineno.
0N/A *
656N/A * @return Value of property lineno.
0N/A */
0N/A public String getLineno() {
0N/A return this.lineno;
271N/A }
0N/A
0N/A /**
656N/A * Setter for property lineno.
0N/A *
656N/A * @param lineno New value of property lineno.
0N/A */
335N/A public void setLineno(String lineno) {
335N/A this.lineno = lineno;
509N/A }
509N/A
509N/A /**
509N/A * Compare this object to another hit (in order to implement the comparable
509N/A * interface)
509N/A *
509N/A * @param o The object to compare this object with
559N/A *
559N/A * @return the result of a toString().compareTo() of the filename
1195N/A *
509N/A * @throws java.lang.ClassCastException if o is an instance of another
1195N/A * class than Hit
335N/A */
0N/A public int compareTo(Object o) throws ClassCastException {
0N/A if (o instanceof Hit) {
return getFilename().compareTo(((Hit)o).getFilename());
} else {
throw new ClassCastException("Not an instance of Hit. " +
o.toString() + " " + o.getClass().toString());
}
}
/**
* Getter for property binary.
*
* @return Value of property binary.
*/
public boolean isBinary() {
return this.binary;
}
/**
* Setter for property binary.
*
* @param binary New value of property binary.
*/
public void setBinary(boolean binary) {
this.binary = binary;
}
/**
* Holds value of property tag.
*/
private String tag;
/**
* Getter for property tag.
* @return Value of property tag.
*/
public String getTag() {
return this.tag;
}
/**
* Setter for property tag.
* @param tag New value of property tag.
*/
public void setTag(String tag) {
this.tag = tag;
}
/**
* Should this be alternate file?
*/
public boolean getAlt() {
return alt;
}
}