Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.List;
- import java.util.ArrayList;
- public class trl {
- public static final double MAX_DIAMETER_LIMIT = 99.0;
- public static final String DELIMITER = ",";
- public static final int SITE = 3;
- public static final int INPUT_COLUMN_COUNT = 2;
- public static final String LVT_CRAP = "33";
- public static final String OUTPUT_STRING = (
- ",%d,%d,,%d,%d%s,%d,%s"
- );
- public static final String[][] species = {
- {"BS", "RS", "WS", "BF", "WP", "JP", "RP", "EC", "EH", "TL", "BE", "SM", "RM", "YB", "OT", "WB", "(?:PO|LA|TA)" },
- {"bS", "rS", "wS", "bF", "wP", "jP", "rP", "eC", "eH", "tL", "bE", "sM", "rM", "yB", "OT", "wB", "Po"}
- };
- public static String translate(String s) {
- String r = null;
- for (int i = 0, l = species[0].length; i < l; i++) {
- if (s.matches(species[0][i])) {
- r = species[1][i];
- break;
- }
- }
- return (r);
- }
- public static int index(String s) {
- int r = 0;
- for (int i = 0, l = species[1].length; i < l; i++) {
- if (species[1][i].compareTo(s) == 0) {
- r = i + 1;
- break;
- }
- }
- return (r);
- }
- public static int classify(double d) {
- int r = 0;
- if (d < 9.0) {
- r = 0;
- } else if (d < 11.6) {
- r = 10;
- } else {
- for (double i = 12.0; i < MAX_DIAMETER_LIMIT; i += 2.0) {
- if ((d >= (i - 0.4)) && (d <= (i + 1.5))) {
- r = (int) i;
- break;
- }
- }
- }
- return (r);
- }
- public static void main(String[] arg) throws IOException {
- if (arg == null || arg.length == 0 || arg[0] == null || arg[0].length() < 1) {
- System.out.println("Hey bud, quit it.");
- return;
- }
- BufferedReader csv = new BufferedReader(
- new FileReader(arg[0])
- );
- String line = null; // swap space
- String[] crap = null; // more swap space
- List<String> mSpecies = new ArrayList<String>(50);
- List<Integer> mCount = new ArrayList<Integer>(50);
- List<Integer> mDiameter = new ArrayList<Integer>(50);
- List<Integer> mIndex = new ArrayList<Integer>(50);
- while ((line = csv.readLine()) != null) {
- if (line == null) {
- continue;
- }
- crap = line.split(DELIMITER);
- if (crap == null || crap.length != INPUT_COLUMN_COUNT) {
- crap = null;
- continue;
- }
- String spc = crap[0];
- String trl = translate(spc);
- if (trl == null) {
- continue;
- }
- int idx = index(trl);
- double dia = Double.parseDouble(crap[1]);
- int tcl = classify(dia);
- if ((tcl == 0) || (idx == 0)) {
- continue;
- }
- if (mSpecies.size() == 0) {
- mSpecies.add(trl);
- mCount.add((Integer) 1);
- mDiameter.add((Integer) tcl);
- mIndex.add((Integer) idx);
- } else {
- for (int i = 0, l = mSpecies.size(); i < l; i++) {
- String s = (String) mSpecies.get(i);
- Integer c = (Integer) mCount.get(i);
- Integer d = (Integer) mDiameter.get(i);
- Integer g = (Integer) mIndex.get(i);
- if (idx == g) {
- if (tcl == d) {
- mCount.set(i, ++c);
- break;
- }
- } else if (i == (l - 1)) {
- mSpecies.add(trl);
- mCount.add((Integer) 1);
- mIndex.add((Integer) idx);
- mDiameter.add((Integer) tcl);
- break;
- }
- }
- }
- }
- for (int i = 0; i < mSpecies.size(); i++) {
- System.out.println(
- String.format(
- OUTPUT_STRING,
- SITE, mIndex.get(i), mDiameter.get(i), mIndex.get(i),
- LVT_CRAP, (mCount.get(i) * 25), mSpecies.get(i)
- )
- );
- }
- }
- }
Add Comment
Please, Sign In to add comment