Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkm committed Jan 9, 2024
1 parent 8aa3bca commit 6971814
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ca.bc.gov.nrs.vdyp.common_calculators;

import java.lang.Math;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.*;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.GrowthInterceptMaximumException;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.GrowthInterceptMinimumException;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.LessThan13Exception;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.NoAnswerException;

/* @formatter:off */
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.*;

import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.GrowthInterceptTotalException;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.LessThan13Exception;
import ca.bc.gov.nrs.vdyp.common_calculators.custom_exceptions.NoAnswerException;

/* @formatter:off */
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ca.bc.gov.nrs.vdyp.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import ca.bc.gov.nrs.vdyp.common.HoldFirst;
import ca.bc.gov.nrs.vdyp.model.Coefficients;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.IntFunction;

import ca.bc.gov.nrs.vdyp.model.Coefficients;
import ca.bc.gov.nrs.vdyp.model.MatrixMap2;
import ca.bc.gov.nrs.vdyp.model.MatrixMap2Impl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.model.GenusDefinition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package ca.bc.gov.nrs.vdyp.io.write;

import java.io.*;
import java.util.*;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Stream;

import ca.bc.gov.nrs.vdyp.common.ControlKeys;
import ca.bc.gov.nrs.vdyp.common.Utils;
import ca.bc.gov.nrs.vdyp.common_calculators.BaseAreaTreeDensityDiameter;
import ca.bc.gov.nrs.vdyp.io.FileResolver;
import ca.bc.gov.nrs.vdyp.io.parse.GenusDefinitionParser;
import ca.bc.gov.nrs.vdyp.model.*;
import ca.bc.gov.nrs.vdyp.model.BaseVdypSpecies;
import ca.bc.gov.nrs.vdyp.model.FipMode;
import ca.bc.gov.nrs.vdyp.model.Layer;
import ca.bc.gov.nrs.vdyp.model.UtilizationClass;
import ca.bc.gov.nrs.vdyp.model.VdypLayer;
import ca.bc.gov.nrs.vdyp.model.VdypPolygon;
import ca.bc.gov.nrs.vdyp.model.VdypSpecies;
import ca.bc.gov.nrs.vdyp.model.VdypUtilizationHolder;

/**
* Write files to be input into VRI Adjust.
Expand Down Expand Up @@ -50,8 +63,6 @@ public class VriAdjustInputWriter implements Closeable {

static final String END_RECORD_FORMAT = POLY_IDENTIFIER_FORMAT + " \n";

boolean haveWrittenSpec = false;

/**
* Create a writer for VRI Adjust input files using provided OutputStreams. The
* Streams will be closed when the writer is closed.
Expand Down Expand Up @@ -125,7 +136,6 @@ void writePolygon(VdypPolygon polygon) throws IOException {
* @throws IOException
*/
void writeSpecies(VdypLayer layer, VdypSpecies spec) throws IOException {
haveWrittenSpec = true;
// Ensure we have a list of 4 distribution entries
var specDistributionEntries = Stream.concat(
spec.getSpeciesPercent().entrySet().stream().sorted(Utils.compareUsing(Entry::getValue)),
Expand Down Expand Up @@ -236,12 +246,11 @@ void writeUtilization(VdypLayer layer, VdypUtilizationHolder utils) throws IOExc
public void writePolygonWithSpeciesAndUtilization(VdypPolygon polygon) throws IOException {

writePolygon(polygon);
polygon.getLayers().values();
for (var layer : polygon.getLayers().values()) {
writeUtilization(layer, layer);
List<VdypSpecies> specs = new ArrayList<>(layer.getSpecies().size());
specs.addAll(layer.getSpecies().values());
specs.sort(Utils.compareUsing((VdypSpecies x) -> x.getGenus()));
specs.sort(Utils.compareUsing(BaseVdypSpecies::getGenus));
for (var species : specs) {
writeSpecies(layer, species);
writeUtilization(layer, species);
Expand Down Expand Up @@ -270,9 +279,6 @@ void writeFormat(OutputStream os, String format, Object... params) throws IOExce
@Override
public void close() throws IOException {
polygonFile.close();
if (haveWrittenSpec) {
// writeFormat(speciesFile, "\n");
}
speciesFile.close();
utilizationFile.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static void populateControlMapBec(Map<String, Object> controlMap) {
populateControlMapBec(controlMap, "B1", "B2");
}

@SuppressWarnings("unused")
private static BecDefinition makeBec(String id, Region region, String name) {
return new BecDefinition(id, region, name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import ca.bc.gov.nrs.vdyp.io.parse.ControlMapModifier;
import ca.bc.gov.nrs.vdyp.io.parse.DecayEquationGroupParser;
import ca.bc.gov.nrs.vdyp.io.parse.DefaultEquationNumberParser;
import ca.bc.gov.nrs.vdyp.io.parse.EquationModifierParser;
import ca.bc.gov.nrs.vdyp.io.parse.GenusDefinitionParser;
import ca.bc.gov.nrs.vdyp.io.parse.HLCoefficientParser;
import ca.bc.gov.nrs.vdyp.io.parse.HLNonprimaryCoefficientParser;
import ca.bc.gov.nrs.vdyp.io.parse.ResourceParseException;
import ca.bc.gov.nrs.vdyp.io.parse.SiteCurveAgeMaximumParser;
import ca.bc.gov.nrs.vdyp.io.parse.SiteCurveParser;
import ca.bc.gov.nrs.vdyp.io.parse.SmallComponentBaseAreaParser;
Expand All @@ -45,10 +49,6 @@
import ca.bc.gov.nrs.vdyp.io.parse.VolumeNetDecayParser;
import ca.bc.gov.nrs.vdyp.io.parse.VolumeNetDecayWasteParser;
import ca.bc.gov.nrs.vdyp.model.JProgram;
import ca.bc.gov.nrs.vdyp.io.parse.EquationModifierParser;
import ca.bc.gov.nrs.vdyp.io.parse.HLCoefficientParser;
import ca.bc.gov.nrs.vdyp.io.parse.HLNonprimaryCoefficientParser;
import ca.bc.gov.nrs.vdyp.io.parse.ResourceParseException;

/**
* Parser for FIP control files
Expand All @@ -57,6 +57,7 @@
*
*/
public class FipControlParser {
@SuppressWarnings("unused")
private static final Logger log = LoggerFactory.getLogger(FipControlParser.class);

public static final String FIP_YIELD_POLY_INPUT = FipPolygonParser.CONTROL_KEY;
Expand Down
Loading

0 comments on commit 6971814

Please sign in to comment.