FileDocCategorySizeDatePackage
FileList.javaAPI DocphoneME MR2 API (J2ME)7448Wed May 02 17:59:48 BST 2007makedep

FileList

public class FileList extends Vector
This class implements the java.util.List interface as well as providing functionality specific to keeping track of lists of files. See the documentation for the Database class to see how these are used. Each FileList must only contain other FileLists (although that is not currently enforced in the mutators).

Fields Summary
private String
name
private boolean
beenHere
private boolean
mayBeCycle
private boolean
isCycle
private boolean
useGrandInclude
Put in list because a file can refuse to
private String
platformDependentInclude
private int
count
private Platform
plat
Constructors Summary
public FileList(String n, Platform plat)

	super();
	this.plat = plat;
	beenHere = mayBeCycle = isCycle = false;
	platformDependentInclude = null;
	name = n;
	count = 0;
	useGrandInclude = plat.haveGrandInclude();
    
Methods Summary
public voidaddIfAbsent(makedep.FileList s)

	for (Iterator iter = iterator(); iter.hasNext(); ) {
	    if (iter.next() == s) {
		return;
	    }
	}
	add(s);
    
public booleancompareLists(makedep.FileList s)

	Iterator myIter = iterator();
	Iterator hisIter = s.iterator();

	while (myIter.hasNext() &&
	       hisIter.hasNext()) {
	    // crude: order dependent
	    FileList myElement = (FileList) myIter.next();
	    FileList hisElement = (FileList) hisIter.next();
	    if (!plat.fileNameStringEquality(myElement.name,
					     hisElement.name)) {
		return false;
	    }
	}
	
	if (myIter.hasNext() != hisIter.hasNext()) {
	    // One ended earlier
	    return false;
	}
	
	return true;
    
public makedep.FileListdoCFile()

	FileList s = new FileList(name, plat);
	s.useGrandInclude = useGrandInclude; // propagate this
	doFiles(s);
	for (Iterator iter = s.iterator(); iter.hasNext(); ) {
	    FileList l = (FileList) iter.next();
	    l.beenHere = false;
	}
	return s;
    
public booleandoFiles(makedep.FileList s)

	boolean result = true;
	for (Iterator iter = iterator(); iter.hasNext(); ) {
	    FileList h = (FileList) iter.next();
	    if (h.platformDependentInclude != null) {
		System.err.println("Error: the source for " +
				   h.platformDependentInclude +
				   " is " + h.name + ".");
		System.err.println("\tIt shouldn't be included directly by " +
				   name + ".");
		h.platformDependentInclude = null; // report once per file
		result = false;
	    }
	    h.doHFile(s);
	}
	return result;
    
public voiddoHFile(makedep.FileList s)

	if (beenHere) {
	    if (mayBeCycle) {
		traceCycle(this);
	    }
	    return;
	}
	beenHere = true;
	mayBeCycle = true;
	doFiles(s);
	mayBeCycle = false;
	s.add(this);
    
public booleanequals(java.lang.Object o)

      return ((Object) this) == o;
    
public intgetCount()

	return count;
    
public java.lang.StringgetName()

	return name;
    
public java.lang.StringgetPlatformDependentInclude()

	return platformDependentInclude;
    
public booleangetUseGrandInclude()

	return useGrandInclude;
    
public booleanhasListForFile(java.lang.String fileName)

	for (Iterator iter = iterator(); iter.hasNext(); ) {
	    FileList fl = (FileList) iter.next();
	    if (plat.fileNameStringEquality(fl.name, fileName)) {
		plat.fileNamePortabilityCheck(fl.name, fileName);
		return true;
	    }
	}
	return false;
    
public voidincrementCount()

	count++;
    
public makedep.FileListlistForFile(java.lang.String fileName)

	for (Iterator iter = iterator(); iter.hasNext(); ) {
	    FileList fl = (FileList) iter.next();
	    if (plat.fileNameStringEquality(fl.name, fileName)) {
		plat.fileNamePortabilityCheck(fl.name, fileName);
		return fl;
	    }
	}
	plat.fileNamePortabilityCheck(fileName);
	FileList newList = new FileList(fileName, plat);
	add(newList);
	return newList;
    
public voidputInclFile(Database db)
if .h file is included thresh times, put it in the grand include file

        boolean needline = true;
	FileName inclName = plat.getInclFileTemplate().copyStem(name);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(baos);
    	PrintWriter inclFile = new PrintWriter(writer);

	if (plat.haveGrandInclude() && plat.includeGIInEachIncl()) {
	    inclFile.println("# include \"" +
			     plat.getGIFileTemplate().dirPreStemAltSuff() +
			     "\"");
	    needline = false;
	}
	for (Iterator iter = iterator(); iter.hasNext(); ) {
	    FileList hfile = (FileList) iter.next();
	    if (!db.hfileIsInGrandInclude(hfile, this)) {
                String incname = plat.getInclFileTemplate().getInvDir() + 
				 db.tryGetFullPath(hfile.name);
                incname = plat.translateFileName(incname);
		inclFile.println("#include \"" + incname + "\"");
	        needline = false;
	    }
	}

	// Solaris C++ in strict mode warns about empty files

	if (needline) {
	    inclFile.println();
	}
        inclFile.flush();
        Database.updateFile(inclName.dirPreStemSuff(), baos);
	inclFile.close();
    
public voidsetFirstFile(makedep.FileList s)

      // Remove the file list if it's already here
      remove(s);
      add(0, s);
    
public voidsetLastFile(makedep.FileList s)

      // Remove the file list if it's already here
      remove(s);
      add(s);
    
public voidsetPlatformDependentInclude(java.lang.String arg)

	platformDependentInclude = arg;
    
public voidsetUseGrandInclude(boolean arg)

	useGrandInclude = arg;
    
public voidsortByName()

	Collections.sort(this, new Comparator() {
		public int compare(Object o1, Object o2) {
		    FileList fl1 = (FileList) o1;
		    FileList fl2 = (FileList) o2;
		    return fl1.getName().compareTo(fl2.getName());
		}
	    });
    
public voidtraceCycle(makedep.FileList s)

	if (isCycle) // already traced
	    return;
	isCycle = true;
	System.err.println("\ttracing cycle for " + name);
	// IMPL_NOTE: must return status in caller routine
	// exitCode = 1;
	for (Iterator iter = iterator(); iter.hasNext(); ) {
	    FileList q = (FileList) iter.next();
	    if (q.mayBeCycle) {
		if (s == q) {
		    plat.fatalError("\tend of cycle for " + s.getName());
		} else {
		    q.traceCycle(s);
		}
	    }
	}