Hit.java revision 0
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
137N/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/*
137N/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
0N/Aimport java.io.File;
137N/A
137N/A/**
137N/A * The hit class represents a single search hit
137N/A *
137N/A * @author Trond Norbye
137N/A */
137N/Apublic class Hit implements Comparable {
137N/A /**
457N/A * Holds value of property filename.
137N/A */
137N/A private String filename;
428N/A
428N/A /**
0N/A * Holds value of property directory
0N/A */
0N/A private String directory;
0N/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 /**
137N/A * Holds value of property binary.
0N/A */
0N/A private boolean binary;
0N/A
0N/A /**
137N/A * Holds value of property alt used to hightlight alternating files.
0N/A */
137N/A private boolean alt;
0N/A
0N/A /**
457N/A * path relative to source root.
0N/A */
0N/A private String path;
0N/A
137N/A /**
0N/A * Creates a new instance of Hit
0N/A */
0N/A public Hit() {
0N/A this(null, null, null, false, false);
0N/A }
137N/A
0N/A /**
137N/A * Creates a new instance of Hit
0N/A *
0N/A * @param filename The name of the file this hit represents
0N/A * @param line The line containing the match
0N/A * @param lineno The line number in the file the match was found
137N/A * @param binary If this is a binary file or not
0N/A */
0N/A public Hit(String filename, String line, String lineno, boolean binary, boolean alt) {
0N/A File file = new File(filename);
0N/A this.path = filename;
137N/A this.filename = file.getName();
0N/A this.directory = file.getParent();
137N/A if (directory == null) {
0N/A directory = "";
0N/A }
0N/A this.line = line;
0N/A this.lineno = lineno;
0N/A this.binary = binary;
137N/A this.alt = alt;
0N/A }
0N/A
0N/A /**
0N/A * Getter for property filename.
0N/A *
0N/A * @return Value of property filename.
0N/A */
137N/A public String getFilename() {
0N/A return this.filename;
0N/A }
0N/A
0N/A /**
0N/A * Getter for property path.
0N/A *
0N/A * @return Value of property path.
137N/A */
0N/A public String getPath() {
0N/A return this.path;
0N/A }
0N/A
0N/A /**
0N/A * Getter for property directory
137N/A *
0N/A * @return Value of property directory
0N/A */
0N/A public String getDirectory() {
137N/A return this.directory;
137N/A }
0N/A
0N/A /**
0N/A * Setter for property filename.
0N/A *
0N/A * @param filename New value of property filename.
0N/A */
0N/A public void setFilename(String filename) {
137N/A this.filename = filename;
0N/A }
0N/A
0N/A /**
0N/A * Getter for property line.
0N/A *
137N/A * @return Value of property line.
0N/A */
137N/A public String getLine() {
0N/A return this.line;
0N/A }
0N/A
0N/A /**
137N/A * Setter for property line.
0N/A *
137N/A * @param line New value of property line.
137N/A */
0N/A public void setLine(String line) {
0N/A this.line = line;
0N/A }
0N/A
137N/A /**
0N/A * Getter for property lineno.
137N/A *
0N/A * @return Value of property lineno.
0N/A */
0N/A public String getLineno() {
137N/A return this.lineno;
0N/A }
137N/A
0N/A /**
137N/A * Setter for property lineno.
0N/A *
0N/A * @param lineno New value of property lineno.
137N/A */
137N/A public void setLineno(String lineno) {
0N/A this.lineno = lineno;
0N/A }
0N/A
0N/A /**
0N/A * Compare this object to another hit (in order to implement the comparable
0N/A * interface)
0N/A *
0N/A * @param o The object to compare this object with
0N/A *
0N/A * @return the result of a toString().compareTo() of the filename
0N/A *
137N/A * @throws java.lang.ClassCastException if o is an instance of another
0N/A * class than Hit
0N/A */
0N/A public int compareTo(Object o) throws ClassCastException {
137N/A if (o instanceof Hit) {
137N/A return getFilename().compareTo(((Hit)o).getFilename());
0N/A } else {
0N/A throw new ClassCastException("Not an instance of Hit. " +
0N/A o.toString() + " " + o.getClass().toString());
0N/A }
0N/A }
0N/A
137N/A /**
0N/A * Getter for property binary.
0N/A *
0N/A * @return Value of property binary.
0N/A */
0N/A public boolean isBinary() {
137N/A return this.binary;
0N/A }
0N/A
0N/A /**
0N/A * Setter for property binary.
137N/A *
0N/A * @param binary New value of property binary.
0N/A */
137N/A public void setBinary(boolean binary) {
0N/A this.binary = binary;
0N/A }
0N/A
0N/A /**
0N/A * Holds value of property tag.
0N/A */
137N/A private String tag;
0N/A
137N/A /**
0N/A * Getter for property tag.
283N/A * @return Value of property tag.
0N/A */
0N/A public String getTag() {
0N/A
0N/A return this.tag;
0N/A }
0N/A
0N/A /**
137N/A * Setter for property tag.
137N/A * @param tag New value of property tag.
137N/A */
137N/A public void setTag(String tag) {
0N/A
137N/A this.tag = tag;
0N/A }
0N/A
0N/A /**
0N/A * Should this be alternate file?
0N/A */
0N/A public boolean getAlt() {
0N/A return alt;
0N/A }
0N/A}
0N/A