View Javadoc

1   /*
2    * #%L
3    * Bitrepository Reference Pillar
4    * %%
5    * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 2.1 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package org.bitrepository.pillar.cache.database;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.bitrepository.bitrepositoryelements.ChecksumDataForChecksumSpecTYPE;
28  import org.bitrepository.common.utils.Base16Utils;
29  import org.bitrepository.common.utils.CalendarUtils;
30  import org.bitrepository.pillar.cache.ChecksumEntry;
31  
32  /**
33   * Container of the results of a checksum database exctraction.
34   */
35  public class ExtractedChecksumResultSet {
36      /** The list of checksum entries.*/
37      protected final List<ChecksumDataForChecksumSpecTYPE> entries;
38      /** Whether more results has been found.*/
39      protected boolean moreEntriesReported;
40      
41      /**
42       * Constructor.
43       */
44      public ExtractedChecksumResultSet() {
45          entries = new ArrayList<ChecksumDataForChecksumSpecTYPE>();
46          moreEntriesReported = false;
47      }
48      
49      /**
50       * Adds an entry to this result set. 
51       * @param entry The entry to add.
52       */
53      public void insertChecksumEntry(ChecksumDataForChecksumSpecTYPE entry) {
54          entries.add(entry);
55      }
56      
57      /**
58       * Adds an entry to this result set. 
59       * @param entry The entry to add.
60       */
61      public void insertChecksumEntry(ChecksumEntry entry) {
62          ChecksumDataForChecksumSpecTYPE res = new ChecksumDataForChecksumSpecTYPE();
63          res.setCalculationTimestamp(CalendarUtils.getXmlGregorianCalendar(entry.getCalculationDate()));
64          res.setChecksumValue(Base16Utils.encodeBase16(entry.getChecksum()));
65          res.setFileID(entry.getFileId());
66          entries.add(res);
67      }
68      
69      /**
70       * @return A list with all the reported entries.
71       */
72      public List<ChecksumDataForChecksumSpecTYPE> getEntries() {
73          return new ArrayList<ChecksumDataForChecksumSpecTYPE>(entries);
74      }
75      
76      /**
77       * Set that more entries has been found. 
78       */
79      public void reportMoreEntriesFound() {
80          moreEntriesReported = true;
81      }
82      
83      /**
84       * @return Whether it has been reported, that more results exists.
85       */
86      public boolean hasMoreEntries() {
87          return moreEntriesReported;
88      }
89  }