package net.ssehub.kernel_haven.test_utils;

import java.util.Properties;

import net.ssehub.kernel_haven.SetUpException;
import net.ssehub.kernel_haven.analysis.AnalysisComponent;
import net.ssehub.kernel_haven.util.BlockingQueue;

/**
 * An analysis component that provides static data. Useful as input for testing other components.
 * 
 * @param <T> The type of data to create.
 * 
 * @author Adam
 */
public class TestAnalysisComponentProvider<T> extends AnalysisComponent<T> {

    private BlockingQueue<T> data;
    
    /**
     * Creates a new instance with the given data.
     * 
     * @param data The data that this component should "create" and pass to the next component.
     * 
     * @throws SetUpException Shouldn't happen.
     */
    public TestAnalysisComponentProvider(Iterable<T> data) throws SetUpException {
        super(new TestConfiguration(new Properties()));
        this.data = new BlockingQueue<>();
        for (T t : data) {
            this.data.add(t);
        }
        this.data.end();
    }
    
    /**
     * Creates a new instance with the given data.
     * 
     * @param data The data that this component should "create" and pass to the next component.
     * 
     * @throws SetUpException Shouldn't happen.
     */
    @SafeVarargs
    public TestAnalysisComponentProvider(T... data) throws SetUpException {
        super(new TestConfiguration(new Properties()));
        this.data = new BlockingQueue<>();
        for (T t : data) {
            this.data.add(t);
        }
        this.data.end();
    }
    
    /**
     * Creates a new instance with the given data.
     * 
     * @param data The data that this component should "create" and pass to the next component.
     * 
     * @throws SetUpException Shouldn't happen.
     */
    public TestAnalysisComponentProvider(T data) throws SetUpException {
        super(new TestConfiguration(new Properties()));
        this.data = new BlockingQueue<>();
        this.data.add(data);
        this.data.end();
    }

    @Override
    protected void execute() {
        for (T element : this.data) {
            addResult(element);
        }
    }

    @Override
    public String getResultName() {
        return "TestResult";
    }
    
}

@@ -512,24 +512,54 @@
  data;%0A    %0A
+    private String name;%0A    %0A
     /**%0A    
@@ -1039,32 +1039,69 @@
 his.data.end();%0A
+        this.name = %22TestComponent%22;%0A
     %7D%0A    %0A    /
@@ -1427,202 +1427,48 @@
     
-super(new TestConfiguration(new Properties()));%0A        this.data = new BlockingQueue%3C%3E();%0A        for (T t : data) %7B%0A            this.data.add(t);%0A        %7D%0A        this.data.end();%0A    %7D%0A    %0D
+this(%22TestComponent%22, data);%0A    %7D%0A    %0A
     
@@ -1522,32 +1522,105 @@
 n data.%0A     * %0A
+     * @param name The name that %7B@link #getResultName()%7D should return.%0A
      * @param da
@@ -1755,32 +1755,49 @@
 happen.%0A     */%0A
+    @SafeVarargs%0A
     public TestA
@@ -1821,17 +1821,33 @@
 rovider(
-T
+String name, T...
  data) t
@@ -1960,32 +1960,63 @@
 ckingQueue%3C%3E();%0A
+        for (T t : data) %7B%0A    
         this.dat
@@ -2021,23 +2021,30 @@
 ata.add(
-data
+t
 );%0A
+        %7D%0A
         
@@ -2060,27 +2060,57 @@
 .end();%0A    
-%7D%0A%0A
+    this.name = name;%0A    %7D%0A    %0D
     @Overrid
@@ -2298,20 +2298,12 @@
 urn 
-%22TestResult%22
+name
 ;%0A  

Allow setting the result name in TestAnalysisComponentProvider