diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..170ef7b --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,34 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: build diff --git a/build.gradle b/build.gradle index f0ddbb6..2353d8e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { group 'org.launchcode' version '1.0-SNAPSHOT' -sourceCompatibility = 1.8 +sourceCompatibility = 11 repositories { mavenCentral() @@ -15,3 +15,4 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' implementation('org.apache.commons:commons-csv:1.4') } +targetCompatibility = JavaVersion.VERSION_11 diff --git a/src/main/java/JobData.java b/src/main/java/JobData.java index 4f835d3..d187689 100644 --- a/src/main/java/JobData.java +++ b/src/main/java/JobData.java @@ -5,10 +5,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.Reader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; /** * Created by LaunchCode @@ -48,6 +45,12 @@ public static ArrayList findAll(String field) { return values; } +// private static void loadData() { +// if (isDataLoaded) { +// return; +// } +// } + public static ArrayList> findAll() { // load data, if not already loaded @@ -77,9 +80,9 @@ public static ArrayList> findByColumnAndValue(String col for (HashMap row : allJobs) { - String aValue = row.get(column); + String aValue = row.get(column).toLowerCase(); - if (aValue.contains(value)) { + if (aValue.contains(value.toLowerCase())) { jobs.add(row); } } @@ -91,16 +94,23 @@ public static ArrayList> findByColumnAndValue(String col * Search all columns for the given term * * @param value The search term to look for - * @return List of all jobs with at least one field containing the value + * @return List of all jobs with at least one field containing the value */ public static ArrayList> findByValue(String value) { - - // load data, if not already loaded - loadData(); - +// + loadData(); + ArrayList> jobs = new ArrayList<>(); + for (HashMap row : allJobs) { + for (String key : row.keySet()) { + String aValue = row.get(key); + if (aValue.toLowerCase().contains(value.toLowerCase())){ + jobs.add(row); + break; + }} // TODO - implement this method - return null; +// return jobs; } + return jobs;} /** * Read in data from a CSV file and store it in a list @@ -140,7 +150,23 @@ private static void loadData() { } catch (IOException e) { System.out.println("Failed to load job data"); e.printStackTrace(); - } - } - + }} +// public static ArrayList> findByValue(String value) { +// +// // load data, if not already loaded +// loadData(); +// ArrayList> jobs = new ArrayList<>(); +// for (HashMap row : allJobs) { +// for (String key : row.keySet()) { +// String aValue = row.get(key); +// if (aValue.toLowerCase().contains(value.toLowerCase())){ +// jobs.add(row); +// break; +// }} +// // TODO - implement this method +//// return jobs; +// } +// return jobs; +// } +// break; } diff --git a/src/main/java/TechJobs.java b/src/main/java/TechJobs.java index 099f4ef..79b1f2b 100644 --- a/src/main/java/TechJobs.java +++ b/src/main/java/TechJobs.java @@ -1,7 +1,7 @@ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; /** * Created by LaunchCode @@ -9,8 +9,9 @@ public class TechJobs { static Scanner in = new Scanner(System.in); +// private static ArrayList> someJobs; - public static void main (String[] args) { + public static void main(String[] args) { // Initialize our field map with key/name pairs HashMap columnChoices = new HashMap<>(); @@ -60,9 +61,10 @@ public static void main (String[] args) { // What is their search term? System.out.println("\nSearch term:"); String searchTerm = in.nextLine(); +// System.out.println(searchTerm); if (searchField.equals("all")) { - printJobs(JobData.findByValue(searchTerm)); + printJobs(Objects.requireNonNull(JobData.findByValue(searchTerm))); } else { printJobs(JobData.findByColumnAndValue(searchField, searchTerm)); } @@ -77,7 +79,7 @@ private static String getUserSelection(String menuHeader, HashMap> someJobs) { +// HashMap columnChoices = new HashMap<>(); +// String path = "src//main//resources//job_data.csv"; +// System.out.println(path); +// BufferedReader reader = null; +// String line = ""; +// System.out.print("\n"); + + if (someJobs.isEmpty()) { + System.out.print("No Results"); + } else { + for (HashMap sJobs : someJobs) { + System.out.print("\n*****"); + System.out.print("\n"); + for (Map.Entry sJob : sJobs.entrySet()) { + System.out.println(sJob.getKey() + ": " + sJob.getValue()); + } + System.out.print("*****"); + System.out.print("\n"); + } - System.out.println("printJobs is not implemented yet"); +// try { +// reader = new BufferedReader(new FileReader(path)); +// while ((line = reader.readLine()) != null) { +// String[] row = line.split(","); +//// String [] column = line.split("\n"); +// System.out.println("*****" + "\n" + "position type: " + row[3] + "\n" + "name: " + row[0] + "\n" + "employer: " + row[1] + "\n" + "location: " + row[2] + "\n" + "core competency: " + row[4] + "\n" + "*****" + "\n"); +//// for (String index : row ){ +////// System.out.printf("%-10s", "\n" + index); +////// for (String indexes : row) { +//// System.out.printf(index[0] + "\n" + ": "); +//// } +// } +// System.out.println(); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// try { +// reader.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +//return someJobs; + } } } +// public static void setSomeJobs(Object someJobs) { +// TechJobs.someJobs = (ArrayList>) someJobs; +// } +//}