alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

/************************************************************************

        FILENAME: Entry.java

        AUTHOR: Erica Grevemeyer      DATE: Jan  7 11:21:09 PST 2002

************************************************************************/
package org.netbeans.nbbuild.utils.cvsutils;

import java.util.*;

/**
 *	This CVS utility class will parse a single line in a 
 *	CVS/Entries file.
 *
 *   @author Erica Grevemeyer
 *   @version  1.1 Jan  7 11:21:09 PST 2002
 */

public class Entry {
	private static final String DEFAULT_SEPARATOR = "/";
	private String filename, filetype, revno, timestamp;

	// Constructor Methods
	/** Create an Entry instance when all information is already available.
	* @param ft - File type. (Value will be either "F" or "D" indicating file or directory).
	* @param fn - filename listed in the entry
	* @param revno - latest revision number listedx.
	* @param ts - the time stamp string. (ex. Sat Dec 22 00:31:24 2001)
    * This may have additional information if the file is not up to date.
	*/
	public Entry(String ft, String fn, String revno, String ts) {
		setFiletype(ft);
		setFilename(fn);
		setRevno(revno);
		setTimestamp(ts);
	}

	/**
	* @param line - line from the read in file. 
	* @param separator - separator used in this file.  CVS generated files will use "/" 
	*/
	public Entry(String line, String separator) {
	/*
		We use the separator here instead of always 
		defaulting to CVS's "/" so that we can use 
		this class to parse files which are 
		organized the same way, but don't use the '/'.

	*/ 
		StringTokenizer st = new StringTokenizer(line, separator);

		int index = 0;
		String[] item=new String[6];

		while (st.hasMoreTokens()) {
			String ftstr = ""; 
			String tok = st.nextToken();
			
			//  Typical CVS/Entries file lines:
			//   D/dirname////
			//  /filename/1.3/Sat Dec 22 00:31:24 2001//

			if (index == 0 ) {
				if ( ! tok.equals("D") ) {
					item[index++]="F";
				}
			}
			item[index++]=tok;
			//item[0] = filetype
			//item[1] = filename
			//item[2] = revno
			//item[3] = timestamp
			//item[4] = other
			//item[5] = other1

		} //while more tokens
		this.setFiletype(item[0]);
		this.setFilename(item[1]);
		this.setRevno(item[2]);
		this.setTimestamp(item[3]);
		
	}
        
	public Entry(String line) {
		this(line, DEFAULT_SEPARATOR);
	}
	
	public boolean hasName(String queryFilename) {	
		return this.getFilename().trim().equals(queryFilename.trim());
	}	

	//Display Methods
	public String toString() {
		String fn, ft, revno, ts;

		fn=this.getFilename();
		ft=this.getFiletype();
		revno=this.getRevno();
		ts=this.getTimestamp();

		String fullEntry="FileName:\t"
			+fn+"\nFileType:\t"+ft +"\nRevno:\t"+revno
			+"\nTimeStamp:\t" +ts+"\n";
		return fullEntry;	
	}

	// Accessor Methods
	public void setFilename(String str) {
		this.filename=str;
	}	

	public String getFilename() {
		return filename;
	}	

	public void setFiletype(String str) {
		this.filetype=str;
	}	

	public String getFiletype() {
		return filetype;
	}	

	public void setRevno(String str) {
		this.revno=str;
	}	

	public String getRevno() {
		return revno;
	}	

	public void setTimestamp(String str) {
		this.timestamp=str;
	}	

	public String getTimestamp() {
		return timestamp;
	}	
	
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.