package com.health.operations;

import java.util.function.Function;

import com.health.Record;
import com.health.Table;

/**
 * A utility class to perform constraining of tables.
 */
public final class Constraints {
    private Constraints() {
    }

    /**
     * Creates a new table containing only the records from the given table for
     * which the given predicate is evaluated as true.
     *
     * @param predicate
     *            a predicate that determines whether or not to add a given
     *            record to the new table.
     * @param table
     *            the table to constrain on.
     * @return a new table containing only the records for which the given
     *         predicate is evaluated as true.
     */
    public static Table constrain(final Function<Record, Boolean> predicate, final Table table) {
        Table constrained = new Table(table.getColumns());

        for (Record record : table.getRecords()) {
            if (predicate.apply(record)) {
                record.copyTo(constrained);
            }
        }

        return constrained;
    }
}

@@ -209,18 +209,16 @@
 aints %7B%0A
-  
   privat
@@ -239,25 +239,19 @@
 ) %7B%0A
-  
   %7D%0A%0A  
- 
- 
 /**%0A
-  
    *
@@ -323,23 +323,16 @@
 able for
-%0A     *
  which t
@@ -339,16 +339,21 @@
 he given
+%0A   *
  predica
@@ -384,14 +384,10 @@
 %0A   
-  *%0A  
+*%0A
    *
@@ -403,29 +403,25 @@
 redicate%0A   
-  *  
+*
           a 
@@ -475,34 +475,16 @@
  a given
-%0A     *           
  record 
@@ -504,18 +504,16 @@
 ble.%0A   
- 
- 
 * @param
@@ -518,29 +518,25 @@
 am table%0A   
-  *  
+*
           th
@@ -560,18 +560,16 @@
 ain on.%0A
-  
    * @re
@@ -636,23 +636,8 @@
 iven
-%0A     *        
  pre
@@ -650,32 +650,45 @@
  is evaluated as
+%0A   *        
  true.%0A     */%0A 
@@ -685,15 +685,11 @@
 %0A   
-  
 */%0A
-  
   pu
@@ -776,28 +776,24 @@
 le table) %7B%0A
-    
     Table co
@@ -840,20 +840,16 @@
 );%0A%0A    
-   
- 
 for (Rec
@@ -879,30 +879,24 @@
 ecords()) %7B%0A
-      
       if (pr
@@ -928,24 +928,16 @@
         
- 
-       
 record.c
@@ -966,31 +966,17 @@
     
- 
-     %7D%0A  
+%7D%0A
     
-  
 %7D%0A%0A
-    
     
@@ -995,16 +995,14 @@
 rained;%0A
-  
   %7D%0A%7D%0A

format constraint