-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from pmia712/closest-shoreline-distance
Closest shoreline distance
- Loading branch information
Showing
6 changed files
with
367 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
GlobalQuakeCore/src/main/java/globalquake/utils/LookupTableIO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package globalquake.utils; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import globalquake.core.regions.Regions; | ||
|
||
public class LookupTableIO { | ||
public static boolean exportLookupTableToFile() { | ||
List<HashMap<String, Double>> lookupTables = Regions.generateLookupTablesInParallel(); | ||
HashMap<String, Double> lookupTable = new HashMap<>(); | ||
for(HashMap<String, Double> singleLT : lookupTables) { | ||
lookupTable.putAll(singleLT); | ||
} | ||
|
||
return performExport(lookupTable); | ||
} | ||
|
||
public static boolean exportLookupTableToFile(HashMap<String, Double> lookupTable) throws IOException { | ||
return performExport(lookupTable); | ||
} | ||
|
||
private static boolean performExport(HashMap<String, Double> lookupTable) { | ||
String path = "lookup/lookupTable.dat"; | ||
URL resource = ClassLoader.getSystemClassLoader().getResource(path); | ||
|
||
try{ | ||
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("lookupTable.dat")); | ||
output.writeObject(lookupTable); | ||
output.close(); | ||
} catch (Exception e){ | ||
System.err.println("Unable to save a lookup table! " + e); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static HashMap<String, Double> importLookupTableFromFile() throws IOException { | ||
String path = "lookup/lookupTable.dat"; | ||
URL resource = ClassLoader.getSystemClassLoader().getResource(path); | ||
|
||
if (resource == null) { | ||
System.err.printf("Unable to load a lookup table: %s", path); | ||
return null; | ||
} | ||
|
||
HashMap<String, Double> lookupTable; | ||
try{ | ||
ObjectInput input = new ObjectInputStream(resource.openStream()); | ||
lookupTable = (HashMap<String, Double>) input.readObject(); | ||
} catch (IOException | ClassNotFoundException e) { | ||
throw new IOException("Unable to load stream of a lookup table! ", e); | ||
} | ||
|
||
return lookupTable; | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.