Coverage Report - org.galagosearch.core.types.DocumentValuedExtent
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentValuedExtent
0%
0/12
0%
0/2
0
DocumentValuedExtent$IdentifierOrder
0%
0/26
0%
0/4
0
DocumentValuedExtent$IdentifierOrder$1
0%
0/5
0%
0/2
0
DocumentValuedExtent$IdentifierOrder$2
0%
0/5
0%
0/2
0
DocumentValuedExtent$IdentifierOrder$DuplicateEliminator
0%
0/19
0%
0/4
0
DocumentValuedExtent$IdentifierOrder$OrderedWriterClass
0%
0/14
0%
0/6
0
DocumentValuedExtent$IdentifierOrder$ShreddedBuffer
0%
0/86
0%
0/58
0
DocumentValuedExtent$IdentifierOrder$ShreddedCombiner
0%
0/55
0%
0/36
0
DocumentValuedExtent$IdentifierOrder$ShreddedProcessor
N/A
N/A
0
DocumentValuedExtent$IdentifierOrder$ShreddedReader
0%
0/72
0%
0/34
0
DocumentValuedExtent$IdentifierOrder$ShreddedSource
N/A
N/A
0
DocumentValuedExtent$IdentifierOrder$ShreddedWriter
0%
0/39
0%
0/14
0
DocumentValuedExtent$IdentifierOrder$TupleShredder
0%
0/20
0%
0/8
0
DocumentValuedExtent$IdentifierOrder$TupleUnshredder
0%
0/25
0%
0/2
0
DocumentValuedExtent$Processor
N/A
N/A
0
DocumentValuedExtent$Source
N/A
N/A
0
 
 1  
 // This file was automatically generated with the command: 
 2  
 //     java org.galagosearch.tupleflow.typebuilder.TypeBuilderMojo ...
 3  
 package org.galagosearch.core.types;
 4  
 
 5  
 import org.galagosearch.tupleflow.Utility;
 6  
 import org.galagosearch.tupleflow.ArrayInput;
 7  
 import org.galagosearch.tupleflow.ArrayOutput;
 8  
 import org.galagosearch.tupleflow.Order;   
 9  
 import org.galagosearch.tupleflow.OrderedWriter;
 10  
 import org.galagosearch.tupleflow.Type; 
 11  
 import org.galagosearch.tupleflow.TypeReader;
 12  
 import org.galagosearch.tupleflow.Step; 
 13  
 import org.galagosearch.tupleflow.IncompatibleProcessorException;
 14  
 import org.galagosearch.tupleflow.ReaderSource;
 15  
 import java.io.IOException;             
 16  
 import java.io.EOFException;
 17  
 import java.io.UnsupportedEncodingException;
 18  
 import java.util.ArrayList;
 19  
 import java.util.Arrays;   
 20  
 import java.util.Comparator;
 21  
 import java.util.PriorityQueue;
 22  
 import java.util.Collection;
 23  
 
 24  
 public class DocumentValuedExtent implements Type<DocumentValuedExtent> {
 25  
     public String extentName;
 26  
     public String identifier;
 27  
     public int begin;
 28  
     public int end;
 29  
     public long value; 
 30  
     
 31  0
     public DocumentValuedExtent() {}
 32  0
     public DocumentValuedExtent(String extentName, String identifier, int begin, int end, long value) {
 33  0
         this.extentName = extentName;
 34  0
         this.identifier = identifier;
 35  0
         this.begin = begin;
 36  0
         this.end = end;
 37  0
         this.value = value;
 38  0
     }  
 39  
     
 40  
     public String toString() {
 41  0
             return String.format("%s,%s,%d,%d,%d",
 42  
                                    extentName, identifier, begin, end, value);
 43  
     } 
 44  
 
 45  
     public Order<DocumentValuedExtent> getOrder(String... spec) {
 46  0
         if (Arrays.equals(spec, new String[] { "+identifier" })) {
 47  0
             return new IdentifierOrder();
 48  
         }
 49  0
         return null;
 50  
     } 
 51  
       
 52  
     public interface Processor extends Step, org.galagosearch.tupleflow.Processor<DocumentValuedExtent> {
 53  
         public void process(DocumentValuedExtent object) throws IOException;
 54  
         public void close() throws IOException;
 55  
     }                        
 56  
     public interface Source extends Step {
 57  
     }
 58  0
     public static class IdentifierOrder implements Order<DocumentValuedExtent> {
 59  
         public int hash(DocumentValuedExtent object) {
 60  0
             int h = 0;
 61  0
             h += Utility.hash(object.identifier);
 62  0
             return h;
 63  
         } 
 64  
         public Comparator<DocumentValuedExtent> greaterThan() {
 65  0
             return new Comparator<DocumentValuedExtent>() {
 66  0
                 public int compare(DocumentValuedExtent one, DocumentValuedExtent two) {
 67  0
                     int result = 0;
 68  
                     do {
 69  0
                         result = + Utility.compare(one.identifier, two.identifier);
 70  0
                         if(result != 0) break;
 71  
                     } while (false);
 72  0
                     return -result;
 73  
                 }
 74  
             };
 75  
         }     
 76  
         public Comparator<DocumentValuedExtent> lessThan() {
 77  0
             return new Comparator<DocumentValuedExtent>() {
 78  0
                 public int compare(DocumentValuedExtent one, DocumentValuedExtent two) {
 79  0
                     int result = 0;
 80  
                     do {
 81  0
                         result = + Utility.compare(one.identifier, two.identifier);
 82  0
                         if(result != 0) break;
 83  
                     } while (false);
 84  0
                     return result;
 85  
                 }
 86  
             };
 87  
         }     
 88  
         public TypeReader<DocumentValuedExtent> orderedReader(ArrayInput _input) {
 89  0
             return new ShreddedReader(_input);
 90  
         }    
 91  
 
 92  
         public TypeReader<DocumentValuedExtent> orderedReader(ArrayInput _input, int bufferSize) {
 93  0
             return new ShreddedReader(_input, bufferSize);
 94  
         }    
 95  
         public OrderedWriter<DocumentValuedExtent> orderedWriter(ArrayOutput _output) {
 96  0
             ShreddedWriter w = new ShreddedWriter(_output);
 97  0
             return new OrderedWriterClass(w); 
 98  
         }                                    
 99  0
         public static class OrderedWriterClass extends OrderedWriter< DocumentValuedExtent > {
 100  0
             DocumentValuedExtent last = null;
 101  0
             ShreddedWriter shreddedWriter = null; 
 102  
             
 103  0
             public OrderedWriterClass(ShreddedWriter s) {
 104  0
                 this.shreddedWriter = s;
 105  0
             }
 106  
             
 107  
             public void process(DocumentValuedExtent object) throws IOException {
 108  0
                boolean processAll = false;
 109  0
                if (processAll || last == null || 0 != Utility.compare(object.identifier, last.identifier)) { processAll = true; shreddedWriter.processIdentifier(object.identifier); }
 110  0
                shreddedWriter.processTuple(object.extentName, object.begin, object.end, object.value);
 111  0
                last = object;
 112  0
             }           
 113  
                  
 114  
             public void close() throws IOException {
 115  0
                 shreddedWriter.close();
 116  0
             }
 117  
             
 118  
             public Class<DocumentValuedExtent> getInputClass() {
 119  0
                 return DocumentValuedExtent.class;
 120  
             }
 121  
         } 
 122  
         public ReaderSource<DocumentValuedExtent> orderedCombiner(Collection<TypeReader<DocumentValuedExtent>> readers, boolean closeOnExit) {
 123  0
             ArrayList<ShreddedReader> shreddedReaders = new ArrayList();
 124  
             
 125  0
             for (TypeReader<DocumentValuedExtent> reader : readers) {
 126  0
                 shreddedReaders.add((ShreddedReader)reader);
 127  
             }
 128  
             
 129  0
             return new ShreddedCombiner(shreddedReaders, closeOnExit);
 130  
         }                  
 131  
         public DocumentValuedExtent clone(DocumentValuedExtent object) {
 132  0
             DocumentValuedExtent result = new DocumentValuedExtent();
 133  0
             if (object == null) return result;
 134  0
             result.extentName = object.extentName; 
 135  0
             result.identifier = object.identifier; 
 136  0
             result.begin = object.begin; 
 137  0
             result.end = object.end; 
 138  0
             result.value = object.value; 
 139  0
             return result;
 140  
         }                 
 141  
         public Class<DocumentValuedExtent> getOrderedClass() {
 142  0
             return DocumentValuedExtent.class;
 143  
         }                           
 144  
         public String[] getOrderSpec() {
 145  0
             return new String[] {"+identifier"};
 146  
         }
 147  
 
 148  
         public static String getSpecString() {
 149  0
             return "+identifier";
 150  
         }
 151  
                            
 152  
         public interface ShreddedProcessor extends Step {
 153  
             public void processIdentifier(String identifier) throws IOException;
 154  
             public void processTuple(String extentName, int begin, int end, long value) throws IOException;
 155  
             public void close() throws IOException;
 156  
         }    
 157  
         public interface ShreddedSource extends Step {
 158  
         }                                              
 159  
         
 160  0
         public static class ShreddedWriter implements ShreddedProcessor {
 161  
             ArrayOutput output;
 162  0
             ShreddedBuffer buffer = new ShreddedBuffer();
 163  
             String lastIdentifier;
 164  0
             boolean lastFlush = false;
 165  
             
 166  0
             public ShreddedWriter(ArrayOutput output) {
 167  0
                 this.output = output;
 168  0
             }                        
 169  
             
 170  
             public void close() throws IOException {
 171  0
                 flush();
 172  0
             }
 173  
             
 174  
             public void processIdentifier(String identifier) {
 175  0
                 lastIdentifier = identifier;
 176  0
                 buffer.processIdentifier(identifier);
 177  0
             }
 178  
             public final void processTuple(String extentName, int begin, int end, long value) throws IOException {
 179  0
                 if (lastFlush) {
 180  0
                     if(buffer.identifiers.size() == 0) buffer.processIdentifier(lastIdentifier);
 181  0
                     lastFlush = false;
 182  
                 }
 183  0
                 buffer.processTuple(extentName, begin, end, value);
 184  0
                 if (buffer.isFull())
 185  0
                     flush();
 186  0
             }
 187  
             public final void flushTuples(int pauseIndex) throws IOException {
 188  
                 
 189  0
                 while (buffer.getReadIndex() < pauseIndex) {
 190  
                            
 191  0
                     output.writeString(buffer.getExtentName());
 192  0
                     output.writeInt(buffer.getBegin());
 193  0
                     output.writeInt(buffer.getEnd());
 194  0
                     output.writeLong(buffer.getValue());
 195  0
                     buffer.incrementTuple();
 196  
                 }
 197  0
             }  
 198  
             public final void flushIdentifier(int pauseIndex) throws IOException {
 199  0
                 while (buffer.getReadIndex() < pauseIndex) {
 200  0
                     int nextPause = buffer.getIdentifierEndIndex();
 201  0
                     int count = nextPause - buffer.getReadIndex();
 202  
                     
 203  0
                     output.writeString(buffer.getIdentifier());
 204  0
                     output.writeInt(count);
 205  0
                     buffer.incrementIdentifier();
 206  
                       
 207  0
                     flushTuples(nextPause);
 208  0
                     assert nextPause == buffer.getReadIndex();
 209  0
                 }
 210  0
             }
 211  
             public void flush() throws IOException { 
 212  0
                 flushIdentifier(buffer.getWriteIndex());
 213  0
                 buffer.reset(); 
 214  0
                 lastFlush = true;
 215  0
             }                           
 216  
         }
 217  0
         public static class ShreddedBuffer {
 218  0
             ArrayList<String> identifiers = new ArrayList();
 219  0
             ArrayList<Integer> identifierTupleIdx = new ArrayList();
 220  0
             int identifierReadIdx = 0;
 221  
                             
 222  
             String[] extentNames;
 223  
             int[] begins;
 224  
             int[] ends;
 225  
             long[] values;
 226  0
             int writeTupleIndex = 0;
 227  0
             int readTupleIndex = 0;
 228  
             int batchSize;
 229  
 
 230  0
             public ShreddedBuffer(int batchSize) {
 231  0
                 this.batchSize = batchSize;
 232  
 
 233  0
                 extentNames = new String[batchSize];
 234  0
                 begins = new int[batchSize];
 235  0
                 ends = new int[batchSize];
 236  0
                 values = new long[batchSize];
 237  0
             }                              
 238  
 
 239  
             public ShreddedBuffer() {    
 240  0
                 this(10000);
 241  0
             }                                                                                                                    
 242  
             
 243  
             public void processIdentifier(String identifier) {
 244  0
                 identifiers.add(identifier);
 245  0
                 identifierTupleIdx.add(writeTupleIndex);
 246  0
             }                                      
 247  
             public void processTuple(String extentName, int begin, int end, long value) {
 248  0
                 assert identifiers.size() > 0;
 249  0
                 extentNames[writeTupleIndex] = extentName;
 250  0
                 begins[writeTupleIndex] = begin;
 251  0
                 ends[writeTupleIndex] = end;
 252  0
                 values[writeTupleIndex] = value;
 253  0
                 writeTupleIndex++;
 254  0
             }
 255  
             public void resetData() {
 256  0
                 identifiers.clear();
 257  0
                 identifierTupleIdx.clear();
 258  0
                 writeTupleIndex = 0;
 259  0
             }                  
 260  
                                  
 261  
             public void resetRead() {
 262  0
                 readTupleIndex = 0;
 263  0
                 identifierReadIdx = 0;
 264  0
             } 
 265  
 
 266  
             public void reset() {
 267  0
                 resetData();
 268  0
                 resetRead();
 269  0
             } 
 270  
             public boolean isFull() {
 271  0
                 return writeTupleIndex >= batchSize;
 272  
             }
 273  
 
 274  
             public boolean isEmpty() {
 275  0
                 return writeTupleIndex == 0;
 276  
             }                          
 277  
 
 278  
             public boolean isAtEnd() {
 279  0
                 return readTupleIndex >= writeTupleIndex;
 280  
             }           
 281  
             public void incrementIdentifier() {
 282  0
                 identifierReadIdx++;  
 283  0
             }                                                                                              
 284  
 
 285  
             public void autoIncrementIdentifier() {
 286  0
                 while (readTupleIndex >= getIdentifierEndIndex() && readTupleIndex < writeTupleIndex)
 287  0
                     identifierReadIdx++;
 288  0
             }                 
 289  
             public void incrementTuple() {
 290  0
                 readTupleIndex++;
 291  0
             }                    
 292  
             public int getIdentifierEndIndex() {
 293  0
                 if ((identifierReadIdx+1) >= identifierTupleIdx.size())
 294  0
                     return writeTupleIndex;
 295  0
                 return identifierTupleIdx.get(identifierReadIdx+1);
 296  
             }
 297  
             public int getReadIndex() {
 298  0
                 return readTupleIndex;
 299  
             }   
 300  
 
 301  
             public int getWriteIndex() {
 302  0
                 return writeTupleIndex;
 303  
             } 
 304  
             public String getIdentifier() {
 305  0
                 assert readTupleIndex < writeTupleIndex;
 306  0
                 assert identifierReadIdx < identifiers.size();
 307  
                 
 308  0
                 return identifiers.get(identifierReadIdx);
 309  
             }
 310  
             public String getExtentName() {
 311  0
                 assert readTupleIndex < writeTupleIndex;
 312  0
                 return extentNames[readTupleIndex];
 313  
             }                                         
 314  
             public int getBegin() {
 315  0
                 assert readTupleIndex < writeTupleIndex;
 316  0
                 return begins[readTupleIndex];
 317  
             }                                         
 318  
             public int getEnd() {
 319  0
                 assert readTupleIndex < writeTupleIndex;
 320  0
                 return ends[readTupleIndex];
 321  
             }                                         
 322  
             public long getValue() {
 323  0
                 assert readTupleIndex < writeTupleIndex;
 324  0
                 return values[readTupleIndex];
 325  
             }                                         
 326  
             public void copyTuples(int endIndex, ShreddedProcessor output) throws IOException {
 327  0
                 while (getReadIndex() < endIndex) {
 328  0
                    output.processTuple(getExtentName(), getBegin(), getEnd(), getValue());
 329  0
                    incrementTuple();
 330  
                 }
 331  0
             }                                                                           
 332  
             public void copyUntilIndexIdentifier(int endIndex, ShreddedProcessor output) throws IOException {
 333  0
                 while (getReadIndex() < endIndex) {
 334  0
                     output.processIdentifier(getIdentifier());
 335  0
                     assert getIdentifierEndIndex() <= endIndex;
 336  0
                     copyTuples(getIdentifierEndIndex(), output);
 337  0
                     incrementIdentifier();
 338  
                 }
 339  0
             }  
 340  
             public void copyUntilIdentifier(ShreddedBuffer other, ShreddedProcessor output) throws IOException {
 341  0
                 while (!isAtEnd()) {
 342  0
                     if (other != null) {   
 343  0
                         assert !other.isAtEnd();
 344  0
                         int c = + Utility.compare(getIdentifier(), other.getIdentifier());
 345  
                     
 346  0
                         if (c > 0) {
 347  0
                             break;   
 348  
                         }
 349  
                         
 350  0
                         output.processIdentifier(getIdentifier());
 351  
                                       
 352  0
                         copyTuples(getIdentifierEndIndex(), output);
 353  0
                     } else {
 354  0
                         output.processIdentifier(getIdentifier());
 355  0
                         copyTuples(getIdentifierEndIndex(), output);
 356  
                     }
 357  0
                     incrementIdentifier();  
 358  
                     
 359  
                
 360  
                 }
 361  0
             }
 362  
             public void copyUntil(ShreddedBuffer other, ShreddedProcessor output) throws IOException {
 363  0
                 copyUntilIdentifier(other, output);
 364  0
             }
 365  
             
 366  
         }                         
 367  0
         public static class ShreddedCombiner implements ReaderSource<DocumentValuedExtent>, ShreddedSource {   
 368  
             public ShreddedProcessor processor;
 369  
             Collection<ShreddedReader> readers;       
 370  0
             boolean closeOnExit = false;
 371  0
             boolean uninitialized = true;
 372  0
             PriorityQueue<ShreddedReader> queue = new PriorityQueue<ShreddedReader>();
 373  
             
 374  0
             public ShreddedCombiner(Collection<ShreddedReader> readers, boolean closeOnExit) {
 375  0
                 this.readers = readers;                                                       
 376  0
                 this.closeOnExit = closeOnExit;
 377  0
             }
 378  
                                   
 379  
             public void setProcessor(Step processor) throws IncompatibleProcessorException {  
 380  0
                 if (processor instanceof ShreddedProcessor) {
 381  0
                     this.processor = new DuplicateEliminator((ShreddedProcessor) processor);
 382  0
                 } else if (processor instanceof DocumentValuedExtent.Processor) {
 383  0
                     this.processor = new DuplicateEliminator(new TupleUnshredder((DocumentValuedExtent.Processor) processor));
 384  0
                 } else if (processor instanceof org.galagosearch.tupleflow.Processor) {
 385  0
                     this.processor = new DuplicateEliminator(new TupleUnshredder((org.galagosearch.tupleflow.Processor<DocumentValuedExtent>) processor));
 386  
                 } else {
 387  0
                     throw new IncompatibleProcessorException(processor.getClass().getName() + " is not supported by " + this.getClass().getName());                                                                       
 388  
                 }
 389  0
             }                                
 390  
             
 391  
             public Class<DocumentValuedExtent> getOutputClass() {
 392  0
                 return DocumentValuedExtent.class;
 393  
             }
 394  
             
 395  
             public void initialize() throws IOException {
 396  0
                 for (ShreddedReader reader : readers) {
 397  0
                     reader.fill();                                        
 398  
                     
 399  0
                     if (!reader.getBuffer().isAtEnd())
 400  0
                         queue.add(reader);
 401  
                 }   
 402  
 
 403  0
                 uninitialized = false;
 404  0
             }
 405  
 
 406  
             public void run() throws IOException {
 407  0
                 initialize();
 408  
                
 409  0
                 while (queue.size() > 0) {
 410  0
                     ShreddedReader top = queue.poll();
 411  0
                     ShreddedReader next = null;
 412  0
                     ShreddedBuffer nextBuffer = null; 
 413  
                     
 414  0
                     assert !top.getBuffer().isAtEnd();
 415  
                                                   
 416  0
                     if (queue.size() > 0) {
 417  0
                         next = queue.peek();
 418  0
                         nextBuffer = next.getBuffer();
 419  0
                         assert !nextBuffer.isAtEnd();
 420  
                     }
 421  
                     
 422  0
                     top.getBuffer().copyUntil(nextBuffer, processor);
 423  0
                     if (top.getBuffer().isAtEnd())
 424  0
                         top.fill();                 
 425  
                         
 426  0
                     if (!top.getBuffer().isAtEnd())
 427  0
                         queue.add(top);
 428  0
                 }              
 429  
                 
 430  0
                 if (closeOnExit)
 431  0
                     processor.close();
 432  0
             }
 433  
 
 434  
             public DocumentValuedExtent read() throws IOException {
 435  0
                 if (uninitialized)
 436  0
                     initialize();
 437  
 
 438  0
                 DocumentValuedExtent result = null;
 439  
 
 440  0
                 while (queue.size() > 0) {
 441  0
                     ShreddedReader top = queue.poll();
 442  0
                     result = top.read();
 443  
 
 444  0
                     if (result != null) {
 445  0
                         if (top.getBuffer().isAtEnd())
 446  0
                             top.fill();
 447  
 
 448  0
                         queue.offer(top);
 449  0
                         break;
 450  
                     } 
 451  0
                 }
 452  
 
 453  0
                 return result;
 454  
             }
 455  
         } 
 456  0
         public static class ShreddedReader implements Step, Comparable<ShreddedReader>, TypeReader<DocumentValuedExtent>, ShreddedSource {      
 457  
             public ShreddedProcessor processor;
 458  
             ShreddedBuffer buffer;
 459  0
             DocumentValuedExtent last = new DocumentValuedExtent();         
 460  0
             long updateIdentifierCount = -1;
 461  0
             long tupleCount = 0;
 462  0
             long bufferStartCount = 0;  
 463  
             ArrayInput input;
 464  
             
 465  0
             public ShreddedReader(ArrayInput input) {
 466  0
                 this.input = input; 
 467  0
                 this.buffer = new ShreddedBuffer();
 468  0
             }                               
 469  
             
 470  0
             public ShreddedReader(ArrayInput input, int bufferSize) { 
 471  0
                 this.input = input;
 472  0
                 this.buffer = new ShreddedBuffer(bufferSize);
 473  0
             }
 474  
                  
 475  
             public final int compareTo(ShreddedReader other) {
 476  0
                 ShreddedBuffer otherBuffer = other.getBuffer();
 477  
                 
 478  0
                 if (buffer.isAtEnd() && otherBuffer.isAtEnd()) {
 479  0
                     return 0;                 
 480  0
                 } else if (buffer.isAtEnd()) {
 481  0
                     return -1;
 482  0
                 } else if (otherBuffer.isAtEnd()) {
 483  0
                     return 1;
 484  
                 }
 485  
                                    
 486  0
                 int result = 0;
 487  
                 do {
 488  0
                     result = + Utility.compare(buffer.getIdentifier(), otherBuffer.getIdentifier());
 489  0
                     if(result != 0) break;
 490  
                 } while (false);                                             
 491  
                 
 492  0
                 return result;
 493  
             }
 494  
             
 495  
             public final ShreddedBuffer getBuffer() {
 496  0
                 return buffer;
 497  
             }                
 498  
             
 499  
             public final DocumentValuedExtent read() throws IOException {
 500  0
                 if (buffer.isAtEnd()) {
 501  0
                     fill();             
 502  
                 
 503  0
                     if (buffer.isAtEnd()) {
 504  0
                         return null;
 505  
                     }
 506  
                 }
 507  
                       
 508  0
                 assert !buffer.isAtEnd();
 509  0
                 DocumentValuedExtent result = new DocumentValuedExtent();
 510  
                 
 511  0
                 result.identifier = buffer.getIdentifier();
 512  0
                 result.extentName = buffer.getExtentName();
 513  0
                 result.begin = buffer.getBegin();
 514  0
                 result.end = buffer.getEnd();
 515  0
                 result.value = buffer.getValue();
 516  
                 
 517  0
                 buffer.incrementTuple();
 518  0
                 buffer.autoIncrementIdentifier();
 519  
                 
 520  0
                 return result;
 521  
             }           
 522  
             
 523  
             public final void fill() throws IOException {
 524  
                 try {   
 525  0
                     buffer.reset();
 526  
                     
 527  0
                     if (tupleCount != 0) {
 528  
                                                       
 529  0
                         if(updateIdentifierCount - tupleCount > 0) {
 530  0
                             buffer.identifiers.add(last.identifier);
 531  0
                             buffer.identifierTupleIdx.add((int) (updateIdentifierCount - tupleCount));
 532  
                         }
 533  0
                         bufferStartCount = tupleCount;
 534  
                     }
 535  
                     
 536  0
                     while (!buffer.isFull()) {
 537  0
                         updateIdentifier();
 538  0
                         buffer.processTuple(input.readString(), input.readInt(), input.readInt(), input.readLong());
 539  0
                         tupleCount++;
 540  
                     }
 541  0
                 } catch(EOFException e) {}
 542  0
             }
 543  
 
 544  
             public final void updateIdentifier() throws IOException {
 545  0
                 if (updateIdentifierCount > tupleCount)
 546  0
                     return;
 547  
                      
 548  0
                 last.identifier = input.readString();
 549  0
                 updateIdentifierCount = tupleCount + input.readInt();
 550  
                                       
 551  0
                 buffer.processIdentifier(last.identifier);
 552  0
             }
 553  
 
 554  
             public void run() throws IOException {
 555  
                 while (true) {
 556  0
                     fill();
 557  
                     
 558  0
                     if (buffer.isAtEnd())
 559  0
                         break;
 560  
                     
 561  0
                     buffer.copyUntil(null, processor);
 562  
                 }      
 563  0
                 processor.close();
 564  0
             }
 565  
             
 566  
             public void setProcessor(Step processor) throws IncompatibleProcessorException {  
 567  0
                 if (processor instanceof ShreddedProcessor) {
 568  0
                     this.processor = new DuplicateEliminator((ShreddedProcessor) processor);
 569  0
                 } else if (processor instanceof DocumentValuedExtent.Processor) {
 570  0
                     this.processor = new DuplicateEliminator(new TupleUnshredder((DocumentValuedExtent.Processor) processor));
 571  0
                 } else if (processor instanceof org.galagosearch.tupleflow.Processor) {
 572  0
                     this.processor = new DuplicateEliminator(new TupleUnshredder((org.galagosearch.tupleflow.Processor<DocumentValuedExtent>) processor));
 573  
                 } else {
 574  0
                     throw new IncompatibleProcessorException(processor.getClass().getName() + " is not supported by " + this.getClass().getName());                                                                       
 575  
                 }
 576  0
             }                                
 577  
             
 578  
             public Class<DocumentValuedExtent> getOutputClass() {
 579  0
                 return DocumentValuedExtent.class;
 580  
             }                
 581  
         }
 582  
         
 583  
         public static class DuplicateEliminator implements ShreddedProcessor {
 584  
             public ShreddedProcessor processor;
 585  0
             DocumentValuedExtent last = new DocumentValuedExtent();
 586  0
             boolean identifierProcess = true;
 587  
                                            
 588  0
             public DuplicateEliminator() {}
 589  0
             public DuplicateEliminator(ShreddedProcessor processor) {
 590  0
                 this.processor = processor;
 591  0
             }
 592  
             
 593  
             public void setShreddedProcessor(ShreddedProcessor processor) {
 594  0
                 this.processor = processor;
 595  0
             }
 596  
 
 597  
             public void processIdentifier(String identifier) throws IOException {  
 598  0
                 if (identifierProcess || Utility.compare(identifier, last.identifier) != 0) {
 599  0
                     last.identifier = identifier;
 600  0
                     processor.processIdentifier(identifier);
 601  0
                     identifierProcess = false;
 602  
                 }
 603  0
             }  
 604  
             
 605  
             public void resetIdentifier() {
 606  0
                  identifierProcess = true;
 607  0
             }                                                
 608  
                                
 609  
             public void processTuple(String extentName, int begin, int end, long value) throws IOException {
 610  0
                 processor.processTuple(extentName, begin, end, value);
 611  0
             } 
 612  
             
 613  
             public void close() throws IOException {
 614  0
                 processor.close();
 615  0
             }                    
 616  
         }
 617  
         public static class TupleUnshredder implements ShreddedProcessor {
 618  0
             DocumentValuedExtent last = new DocumentValuedExtent();
 619  
             public org.galagosearch.tupleflow.Processor<DocumentValuedExtent> processor;                               
 620  
             
 621  0
             public TupleUnshredder(DocumentValuedExtent.Processor processor) {
 622  0
                 this.processor = processor;
 623  0
             }         
 624  
             
 625  0
             public TupleUnshredder(org.galagosearch.tupleflow.Processor<DocumentValuedExtent> processor) {
 626  0
                 this.processor = processor;
 627  0
             }
 628  
             
 629  
             public DocumentValuedExtent clone(DocumentValuedExtent object) {
 630  0
                 DocumentValuedExtent result = new DocumentValuedExtent();
 631  0
                 if (object == null) return result;
 632  0
                 result.extentName = object.extentName; 
 633  0
                 result.identifier = object.identifier; 
 634  0
                 result.begin = object.begin; 
 635  0
                 result.end = object.end; 
 636  0
                 result.value = object.value; 
 637  0
                 return result;
 638  
             }                 
 639  
             
 640  
             public void processIdentifier(String identifier) throws IOException {
 641  0
                 last.identifier = identifier;
 642  0
             }   
 643  
                 
 644  
             
 645  
             public void processTuple(String extentName, int begin, int end, long value) throws IOException {
 646  0
                 last.extentName = extentName;
 647  0
                 last.begin = begin;
 648  0
                 last.end = end;
 649  0
                 last.value = value;
 650  0
                 processor.process(clone(last));
 651  0
             }               
 652  
             
 653  
             public void close() throws IOException {
 654  0
                 processor.close();
 655  0
             }
 656  
         }     
 657  0
         public static class TupleShredder implements Processor {
 658  0
             DocumentValuedExtent last = new DocumentValuedExtent();
 659  
             public ShreddedProcessor processor;
 660  
             
 661  0
             public TupleShredder(ShreddedProcessor processor) {
 662  0
                 this.processor = processor;
 663  0
             }                              
 664  
             
 665  
             public DocumentValuedExtent clone(DocumentValuedExtent object) {
 666  0
                 DocumentValuedExtent result = new DocumentValuedExtent();
 667  0
                 if (object == null) return result;
 668  0
                 result.extentName = object.extentName; 
 669  0
                 result.identifier = object.identifier; 
 670  0
                 result.begin = object.begin; 
 671  0
                 result.end = object.end; 
 672  0
                 result.value = object.value; 
 673  0
                 return result;
 674  
             }                 
 675  
             
 676  
             public void process(DocumentValuedExtent object) throws IOException {                                                                                                                                                   
 677  0
                 boolean processAll = false;
 678  0
                 if(last == null || Utility.compare(last.identifier, object.identifier) != 0 || processAll) { processor.processIdentifier(object.identifier); processAll = true; }
 679  0
                 processor.processTuple(object.extentName, object.begin, object.end, object.value);                                         
 680  0
             }
 681  
                           
 682  
             public Class<DocumentValuedExtent> getInputClass() {
 683  0
                 return DocumentValuedExtent.class;
 684  
             }
 685  
             
 686  
             public void close() throws IOException {
 687  0
                 processor.close();
 688  0
             }                     
 689  
         }
 690  
     } 
 691  
 }