Guest User

Untitled

a guest
Jul 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.49 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.List;
  3. import java.util.ArrayList;
  4.  
  5.  
  6. public class trl {
  7.     public static final double MAX_DIAMETER_LIMIT = 99.0;
  8.     public static final String DELIMITER = ",";
  9.     public static final int SITE = 3;
  10.     public static final int INPUT_COLUMN_COUNT = 2;
  11.     public static final String LVT_CRAP = "33";
  12.  
  13.     public static final String OUTPUT_STRING = (
  14.         ",%d,%d,,%d,%d%s,%d,%s"
  15.     );
  16.  
  17.     public static final String[][] species = {
  18.         {"BS", "RS", "WS", "BF", "WP", "JP", "RP", "EC", "EH", "TL", "BE", "SM", "RM", "YB", "OT", "WB", "(?:PO|LA|TA)" },
  19.         {"bS", "rS", "wS", "bF", "wP", "jP", "rP", "eC", "eH", "tL", "bE", "sM", "rM", "yB", "OT", "wB", "Po"}
  20.     };
  21.  
  22.  
  23.     public static String translate(String s) {
  24.         String r = null;
  25.  
  26.         for (int i = 0, l = species[0].length; i < l; i++) {
  27.  
  28.             if (s.matches(species[0][i])) {
  29.                 r = species[1][i];
  30.                 break;
  31.             }
  32.         }
  33.  
  34.         return (r);
  35.     }
  36.  
  37.     public static int index(String s) {
  38.         int r = 0;
  39.  
  40.         for (int i = 0, l = species[1].length; i < l; i++) {
  41.             if (species[1][i].compareTo(s) == 0) {
  42.                 r = i + 1;
  43.                 break;
  44.             }
  45.         }
  46.  
  47.         return (r);
  48.     }
  49.  
  50.     public static int classify(double d) {
  51.         int r = 0;
  52.  
  53.         if (d < 9.0) {
  54.             r = 0;
  55.         } else if (d < 11.6) {
  56.             r = 10;
  57.         } else {
  58.             for (double i = 12.0; i < MAX_DIAMETER_LIMIT; i += 2.0) {
  59.                 if ((d >= (i - 0.4)) && (d <= (i + 1.5))) {
  60.                     r = (int) i;
  61.                     break;
  62.                 }
  63.             }
  64.         }
  65.  
  66.         return (r);
  67.     }
  68.  
  69.  
  70.     public static void main(String[] arg) throws IOException {
  71.         if (arg == null || arg.length == 0 || arg[0] == null || arg[0].length() < 1) {
  72.             System.out.println("Hey bud, quit it.");
  73.             return;
  74.         }
  75.  
  76.         BufferedReader csv = new BufferedReader(
  77.             new FileReader(arg[0])
  78.         );
  79.  
  80.         String line = null; // swap space
  81.         String[] crap = null; // more swap space
  82.  
  83.         List<String> mSpecies = new ArrayList<String>(50);
  84.         List<Integer> mCount = new ArrayList<Integer>(50);
  85.         List<Integer> mDiameter = new ArrayList<Integer>(50);
  86.         List<Integer> mIndex = new ArrayList<Integer>(50);
  87.  
  88.         while ((line = csv.readLine()) != null) {
  89.             if (line == null) {
  90.                 continue;
  91.             }
  92.  
  93.             crap = line.split(DELIMITER);
  94.  
  95.             if (crap == null || crap.length != INPUT_COLUMN_COUNT) {
  96.                 crap = null;
  97.                 continue;
  98.             }
  99.  
  100.             String spc = crap[0];
  101.             String trl = translate(spc);
  102.  
  103.             if (trl == null) {
  104.                 continue;
  105.             }
  106.  
  107.             int idx = index(trl);
  108.             double dia = Double.parseDouble(crap[1]);
  109.             int tcl = classify(dia);
  110.  
  111.             if ((tcl == 0) || (idx == 0)) {
  112.                 continue;
  113.             }
  114.  
  115.             if (mSpecies.size() == 0) {
  116.                     mSpecies.add(trl);
  117.                     mCount.add((Integer) 1);
  118.                     mDiameter.add((Integer) tcl);
  119.                     mIndex.add((Integer) idx);
  120.             } else {
  121.                 for (int i = 0, l = mSpecies.size(); i < l; i++) {
  122.                     String s = (String) mSpecies.get(i);
  123.                     Integer c = (Integer) mCount.get(i);
  124.                     Integer d = (Integer) mDiameter.get(i);
  125.                     Integer g = (Integer) mIndex.get(i);
  126.  
  127.                     if (idx == g) {
  128.                         if (tcl == d) {
  129.                             mCount.set(i, ++c);
  130.                             break;
  131.                         }
  132.                     } else if (i == (l - 1)) {
  133.                         mSpecies.add(trl);
  134.                                             mCount.add((Integer) 1);
  135.                         mIndex.add((Integer) idx);
  136.                                             mDiameter.add((Integer) tcl);
  137.                         break;
  138.                     }
  139.                 }
  140.             }
  141.         }
  142.  
  143.         for (int i = 0; i < mSpecies.size(); i++) {
  144.             System.out.println(
  145.                 String.format(
  146.                     OUTPUT_STRING,
  147.                     SITE, mIndex.get(i), mDiameter.get(i), mIndex.get(i),
  148.                     LVT_CRAP, (mCount.get(i) * 25), mSpecies.get(i)
  149.                 )
  150.             );
  151.         }
  152.     }
  153. }
Add Comment
Please, Sign In to add comment