Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add java collections examples #128

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.graphQL;
package apiPractice.graphQL;
import static io.restassured.RestAssured.baseURI;

import practice.api.graphQL.GraphQlApiObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.TAU.dataentities;
package apiPractice.rest.TAU.dataentities;

import com.fasterxml.jackson.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.TAU.dataentities;
package apiPractice.rest.TAU.dataentities;

import com.fasterxml.jackson.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.TestAPIs_Booking;
package apiPractice.rest.TestAPIs_Booking;


import static org.hamcrest.Matchers.equalTo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.dataentities;
package apiPractice.rest.dataentities;

public class Address {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.dataentities;
package apiPractice.rest.dataentities;

public class Car {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.dataentities;
package apiPractice.rest.dataentities;

public class Photo {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.restAssured;
package apiPractice.rest.restAssured;

import io.restassured.RestAssured;
import org.testng.annotations.DataProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.restAssured;
package apiPractice.rest.restAssured;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.restAssured;
package apiPractice.rest.restAssured;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.restAssured;
package apiPractice.rest.restAssured;

import org.testng.annotations.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.run_script_dataDriven;
package apiPractice.rest.run_script_dataDriven;

import static io.restassured.RestAssured.get;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.run_script_dataDriven;
package apiPractice.rest.run_script_dataDriven;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFRow;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.run_script_jsn;
package apiPractice.rest.run_script_jsn;

import static org.hamcrest.Matchers.equalTo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.rest.saveToFile;
package apiPractice.rest.saveToFile;

import io.restassured.RestAssured;
import org.testng.annotations.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api.restAssured;
package apiPractice.restAssured;

import com.engine.constants.FrameworkConstants;
import practice.api.rest.travels.RestApiBase;
Expand Down
17 changes: 0 additions & 17 deletions src/test/java/java/coursesJava/Calculation.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/java/java/coursesJava/EnglishCourse.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/java/java/coursesJava/MyCalcuation.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/test/java/java/coursesJava/OperationArithmetic.java

This file was deleted.

28 changes: 0 additions & 28 deletions src/test/java/java/coursesJava/TestRelational.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.arrays;
package javaPractice.arrays;

import java.util.Arrays;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.coursesJava;
package javaPractice.arrays;

public class ArraysDemo {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.arrays;
package javaPractice.arrays;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.arrays;
package javaPractice.arrays;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.coursesJava;
package javaPractice.arrays;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.coursesJava;
package javaPractice.arrays;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.coursesJava;
package javaPractice.arrays;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.coursesJava;
package javaPractice.arrays;

public class StaticArray {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.arrays;
package javaPractice.arrays;

public class test {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

/*
* Objects are structures which contain data in the form of fields and methods.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;


import java.util.Scanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.classesAndObjects;
package javaPractice.classesAndObjects;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package java.collections;
package javaPractice.collections;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package javaPractice.collections.Comparable;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ComparableExample {
public static void main(String[] args) {
List<Employee> employees = new ArrayList<>();

employees.add(new Employee(1010, "Rajeev", 100000.00, LocalDate.of(2010, 7, 10)));
employees.add(new Employee(1004, "Chris", 95000.50, LocalDate.of(2017, 3, 19)));
employees.add(new Employee(1015, "David", 134000.00, LocalDate.of(2017, 9, 28)));

System.out.println("Employees (Before Sorting) : " + employees);

// This will use the `compareTo()` method of the `Employee` class to compare two employees and sort them.
Collections.sort(employees);

System.out.println("\nEmployees (After Sorting) : " + employees);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package javaPractice.collections.Comparable;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ComparatorExample {
public static void main(String[] args) {
List<Employee> employees = new ArrayList<>();

employees.add(new Employee(1010, "Rajeev", 100000.00, LocalDate.of(2010, 7, 10)));
employees.add(new Employee(1004, "Chris", 95000.50, LocalDate.of(2017, 3, 19)));
employees.add(new Employee(1015, "David", 134000.00, LocalDate.of(2017, 9, 28)));
employees.add(new Employee(1009, "Steve", 100000.00, LocalDate.of(2016, 5, 18)));

System.out.println("Employees : " + employees);

// Sort employees by Name
Collections.sort(employees, Comparator.comparing(Employee::getName));
System.out.println("\nEmployees (Sorted by Name) : " + employees);

// Sort employees by Salary
Collections.sort(employees, Comparator.comparingDouble(Employee::getSalary));
System.out.println("\nEmployees (Sorted by Salary) : " + employees);

// Sort employees by JoiningDate
Collections.sort(employees, Comparator.comparing(Employee::getJoiningDate));
System.out.println("\nEmployees (Sorted by JoiningDate) : " + employees);

// Sort employees by Name in descending order
Collections.sort(employees, Comparator.comparing(Employee::getName).reversed());
System.out.println("\nEmployees (Sorted by Name in descending order) : " + employees);

// Chaining multiple Comparators
// Sort by Salary. If Salary is same then sort by Name
Collections.sort(employees, Comparator.comparingDouble(Employee::getSalary).thenComparing(Employee::getName));
System.out.println("\nEmployees (Sorted by Salary and Name) : " + employees);
}
}
Loading
Loading