Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Arrays;
- import java.math.BigDecimal;
- import java.lang.System;
- import java.lang.Exception;
- public class VetoParser {
- public static VetoSet[] interpBetweenVetoSets(VetoSet[] input, int power, int numSets, int numPoints) throws Exception {
- VetoSet[] interpInput = Interpolate.interpVetoArray(input, power, numPoints);
- for(int i = 0; i < input.length; i++) {
- System.out.println(input[i].getVetoPairs().length);
- }
- for(int i = 0; i < interpInput.length; i++) {
- System.out.println(interpInput[i].getVetoPairs().length);
- }
- BigDecimal[] depths = getDepthsOfVetoSets(interpInput);
- BigDecimal[] interpDepths = interpDepthArray(depths, power, numSets);
- Pair[][] rearrangedPairs = rearrangeVetoSets(interpInput);
- Pair[][] interpArray = new Pair[rearrangedPairs[0].length][rearrangedPairs.length];
- for(int i = 0; i < interpArray.length; i++)
- interpArray[i] = Interpolate.fixValues(rearrangedPairs[i], power, numSets);
- Pair[][] resultPairArray = rotatePairArray(interpArray);
- List<VetoSet> resultList = new LinkedList<VetoSet>();
- for(int i = 0; i < resultPairArray.length; i++)
- resultList.add(new VetoSet(interpDepths[i], resultPairArray[i]));
- VetoSet[] result = new VetoSet[resultList.size()];
- resultList.toArray(result);
- return result;
- }
- private static BigDecimal[] interpDepthArray(BigDecimal[] input, int power, int numPoints) {
- Pair[] depthPairArray = new Pair[input.length];
- for(int i = 0; i < input.length; i++)
- depthPairArray[i] = new Pair(new BigDecimal(i), input[i]);
- return Utility.unzipSnd(Interpolate.fixValues(depthPairArray, power, numPoints));
- }
- private static BigDecimal[] getDepthsOfVetoSets(VetoSet[] input) {
- List<BigDecimal> depthList = new LinkedList<BigDecimal>();
- for(VetoSet v : input)
- depthList.add(v.getDepth());
- BigDecimal[] depthArray = new BigDecimal[depthList.size()];
- depthList.toArray(depthArray);
- return depthArray;
- }
- private static Pair[][] rearrangeVetoSets(VetoSet[] input) throws Exception {
- return rotatePairArray(vetoSetToPairArray(input));
- }
- private static Pair[][] rotatePairArray(Pair[][] input) {
- Pair[][] result = new Pair[input.length][input[0].length];
- for(int x = 0; x < input.length; x++) {
- for(int y = 0; y < input[0].length; y++) {
- System.out.println("Switched: " + x + ", " + y);
- result[x][y] = input[y][x];
- }
- }
- return result;
- }
- private static Pair[][] vetoSetToPairArray(VetoSet[] input) throws Exception {
- if(!validVetoSetArray(input)) { throw new Exception("Bad VSA"); }
- Pair[][] pairArray = new Pair[input[0].getVetoPairs().length][input.length];
- for(int i = 0; i < input.length; i++)
- pairArray[i] = input[i].getVetoPairs();
- return pairArray;
- }
- // This function returns false if the VetoSet array (pairs) isn't rectangular
- private static boolean validVetoSetArray(VetoSet[] input) {
- int l = input[0].getVetoPairs().length;
- for(VetoSet v : input)
- if(v.getVetoPairs().length != l) { return false; }
- return true;
- }
- public static VetoSet getVeto(String filename) throws Exception {
- return parseVeto(readVeto(filename));
- }
- public static VetoSet parseVeto(List<String[]> input) throws Exception {
- if(!checkVeto(input))
- throw new Exception("Bad file data");
- String header = input.get(0)[0]; // The first line should only have one token
- BigDecimal depth = new BigDecimal(header);
- BigDecimal a, b;
- Pair[] pairArray = new Pair[input.size() - 1];
- for(int i = 1; i < input.size(); i++) {
- a = new BigDecimal(input.get(i)[0]);
- b = new BigDecimal(input.get(i)[1]);
- pairArray[i - 1] = new Pair(a, b);
- }
- return new VetoSet(depth, pairArray);
- }
- // This function returns false if the input is badly formed
- private static boolean checkVeto(List<String[]> input) {
- if(input.get(0).length != 1) { return false; }
- for(int i = 1; i < input.size(); i++)
- if(input.get(i).length != 2) { return false; }
- return true;
- }
- public static List<String[]> readVeto(String filename) throws Exception {
- return ReadFile.readCSV(filename);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement