package natlab.tame.valueanalysis.components.shape;

import java.util.*;

import natlab.tame.valueanalysis.components.constant.Constant;
import natlab.tame.valueanalysis.value.*;

/**
 * allows construction of shapes
 */
public class ShapeFactory<V extends Value<V>> {
	ValueFactory<V> factory;
	
	public ShapeFactory(){
	}
	
	public ShapeFactory(ValueFactory<V> factory){
		this.factory = factory;
	}
	
	
    /**
     * returns a shape with the given dimensions.
     * The given constants should be scalar.
     * 
     */
    public Shape<V> newShapeFromConstants(List<Constant> dims){
    	ArrayList<V> list = new ArrayList<V>(dims.size());
    	for (Constant dim : dims){
    		list.add(factory.newMatrixValue(dim));
    	}
    	return null;
    	//return new Shape<V>(factory, list);
        //throw new UnsupportedOperationException();//return new Shape<D>(factory); XU modified
    }

    
    /**
     * returns a shape using the given values as dimensions
     */
    public Shape<V> newShapeFromValues(List<V> dims){
    	return null;
    	//return new Shape<V>(factory,dims);
    }
    
    
    /**
     * return a shape using the given integer list as dimensions
     */
    public Shape<V> newShapeFromIntegers(List<Integer> dims){
    	/*ArrayList<V> list = new ArrayList<V>(dims.size());
    	for (V dim : dims){
    		list.add(factory.newMatrixValue(dim)); //this line lead to infinite loop!!!
    	}*/
    	return new Shape<V>(factory,dims);
    }
    
    /**
     * returns a 0x0 shape
     */
    @SuppressWarnings("unchecked")
	public Shape<V> getEmptyShape(){
    	return null;
/*        return new Shape<V>(factory,Arrays.asList(
        		factory.newMatrixValue(0),
        		factory.newMatrixValue(0)        		
        		));*/
    }
    
    
    /**
     * returns 1x1 shape 
     */
    @SuppressWarnings("unchecked")
	public Shape<V> getScalarShape(){
    	return null;
/*        return new Shape<V>(factory,Arrays.asList(
        		factory.newMatrixValue(1),
        		factory.newMatrixValue(1)
        		));*/
    }
    
	
}

@@ -67,16 +67,133 @@
 til.*;%0A%0A
+import natlab.tame.valueanalysis.aggrvalue.AggrValue;%0Aimport natlab.tame.valueanalysis.basicmatrix.BasicMatrixValue;%0A
 import n
@@ -247,16 +247,16 @@
 nstant;%0A
-
 import n
@@ -1201,32 +1201,403 @@
 ms);%0A    %7D%0A    %0A
+    /**%0A     * return a shape using the given input string, like 3x3...%0A     */%0A    public Shape%3CV%3E newShapeFromInputString(String s)%7B%0A    %09String%5B%5D array = s.split(%22%5B%5C%5C*%5D%22);%0A    %09ArrayList%3CInteger%3E list = new ArrayList%3CInteger%3E();%0A    %09for(String a : array)%7B%0A    %09%09Integer i = Integer.parseInt(a);%0A    %09%09list.add(i);%0A    %09%7D%0A    %09return new Shape%3CV%3E(factory,list);%0A    %7D%0A
     %0A    /**%0A   
@@ -2529,17 +2529,233 @@
 /%0A    %7D%0A
-
     %0A
+    public static void main(String%5B%5D args)%7B%0A    %09ShapeFactory sf = new ShapeFactory();%0A    %09Shape%3CAggrValue%3CBasicMatrixValue%3E%3E testShape = sf.newShapeFromInputString(%223*3%22);%0A    %09System.out.println(testShape);%0A    %7D%0A
 %09%0A%7D%0A

add a new method in ShapeFactory to support string input, like 3*3..