Java Reference
In-Depth Information
method that reads all the records from file, and along the way populates our map of UPC
numbers to file locations, along with the getDVDs method that calls it:
113 public List<DVD> getDvds() throws IOException {
114 return getDvdList(false);
115 }
Note The getDvds method in the DvdFileAccess class uses a different naming convention from the
getDVDs method specified in the DBClient interface. We are able to do this because DvdFileAccess is the
class behind the façade—it does not implement DBClient . We have made a design decision to use the Sun
code conventions for the method names in our nonpublic classes, even though this means that they do not
match perfectly with the method names in the public classes and interfaces. There is a trade-off here—a
programmer working with the DvdFileAccess class may appreciate working with class and method names
that conform to one convention, but changing the code convention between the public class and the nonpub-
lic class could also be slightly confusing for a junior programmer.
130 private List<DVD> getDvdList(boolean buildRecordNumbers)
131 throws IOException {
132 log.entering("DvdFileAccess", "getDvdList", buildRecordNumbers);
133 List<DVD> returnValue = new ArrayList<DVD>();
134
135 if (buildRecordNumbers) {
136 recordNumbersLock.writeLock().lock();
137 }
138
139 try {
140 for (long locationInFile = 0;
141 locationInFile < database.length();
142 locationInFile += DVD.RECORD_LENGTH) {
143 DVD dvd = retrieveDvd(locationInFile);
144 log.fine("retrieving record at " + locationInFile);
145 if (dvd == null) {
146 log.fine("found deleted record ");
147 } else {
148 log.fine("found record " + dvd.getUPC());
149 if (buildRecordNumbers) {
150 recordNumbers.put(dvd.getUPC(), locationInFile);
151 }
152 returnValue.add(dvd);
153 }
154 }
155 } finally {
156 if (buildRecordNumbers) {
157 recordNumbersLock.writeLock().unlock();
Search WWH ::




Custom Search