From 380f92e105e695ffe93021ffce321364759a90c5 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 6 Mar 2023 21:32:44 -0600 Subject: [PATCH] reformat fullDataMetaFile --- .../sources/SparseFullDataSource.java | 1 - .../file/fullDatafile/FullDataMetaFile.java | 112 +++++++++--------- 2 files changed, 56 insertions(+), 57 deletions(-) diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java index 95846ecf3..19d010f07 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java @@ -405,7 +405,6 @@ public class SparseFullDataSource implements IIncompleteFullDataSource // get the column data for (int x = 0; x < dataColumn.length; x++) { - if (dataColumn[x].length != 0) { // read in the data columns diff --git a/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java b/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java index f738f7c4b..e50bbeff0 100644 --- a/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java +++ b/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java @@ -190,71 +190,71 @@ public class FullDataMetaFile extends AbstractMetaDataContainerFile if (!this.doesFileExist) { this.handler.onCreateDataFile(this) - .thenApply((data) -> + .thenApply((data) -> + { + this.metaData = makeMetaData(data); + return data; + }) + .thenApply((data) -> this.handler.onDataFileLoaded(data, this.metaData, this::saveChanges, this::applyWriteQueue)) + .whenComplete((fullDataSource, exception) -> + { + if (exception != null) { - this.metaData = makeMetaData(data); - return data; - }) - .thenApply((data) -> this.handler.onDataFileLoaded(data, this.metaData, this::saveChanges, this::applyWriteQueue)) - .whenComplete((fullDataSource, exception) -> + LOGGER.error("Uncaught error on creation "+this.file+": ", exception); + future.complete(null); + this.data.set(null); + } + else { - if (exception != null) - { - LOGGER.error("Uncaught error on creation "+this.file+": ", exception); - future.complete(null); - this.data.set(null); - } - else - { - future.complete(fullDataSource); - new DataObjTracker(fullDataSource); - this.data.set(new SoftReference<>(fullDataSource)); - } - }); + future.complete(fullDataSource); + new DataObjTracker(fullDataSource); + this.data.set(new SoftReference<>(fullDataSource)); + } + }); } else { CompletableFuture.supplyAsync(() -> + { + if (this.metaData == null) { - if (this.metaData == null) - { - throw new IllegalStateException("Meta data not loaded!"); // TODO should this be a CompletionException? - } - - // Load the file. - IFullDataSource data; - try (FileInputStream inputStream = this.getDataContent()) - { - data = this.loader.loadData(this, inputStream, this.level); - } - catch (Exception e) - { - // can happen if there is a missing file or the file was incorrectly formatted - throw new CompletionException(e); - } - - // Apply the write queue - LodUtil.assertTrue(this.inCacheWriteAccessFuture.get() == null, - "No one should be writing to the cache while we are in the process of " + - "loading one into the cache! Is this a deadlock?"); - - data = this.handler.onDataFileLoaded(data, this.metaData, this::saveChanges, this::applyWriteQueue); - return data; - }, this.handler.getIOExecutor()) - .exceptionally((e) -> + throw new IllegalStateException("Meta data not loaded!"); // TODO should this be a CompletionException? + } + + // Load the file. + IFullDataSource data; + try (FileInputStream inputStream = this.getDataContent()) { - LOGGER.error("Error loading file {}: ", this.file, e); - this.data.set(null); - - future.completeExceptionally(e); - return null; // the return value here doesn't matter - }) - .whenComplete((dataSource, e) -> + data = this.loader.loadData(this, inputStream, this.level); + } + catch (Exception e) { - future.complete(dataSource); - new DataObjTracker(dataSource); - this.data.set(new SoftReference<>(dataSource)); - }); + // can happen if there is a missing file or the file was incorrectly formatted + throw new CompletionException(e); + } + + // Apply the write queue + LodUtil.assertTrue(this.inCacheWriteAccessFuture.get() == null, + "No one should be writing to the cache while we are in the process of " + + "loading one into the cache! Is this a deadlock?"); + + data = this.handler.onDataFileLoaded(data, this.metaData, this::saveChanges, this::applyWriteQueue); + return data; + }, this.handler.getIOExecutor()) + .exceptionally((e) -> + { + LOGGER.error("Error loading file {}: ", this.file, e); + this.data.set(null); + + future.completeExceptionally(e); + return null; // the return value here doesn't matter + }) + .whenComplete((dataSource, e) -> + { + future.complete(dataSource); + new DataObjTracker(dataSource); + this.data.set(new SoftReference<>(dataSource)); + }); } // Would use CompletableFuture.completeAsync(...), But, java 8 doesn't have it! :(