Created
June 13, 2024 18:25
-
-
Save audunolsen/ee6c4bbb251ec040f7f9bf469cb7b5b1 to your computer and use it in GitHub Desktop.
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
private static void ParseFindings(String input) { | |
Scanner scanner = new Scanner(input); | |
List<List<String>> discoveries = new ArrayList<>(); | |
int discoveryIndex = 0; | |
while (scanner.hasNextLine()) { | |
String line = scanner.nextLine(); | |
if (discoveryIndex >= discoveries.size()) { | |
discoveries.add(new ArrayList<>()); | |
} | |
if (line.equals("-------")) { | |
discoveryIndex++; | |
if (scanner.hasNextLine()) { | |
discoveries.add(new ArrayList<>()); | |
} | |
continue; | |
} | |
discoveries.get(discoveryIndex).add(line); | |
} | |
List<Jewelry> jewelryDiscoveries = new ArrayList<>(); | |
List<Coin> coinDiscoveries = new ArrayList<>(); | |
List<Weapon> weaponDiscoveries = new ArrayList<>(); | |
for (List<String> discovery : discoveries) { | |
int id = Integer.parseInt(discovery.get(0)); | |
String location = discovery.get(1); | |
int finderId = Integer.parseInt(discovery.get(2)); | |
String date = discovery.get(3); | |
int age = Integer.parseInt(discovery.get(4)); | |
int museumId = Integer.parseInt(discovery.get(5)); | |
String findingType = discovery.get(6); | |
String jewelryType = discovery.get(7); | |
String weaponType = discovery.get(7); | |
int coinDiameter = 0; | |
if (findingType.equals("Mynt")) { | |
coinDiameter = Integer.parseInt(discovery.get(7)); | |
} | |
String coinMetalType = discovery.get(8); | |
String weaponMaterial = discovery.get(8); | |
int jewelryWorth = 0; | |
if (findingType.equals("Smykke")) { | |
jewelryWorth = Integer.parseInt(discovery.get(8)); | |
} | |
String jewelryImageName = ""; | |
int weaponWeight = 0; | |
if (discovery.size() >= 10) { | |
jewelryImageName = discovery.get(9); | |
if (findingType.equals("Våpen")) { | |
weaponWeight = Integer.parseInt(discovery.get(9)); | |
} | |
} | |
switch (findingType) { | |
case "Mynt": | |
coinDiscoveries.add(new Coin()); | |
break; | |
case "Smykke": | |
jewelryDiscoveries.add(new Jewelry()); | |
break; | |
case "Våpen": | |
weaponDiscoveries.add(new Weapon()); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment