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-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.compiler;

import org.openide.compiler.Compiler;
import java.util.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

class DummyCompiler extends Compiler {

    static final Date TIMESTAMP = new Date(2000, 1, 1);
    static final Date TIMESTAMP_NEWER = new Date(2001, 1, 1);
    static final Date TIMESTAMP_OLDER = new Date(1999, 1, 1);
    
    private boolean upToDate = true;
    private Date timeStamp = TIMESTAMP; // some old date
    private Object key;
    String name;
    
    DummyCompiler(String name) {
        this.name = name;
    }
    
    public String toString() {
        return name+" - "+super.toString();
    }
    
    public boolean equals(Object o) {
        if (o instanceof DummyCompiler) {
            DummyCompiler him = (DummyCompiler) o;
            return him.name.equals(name);
        } else {
            return false;
        }
    }
    
    public int hashCode() {
        return name.hashCode();
    }
    
    protected boolean isUpToDate () {
        return upToDate;
    }

    void setUpToDate (boolean upToDate) {
        this.upToDate = upToDate;
    }

    protected Date getTimeStamp () {
        return timeStamp;
    }

    void setTimeStamp (Date timeStamp) {
        this.timeStamp = timeStamp;
    }

    public Class compilerGroupClass () {
        return DummyGroup.class;
    }
    
    public Object compilerGroupKey() {
        return key;
    }

    void setCompilerGroupKey(Object key) {
        this.key = key;
    }
    
    static class  DummyGroup extends CompilerGroup {
        
        private Collection comps = null;
        private Compiler first = null;
        
        public void add (Compiler c) throws IllegalArgumentException {
            if (comps == null)
                comps = new ArrayList();
            comps.add(c);
            if (first == null)
                first = c;
        }

        public boolean start () {
            return true;
        }
        
        public Collection getCompilers() {
            return new ArrayList(comps);
        }
        
        public Object getKey() {
            return first.compilerGroupKey();
        }
        
        public Collection getUniqueCompilers() {
            
            // this code is copied from ExternalGroup:
            // TODO: inherit DummyCompiler and DummyGroup from ExternalCompiler and ExternalGroup
            
            HashMap compilerMap = new HashMap(comps.size() * 4 / 3);
            for (Iterator it = comps.iterator(); it.hasNext(); ) {
                Compiler comp1 = (Compiler)it.next();
                Compiler comp2 = (Compiler)compilerMap.put(comp1, comp1);
                
                if (comp2 != null && comp1 != comp2 && (!comp2.isUpToDate() && comp1.isUpToDate())) {
                    // should happen iff comp2 is BUILD, comp1 COMPILE and both are for the same,
                    // but up-to-date source.
                    compilerMap.put(comp1, comp2);
                }
            }
            return compilerMap.values();
        }
        
    }

}
... 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.