[Mulgara-svn] r1300 - trunk/src/jar/tuples/java/org/mulgara/store/tuples

alexhall at mulgara.org alexhall at mulgara.org
Fri Oct 10 21:17:18 UTC 2008


Author: alexhall
Date: 2008-10-10 14:17:17 -0700 (Fri, 10 Oct 2008)
New Revision: 1300

Modified:
   trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java
Log:
Adding an option to LiteralTuples to throw an exception if the tuples is closed more than once, which will match the behavior of HybridTuples.

This is needed to debug and test the TuplesOperations class.  However, there is also real code that uses this class, so I'm not comfortable changing the default behavior.  Therefore I'm adding a new constructor to expose this option; calls to the old constructor will have the existing behavior where multiple closes are allowed.

Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java	2008-10-09 19:43:22 UTC (rev 1299)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java	2008-10-10 21:17:17 UTC (rev 1300)
@@ -70,8 +70,18 @@
   private boolean[] columnContainsUnbound;
   private long[] prefix;
   private boolean sorted;
+  private boolean strictClose = false;
+  private boolean closed = false;
 
-  public LiteralTuples(String[] variableNames, boolean sorted) {
+  /**
+   * Creates an optionally sorted LiteralTuples instance, with an option for strict handling of
+   * the close operation.
+   * @param variableNames The variables for this tuples.
+   * @param sorted <code>true</code> if the rows in this tuples will be sorted.
+   * @param strictClose If <code>true</code>, an IllegalStateException will be thrown if the
+   *   tuples is closed more than once.
+   */
+  public LiteralTuples(String[] variableNames, boolean sorted, boolean strictClose) {
     List<Variable> vars = new ArrayList<Variable>();
     for (int i = 0; i < variableNames.length; i++) {
       Variable v = new Variable(variableNames[i]);
@@ -79,7 +89,18 @@
       vars.add(v);
     }
     init((Variable[]) vars.toArray(new Variable[0]), sorted);
+    this.strictClose = strictClose;
   }
+  
+  /**
+   * Creates an optionally sorted LiteralTuples instance, which will not throw an exception
+   * if closed multiple times.  Equivalent to calling <code>LiteralTuples(variableNames, sorted, false)</code>.
+   * @param variableNames The variables for this tuples.
+   * @param sorted <code>true</code> if the rows in the tuples will be sorted.
+   */
+  public LiteralTuples(String[] variableNames, boolean sorted) {
+    this(variableNames, sorted, false);
+  }
 
   /**
    * Creates a literal tuples with specified variables.
@@ -162,8 +183,8 @@
     return true;
   }
 
-  public List getOperands() {
-    return new ArrayList(0);
+  public List<Tuples> getOperands() {
+    return new ArrayList<Tuples>(0);
   }
 
   public RowComparator getComparator() {
@@ -219,7 +240,10 @@
   }
 
   public void close() throws TuplesException {
-    // Do nothing.
+    if (closed && strictClose) {
+      throw new IllegalStateException("Attempt to close a LiteralTuples twice.");
+    }
+    closed = true;
   }
 
   public boolean hasNoDuplicates() throws TuplesException {




More information about the Mulgara-svn mailing list