package jalf;

import jalf.relation.algebra.Eq;
import jalf.relation.algebra.Predicate;
import jalf.relation.materialized.SetMemoryRelation;

import java.util.*;
import java.util.stream.*;

/**
 * @author amirm
 */
public class DSL {

    public static AttrName attr(String attr){
        return AttrName.attr(attr);
    }

    public static AttrList attrs(String... attrs) {
        SortedSet<AttrName> set = Stream.of(attrs)
            .distinct()
            .map(AttrName::attr)
            .collect(Collectors.toCollection(TreeSet::new));
        return new AttrList(set);
    }

    public static Renaming renaming(AttrName... namePairs) {
        return Renaming.extension(namePairs);
    }

    public static Renaming renaming(String... namePairs) {
        return Renaming.extension(namePairs);
    }

    public static Tuple tuple(Object... keyValuePairs) {
        return new Tuple(keyValuePairs);
    }

    public static Relation relation(Tuple... tuples) {
        return new SetMemoryRelation(tuples);
    }

    public static Relation project(Relation relation, AttrList attrNames) {
        return relation.project(attrNames);
    }

    public static Relation rename(Relation relation, Renaming renaming) {
        return relation.rename(renaming);
    }

    public static Relation restrict(Relation relation, Predicate predicate) {
        return relation.restrict(predicate);
    }

    public static Predicate eq(String attrName, Object value) {
        return new Eq(AttrName.attr(attrName), value);
    }
}

@@ -139,56 +139,8 @@
 n;%0A%0A
-import java.util.*;%0Aimport java.util.stream.*;%0A%0A
 /**%0A
@@ -180,16 +180,33 @@
  DSL %7B%0A%0A
+    // AttrName%0A%0A
     publ
@@ -278,32 +278,49 @@
 r(attr);%0A    %7D%0A%0A
+    // AttrList%0A%0A
     public stati
@@ -340,22 +340,24 @@
 trs(
-String
+AttrName
 ... attr
 s) %7B
@@ -352,16 +352,20 @@
 ... attr
+Name
 s) %7B%0A   
@@ -373,168 +373,104 @@
     
-SortedSet%3CAttrName%3E set = Stream.of
+return AttrList.attrs
 (attr
+Name
 s)
+;
 %0A    
+%7D%0A%0A
     
-    .distinct()%0A            .map(AttrName::attr)%0A            .collect(Collectors.toCollection(TreeSet::new));
+public static AttrList attrs(String... attrNames) %7B
 %0A   
@@ -485,20 +485,16 @@
 urn 
-new 
 AttrList
 (set
@@ -493,20 +493,49 @@
 List
-(set);%0A    %7D
+.attrs(attrNames);%0A    %7D%0A%0A    // Renaming
 %0A%0A  
@@ -750,32 +750,299 @@
 ePairs);%0A    %7D%0A%0A
+    // Predicate%0A%0A    public static Predicate eq(AttrName attrName, Object value) %7B%0A        return new Eq(attrName, value);%0A    %7D%0A%0A    public static Predicate eq(String attrName, Object value) %7B%0A        return eq(AttrName.attr(attrName), value);%0A    %7D%0A%0A    // Tuple%0A%0A
     public stati
@@ -1122,32 +1122,49 @@
 ePairs);%0A    %7D%0A%0A
+    // Relation%0A%0A
     public stati
@@ -1247,32 +1247,59 @@
 tuples);%0A    %7D%0A%0A
+    // Relational algebra%0A%0A
     public stati
@@ -1666,131 +1666,6 @@
  %7D%0A%0A
-    public static Predicate eq(String attrName, Object value) %7B%0A        return new Eq(AttrName.attr(attrName), value);%0A    %7D%0A
 %7D%0A

Put some order in DSL and systematically delegate to factory methods.