Skip to content

Commit 92db9db

Browse files
allcontributors[bot]rana7azem
authored andcommitted
docs: add mammadyahyayev as a contributor for doc (#3102)
* docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] --------- Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
1 parent b375919 commit 92db9db

File tree

8 files changed

+257
-65
lines changed

8 files changed

+257
-65
lines changed

component/pom.xml

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,15 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--
3-
4-
This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
5-
6-
The MIT License
7-
Copyright © 2014-2022 Ilkka Seppälä
8-
9-
Permission is hereby granted, free of charge, to any person obtaining a copy
10-
of this software and associated documentation files (the "Software"), to deal
11-
in the Software without restriction, including without limitation the rights
12-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
copies of the Software, and to permit persons to whom the Software is
14-
furnished to do so, subject to the following conditions:
15-
16-
The above copyright notice and this permission notice shall be included in
17-
all copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25-
THE SOFTWARE.
26-
27-
-->
28-
<project xmlns="http://maven.apache.org/POM/4.0.0"
29-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
31-
<parent>
32-
<artifactId>java-design-patterns</artifactId>
33-
<groupId>com.iluwatar</groupId>
34-
<version>1.26.0-SNAPSHOT</version>
35-
</parent>
36-
<modelVersion>4.0.0</modelVersion>
37-
38-
<artifactId>component</artifactId>
39-
<dependencies>
40-
<dependency>
41-
<groupId>org.junit.jupiter</groupId>
42-
<artifactId>junit-jupiter-api</artifactId>
43-
<scope>test</scope>
44-
</dependency>
45-
</dependencies>
46-
<build>
47-
<plugins>
48-
<plugin>
49-
<groupId>org.apache.maven.plugins</groupId>
50-
<artifactId>maven-assembly-plugin</artifactId>
51-
<executions>
52-
<execution>
53-
<configuration>
54-
<archive>
55-
<manifest>
56-
<mainClass>com.iluwatar.component.App</mainClass>
57-
</manifest>
58-
</archive>
59-
</configuration>
60-
</execution>
61-
</executions>
62-
</plugin>
63-
</plugins>
64-
</build>
65-
</project>
1+
<dependencies>
2+
<!-- JUnit 5 Dependency -->
3+
<dependency>
4+
<groupId>org.junit.jupiter</groupId>
5+
<artifactId>junit-jupiter-api</artifactId>
6+
<version>5.8.2</version>
7+
<scope>test</scope>
8+
</dependency>
9+
<dependency>
10+
<groupId>org.junit.jupiter</groupId>
11+
<artifactId>junit-jupiter-engine</artifactId>
12+
<version>5.8.2</version>
13+
<scope>test</scope>
14+
</dependency>
15+
</dependencies>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.iluwatar.component;
2+
public class FirstTask implements Task {
3+
private String title;
4+
5+
public FirstTask(String title) {
6+
this.title = title;
7+
}
8+
9+
@Override
10+
public String getTitle() {
11+
return title;
12+
}
13+
14+
@Override
15+
public void setTitle(String title) {
16+
this.title = title;
17+
}
18+
19+
@Override
20+
public void addTask(Task task) {
21+
// Not applicable for FirstTask, as it's a leaf node.
22+
}
23+
24+
@Override
25+
public void removeTask(Task task) {
26+
// Not applicable for FirstTask, as it's a leaf node.
27+
}
28+
29+
@Override
30+
public void display() {
31+
System.out.println("FirstTask: " + title);
32+
}
33+
}
34+
35+
36+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.iluwatar.component;
2+
3+
public interface Task {
4+
String getTitle();
5+
void setTitle(String title);
6+
void addTask(Task task);
7+
void removeTask(Task task);
8+
void display();
9+
}
10+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.iluwatar.component;
2+
3+
public class TaskFactory {
4+
5+
// Creates and returns a simple task
6+
public static Task createFirstTask(String title) {
7+
return new FirstTask(title);
8+
}
9+
10+
// Creates and returns a task list
11+
public static TaskList createTaskList(String title) {
12+
return new TaskList(title);
13+
}
14+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.iluwatar.component;
2+
import java.util.ArrayList;
3+
import java.util.List;
4+
5+
public class TaskList implements Task {
6+
private String title;
7+
private final List<Task> tasks;
8+
9+
public TaskList(String title) {
10+
this.title = title;
11+
this.tasks = new ArrayList<>();
12+
}
13+
14+
@Override
15+
public String getTitle() {
16+
return title;
17+
}
18+
19+
@Override
20+
public void setTitle(String title) {
21+
this.title = title;
22+
}
23+
24+
@Override
25+
public void addTask(Task task) {
26+
tasks.add(task);
27+
}
28+
29+
@Override
30+
public void removeTask(Task task) {
31+
tasks.remove(task);
32+
}
33+
34+
@Override
35+
public void display() {
36+
System.out.println("Task List: " + title);
37+
for (Task task : tasks) {
38+
task.display();
39+
}
40+
}
41+
42+
// Getter method for testing
43+
public List<Task> getTasks() {
44+
return tasks;
45+
}
46+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.iluwatar.component;
2+
3+
public class TaskManager {
4+
5+
// Method to create a task
6+
public Task createTask(String title) {
7+
return TaskFactory.createFirstTask(title);
8+
}
9+
10+
// Method to create a task list
11+
public TaskList createTaskList(String title) {
12+
return TaskFactory.createTaskList(title);
13+
}
14+
15+
// Method to add a task to a task list
16+
public void addTaskToList(TaskList taskList, Task task) {
17+
taskList.addTask(task);
18+
}
19+
20+
// Method to remove a task from a task list
21+
public void removeTaskFromList(TaskList taskList, Task task) {
22+
taskList.removeTask(task);
23+
}
24+
25+
// Method to display a single task
26+
public void displayTask(Task task) {
27+
task.display();
28+
}
29+
30+
// Method to display a task list and its tasks
31+
public void displayTaskList(TaskList taskList) {
32+
taskList.display();
33+
}
34+
}
35+
36+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.iluwatar.component;
2+
public class TaskManagerMain {
3+
public static void main(String[] args) {
4+
// Create an instance of TaskManager
5+
TaskManager taskManager = new TaskManager();
6+
7+
// Create two simple tasks
8+
Task task1 = taskManager.createTask("Study for the quiz");
9+
Task task2 = taskManager.createTask("Complete homework");
10+
11+
// Create a task list to hold the tasks
12+
TaskList taskList = taskManager.createTaskList("My Project Tasks");
13+
14+
// Add tasks to the task list
15+
taskManager.addTaskToList(taskList, task1);
16+
taskManager.addTaskToList(taskList, task2);
17+
18+
// Display individual tasks
19+
System.out.println("Displaying Task 1:");
20+
taskManager.displayTask(task1);
21+
22+
System.out.println("\nDisplaying Task 2:");
23+
taskManager.displayTask(task2);
24+
25+
// Display the task list
26+
System.out.println("\nDisplaying Task List:");
27+
taskManager.displayTaskList(taskList);
28+
}
29+
}
30+
31+
32+
33+
34+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.iluwatar.component;
2+
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
6+
public class TaskListTest
7+
{
8+
9+
@Test
10+
public void testCreateFirstTask()
11+
{
12+
// Test creating the first task
13+
Task task = new FirstTask("Study for the exam");
14+
assertNotNull(task, "Task should not be exit");
15+
assertEquals("Study for the exam", task.getTitle(), "Task title should match");
16+
}
17+
18+
@Test
19+
public void testSetTaskTitle()
20+
{
21+
// Test updating the title for the implemented task
22+
Task task = new FirstTask("Old Title");
23+
task.setTitle("New Title");
24+
assertEquals("New Title", task.getTitle(), "Task title should update correctly");
25+
}
26+
27+
@Test
28+
public void testAddTaskToTaskList()
29+
{
30+
// Test adding tasks to a task list
31+
TaskList taskList = new TaskList("My Task List");
32+
Task task = new FirstTask("Complete homework");
33+
taskList.addTask(task);
34+
35+
assertEquals(1, taskList.getTasks().size(), "Task list should contain one task");
36+
assertEquals("Complete homework", taskList.getTasks().get(0).getTitle(), "Task title should match");
37+
}
38+
39+
@Test
40+
public void testRemoveTaskFromTaskList()
41+
{
42+
// Test removing a task from a task list
43+
TaskList taskList = new TaskList("My Task List");
44+
Task task = new FirstTask("Complete homework");
45+
taskList.addTask(task);
46+
taskList.removeTask(task);
47+
48+
assertEquals(0, taskList.getTasks().size(), "Task list should be empty after removing the task");
49+
}
50+
51+
@Test
52+
public void testDisplayTaskList()
53+
{
54+
// Test displaying the task list and tasks
55+
TaskList taskList = new TaskList("My Task List");
56+
Task task1 = new FirstTask("Complete Task");
57+
Task task2 = new FirstTask("Study for the quiz");
58+
59+
taskList.addTask(task1);
60+
taskList.addTask(task2);
61+
62+
// Test that the tasks are displayed (this doesn't assert, just for practice)
63+
System.out.println("Testing display:");
64+
taskList.display();
65+
}
66+
}

0 commit comments

Comments
 (0)