Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c98b0a522 |
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
Generated
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="WS-07-Multithreading-Basics-and-Hashing" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+20
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://maven.myket.ir/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+18
-18
@@ -1,5 +1,6 @@
|
|||||||
package dev;
|
package dev;
|
||||||
|
|
||||||
|
import dev.model.Student;
|
||||||
import dev.service.StudentManager;
|
import dev.service.StudentManager;
|
||||||
import dev.thread.StudentLoader;
|
import dev.thread.StudentLoader;
|
||||||
import dev.utils.FileManager;
|
import dev.utils.FileManager;
|
||||||
@@ -33,32 +34,30 @@ public class Main {
|
|||||||
|
|
||||||
List<String> data = FileManager.loadStudents("students.txt");
|
List<String> data = FileManager.loadStudents("students.txt");
|
||||||
|
|
||||||
// TODO:
|
List<String> part1 = data.subList(0, 20);
|
||||||
|
|
||||||
// Split data into 3 parts
|
List<String> part2 = data.subList(20, 40);
|
||||||
|
|
||||||
List<String> part1 = null;
|
List<String> part3 = data.subList(40, 60);
|
||||||
|
|
||||||
List<String> part2 = null;
|
|
||||||
|
|
||||||
List<String> part3 = null;
|
StudentLoader t1 = new StudentLoader(part1);
|
||||||
|
|
||||||
// TODO:
|
StudentLoader t2 = new StudentLoader(part2);
|
||||||
|
|
||||||
StudentLoader t1 = null;
|
StudentLoader t3 = new StudentLoader(part3);
|
||||||
|
|
||||||
StudentLoader t2 = null;
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t3.start();
|
||||||
|
|
||||||
StudentLoader t3 = null;
|
t1.join();
|
||||||
|
t2.join();
|
||||||
// TODO:
|
t3.join();
|
||||||
|
|
||||||
// start()
|
|
||||||
|
|
||||||
// join()
|
|
||||||
|
|
||||||
// merge results
|
|
||||||
|
|
||||||
|
manager.addStudents(t1.getStudents());
|
||||||
|
manager.addStudents(t2.getStudents());
|
||||||
|
manager.addStudents(t3.getStudents());
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2 -> {
|
case 2 -> {
|
||||||
@@ -67,7 +66,8 @@ public class Main {
|
|||||||
|
|
||||||
int id = scanner.nextInt();
|
int id = scanner.nextInt();
|
||||||
|
|
||||||
System.out.println(manager.searchStudent(id));
|
Student s = manager.searchStudent(id);
|
||||||
|
System.out.println(s != null ? s : "Not found");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,31 +40,16 @@ public class Student {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
return this.id % 97;
|
||||||
// TODO:
|
|
||||||
// Return custom hash
|
|
||||||
|
|
||||||
// Example:
|
|
||||||
// return id % 97;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
|
||||||
// TODO:
|
if (obj == null || getClass() != obj.getClass()) return false;
|
||||||
|
|
||||||
// Step 1:
|
Student s = (Student) obj;
|
||||||
// Check null
|
return s.id == this.id;
|
||||||
|
|
||||||
// Step 2:
|
|
||||||
// Convert obj to Student
|
|
||||||
|
|
||||||
// Step 3:
|
|
||||||
// Compare IDs
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,33 +11,31 @@ public class StudentManager {
|
|||||||
|
|
||||||
public void addStudents(ArrayList<Student> newStudents) {
|
public void addStudents(ArrayList<Student> newStudents) {
|
||||||
|
|
||||||
// TODO:
|
students.addAll(newStudents);
|
||||||
|
|
||||||
// Merge students
|
|
||||||
|
|
||||||
// Hint:
|
|
||||||
// addAll()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Student searchStudent(int id) {
|
public Student searchStudent(int id) {
|
||||||
|
|
||||||
// TODO:
|
for (Student s : students)
|
||||||
|
{
|
||||||
// Loop through students
|
if (id == s.getId())
|
||||||
|
{
|
||||||
// Compare IDs
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeStudent(int id) {
|
public boolean removeStudent(int id) {
|
||||||
|
|
||||||
// TODO:
|
for (Student s : students)
|
||||||
|
{
|
||||||
// Find student
|
if (id == s.getId())
|
||||||
|
{
|
||||||
// Remove student
|
students.remove(s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,30 +25,17 @@ public class StudentLoader extends Thread {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
// TODO:
|
|
||||||
|
|
||||||
/*
|
|
||||||
Example line:
|
|
||||||
|
|
||||||
1001,Aryan,Computer Science,3.7
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
|
|
||||||
// TODO:
|
String[] parts = line.split(",");
|
||||||
// split line
|
int id = Integer.parseInt(parts[0]);
|
||||||
|
String name = parts[1];
|
||||||
// TODO:
|
String major = parts[2];
|
||||||
// read values
|
double gpa = Double.parseDouble(parts[3]);
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// create Student
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// add to students list
|
|
||||||
|
|
||||||
|
Student student = new Student(id, name, major, gpa);
|
||||||
|
students.add(student);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Student> getStudents() {
|
public ArrayList<Student> getStudents() {
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ public class FileManager {
|
|||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
|
||||||
// TODO:
|
lines.add(line);
|
||||||
|
|
||||||
// Add line to list
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user