krysalis-version/src/java/org/krysalis/version/util/classpath PathSet.java,1.2,1.3

[email protected]
Newsgroups gmane.comp.krysalis.sandbox
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/util/classpath
In directory sc8-pr-cvs1:/tmp/cvs-serv5523/src/java/org/krysalis/version/util/classpath

Modified Files:
	PathSet.java 
Log Message:
Null pointer problem fixed.
Added the init method and made the constructors call it, to initialize the Arraylist member. Which was missing in some of the constructors.

Index: PathSet.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/util/classpath/PathSet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PathSet.java	18 Feb 2003 22:17:10 -0000	1.2
--- PathSet.java	19 Feb 2003 21:34:32 -0000	1.3
***************
*** 69,180 ****
   * @author ajack
   */
! public class PathSet {
  
!     private boolean m_changed = false;
!     private ArrayList m_parts = null;
  
!     public PathSet(String path) {
!         m_parts = new ArrayList();
  
!         importPath(path);
!     }
  
!     public PathSet() {
!         m_parts = new ArrayList();
!     }
  
!     public static PathSet getSystemClasspath() {
!         String classPath = SystemUtils.getSystemProperty("java.class.path");
  
!         VersionLogger.g_log.debug("Class Path: " + classPath);
  
!         return new PathSet(classPath);
!     }
  
!     public static PathSet getSystemBootClasspath() {
!         String bootClassPath =
!             SystemUtils.getSystemProperty("sun.boot.class.path");
  
!         VersionLogger.g_log.debug("Boot Class Path: " + bootClassPath);
  
!         return new PathSet(bootClassPath);
!     }
  
!     public PathSet(Collection collection) {
!         this(collection.iterator());
!     }
  
!     public PathSet(Iterator iterator) {
!         for (; iterator.hasNext();) {
!             Object pathPart = (Object) iterator.next();
  
!             if (pathPart instanceof File) {
!                 File pathPartFileObject = (File) pathPart;
  
!                 addPart(pathPartFileObject.getPath());
!             }
!             else {
!                 addPart(pathPart.toString());
!             }
!         }
!     }
  
!     public void importPath(String path) {
!         for (StringTokenizer tokens =
!             new StringTokenizer(path, SystemUtils.g_pathSeparator);
!             tokens.hasMoreTokens();
!             ) {
!             addPart(tokens.nextToken());
!         }
!     }
  
!     public void importPathSet(PathSet pathSet) {
!         for (Iterator iterator = pathSet.iterator(); iterator.hasNext();) {
!             addPart(iterator.next());
!         }
!     }
  
!     public void addPart(Object path) {
!         m_changed = true;
!         m_parts.add(new PathPart(path));
!     }
  
!     public Iterator iterator() {
  
!         //
!         // Atempt to remove duplicates
!         //
!         if (m_changed)
!             uniqifyOnDemand();
  
!         return m_parts.iterator();
!     }
  
!     public void uniqifyOnDemand() {
!         if (m_changed) {
!             uniqify();
  
!             m_changed = false;
!         }
!     }
  
!     public void uniqify() {
!         ArrayList newParts = new ArrayList();
  
!         //
!         // Remove duplicates, but preserve order..
!         //
!         HashSet set = new HashSet();
  
!         for (Iterator i = m_parts.iterator(); i.hasNext();) {
!             PathPart part = (PathPart) i.next();
  
!             if (!set.contains(part)) {
!                 newParts.add(part);
!                 set.add(part);
!             }
!         }
  
!         m_parts = newParts;
!     }
  }
--- 69,205 ----
   * @author ajack
   */
! public class PathSet
! {
  
! 	private boolean m_changed = false;
! 	private ArrayList m_parts = null;
  
! 	public PathSet(String path)
! 	{
  
! 		init();
! 		importPath(path);
! 	}
  
! 	public PathSet()
! 	{
! 		init();
! 	}
  
! 	public PathSet(Collection collection)
! 	{
! 		this(collection.iterator());
! 	}
  
! 	public PathSet(Iterator iterator)
! 	{
! 		init();
! 		
! 		for (; iterator.hasNext();)
! 		{
! 			Object pathPart = (Object) iterator.next();
  
! 			if (pathPart instanceof File)
! 			{
! 				File pathPartFileObject = (File) pathPart;
  
! 				addPart(pathPartFileObject.getPath());
! 			}
! 			else
! 			{
! 				addPart(pathPart.toString());
! 			}
! 		}
! 	}
  
! 	private void init()
! 	{
! 		m_parts = new ArrayList();
! 	}
! 	
! 	
! 	public static PathSet getSystemClasspath()
! 	{
! 		String classPath = SystemUtils.getSystemProperty("java.class.path");
  
! 		VersionLogger.g_log.debug("Class Path: " + classPath);
  
! 		return new PathSet(classPath);
! 	}
  
! 	public static PathSet getSystemBootClasspath()
! 	{
! 		String bootClassPath = SystemUtils.getSystemProperty("sun.boot.class.path");
  
! 		VersionLogger.g_log.debug("Boot Class Path: " + bootClassPath);
  
! 		return new PathSet(bootClassPath);
! 	}
  
! 	public void importPath(String path)
! 	{
! 		for (StringTokenizer tokens = new StringTokenizer(path, SystemUtils.g_pathSeparator); tokens.hasMoreTokens();)
! 		{
! 			addPart(tokens.nextToken());
! 		}
! 	}
  
! 	public void importPathSet(PathSet pathSet)
! 	{
! 		for (Iterator iterator = pathSet.iterator(); iterator.hasNext();)
! 		{
! 			addPart(iterator.next());
! 		}
! 	}
  
! 	public void addPart(Object path)
! 	{
! 		m_changed = true;
! 		m_parts.add(new PathPart(path));
! 	}
  
! 	public Iterator iterator()
! 	{
  
! 		//
! 		// Atempt to remove duplicates
! 		//
! 		if (m_changed)
! 			uniqifyOnDemand();
  
! 		return m_parts.iterator();
! 	}
  
! 	public void uniqifyOnDemand()
! 	{
! 		if (m_changed)
! 		{
! 			uniqify();
  
! 			m_changed = false;
! 		}
! 	}
  
! 	public void uniqify()
! 	{
! 		ArrayList newParts = new ArrayList();
  
! 		//
! 		// Remove duplicates, but preserve order..
! 		//
! 		HashSet set = new HashSet();
  
! 		for (Iterator i = m_parts.iterator(); i.hasNext();)
! 		{
! 			PathPart part = (PathPart) i.next();
  
! 			if (!set.contains(part))
! 			{
! 				newParts.add(part);
! 				set.add(part);
! 			}
! 		}
  
! 		m_parts = newParts;
! 	}
  }




-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.