package edu.cmu.cs.diamond.opendiamond;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Searchlet {
    final private List<Filter> filters = new ArrayList<Filter>();
    private String[] dependencies;
    
    public void addFilter(Filter f) {
        filters.add(f);
    }
    
    public void setApplicationDependencies(String dependencies[]) {
        this.dependencies = new String[dependencies.length];
        System.arraycopy(dependencies, 0, this.dependencies, 0, dependencies.length);
    }
    
    File createFilterSpecFile() throws IOException {
        File out = File.createTempFile("filterspec", ".txt");
        out.deleteOnExit();

        Writer w = new FileWriter(out);
        for (Filter f : filters) {
            w.write(f.toString());
        }
        
        if (dependencies != null) {
            w.write("FILTER APPLICATION\n");
            for (String d : dependencies) {
                w.write("REQUIRES " + d + "\n");
            }
        }
        
        w.close();
        return out;
    }
    
    File[] createFilterFiles() throws IOException {
        File result[] = new File[filters.size()];

        int i = 0;
        for (Filter f : filters) {
            File file = File.createTempFile("filter", ".bin");
            file.deleteOnExit();
            
            DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
            out.write(f.getFilterCode().getBytes());
            out.close();
            
            result[i++] = file;
        }
        
        return result;
    }
}

@@ -722,47 +722,8 @@
 t);%0A
-        for (Filter f : filters) %7B%0A    
     
@@ -734,18 +734,16 @@
 w.write(
-f.
 toString
@@ -751,234 +751,8 @@
 ));%0A
-        %7D%0A        %0A        if (dependencies != null) %7B%0A            w.write(%22FILTER APPLICATION%5Cn%22);%0A            for (String d : dependencies) %7B%0A                w.write(%22REQUIRES %22 + d + %22%5Cn%22);%0A            %7D%0A        %7D%0A        %0A
     
@@ -1319,10 +1319,438 @@
 ;%0A    %7D%0A
+    %0A    @Override%0A    public String toString() %7B%0A        StringBuilder sb = new StringBuilder();%0A        for (Filter f : filters) %7B%0A            sb.append(f.toString());%0A        %7D%0A        %0A        if (dependencies != null) %7B%0A            sb.append(%22FILTER APPLICATION%5Cn%22);%0A            for (String d : dependencies) %7B%0A                sb.append(%22REQUIRES %22 + d + %22%5Cn%22);%0A            %7D%0A        %7D%0A%0A        return sb.toString();%0A    %7D%0A
 %7D%0A

Add toString() to Searchlet