All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jwall.apache.httpd.config.Position Maven / Gradle / Ivy

The newest version!
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *   Copyright (C) 2010-2014 Christian Bockermann 
 *    
 *   This file is part of the jwall.org apache-config library. The apache-config library is
 *   a parsing library to handle Apache HTTPD configuration files.
 *
 *   More information and documentation for the jwall-tools can be found at
 *   
 *                      http://www.jwall.org/apache-config
 *   
 *   This program is free software; you can redistribute it and/or modify it under
 *   the terms of the GNU General Public License as published by the Free Software
 *   Foundation; either version 3 of the License, or (at your option) any later version.
 *   
 *   This program is distributed in the hope that it will be useful, but WITHOUT ANY
 *   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 *   FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 *   You should have received a copy of the GNU General Public License along with this 
 *   program; if not, see .
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package org.jwall.apache.httpd.config;

import java.io.File;
import java.io.Serializable;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

/**
 * 
 * This class is just a convenience way for referencing a directive's location.
 * 
 * @author Christian Bockermann <[email protected]>
 * 
 */

@XStreamAlias("Location")
public class Position implements Serializable, Comparable {

	/**
     * 
     */
	private static final long serialVersionUID = 7653352783645893776L;

	@XStreamAsAttribute
	private File file;

	@XStreamAlias("line")
	@XStreamAsAttribute
	private Integer lineNum;

	public Position(File f, Integer line) {
		file = f;
		lineNum = line;
	}

	/**
	 * @return the file
	 */
	public File getFile() {
		return file;
	}

	/**
	 * @param file
	 *            the file to set
	 */
	public void setFile(File file) {
		this.file = file;
	}

	/**
	 * @return the lineNum
	 */
	public Integer getLine() {
		return lineNum;
	}

	/**
	 * @param lineNum
	 *            the lineNum to set
	 */
	public void setLine(Integer lineNum) {
		this.lineNum = lineNum;
	}

	public boolean sameFile(Position other) {
		if (this.file == other.file)
			return true;

		return (file.getAbsolutePath().equals(other.file.getAbsolutePath()));
	}

	public int compareTo(Position other) {
		if (this == other)
			return 0;

		if (sameFile(other)) {
			return lineNum.compareTo(other.lineNum);
		} else {
			return file.getAbsolutePath().compareTo(
					other.file.getAbsolutePath());
		}
	}

	public String toString() {
		if (file == null) {
			return "???:" + lineNum;
		}

		return file.getAbsolutePath() + ":" + lineNum;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy