Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8a1f3b2
feat: homework 1 completed
Radium84 Oct 14, 2023
ad85fd1
feat: homework 2 completed
Radium84 Oct 18, 2023
3de4cf3
Merge pull request #1 from Radium84/homework-1
Radium84 Oct 21, 2023
68d7a85
Merge branch 'master' of github.com:Radium84/java-reboot into homework-2
Radium84 Oct 21, 2023
9cd51df
Merge remote-tracking branch 'upstream/master'
Radium84 Oct 21, 2023
a069258
feat: homework 3 completed
Radium84 Oct 28, 2023
3cf55e5
fix: filewriter updated
Radium84 Oct 29, 2023
1dae926
Merge pull request #2 from Radium84/homework-2
Radium84 Oct 29, 2023
bf36bef
Merge branch 'master' of github.com:Radium84/java-reboot into homework-3
Radium84 Oct 29, 2023
42026e2
Merge pull request #3 from Radium84/homework-3
Radium84 Oct 29, 2023
bb327e0
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Oct 29, 2023
af4aaaf
Merge branch 'master' of github.com:Radium84/java-reboot into homework-4
Radium84 Oct 29, 2023
c56ceb4
feat: homework 4 complited
Radium84 Nov 1, 2023
823a002
fix: removed wrong check
Radium84 Nov 1, 2023
f9094ca
fix: added hashcode calculation
Radium84 Nov 1, 2023
0feb131
fix: added missing tests
Radium84 Nov 1, 2023
c1ffc8b
fix: Person fields access has been changed
Radium84 Nov 5, 2023
f36d5d9
Merge pull request #4 from Radium84/homework-4
Radium84 Nov 5, 2023
edbe0f6
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Nov 5, 2023
250e9ca
feat: added all logic to methods
Radium84 Nov 6, 2023
8ce7881
feat: homework 5 completed
Radium84 Nov 8, 2023
0310a65
feat: homework 5 completed
Radium84 Nov 8, 2023
bba9d2a
Merge pull request #5 from Radium84/homework-5
Radium84 Nov 11, 2023
9b161d6
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Nov 12, 2023
c1136b8
feat: homework 6 completed
Radium84 Nov 12, 2023
2b6ce17
Merge branch 'master' of github.com:Radium84/java-reboot
Radium84 Nov 15, 2023
bd6c55f
Merge pull request #6 from Radium84/homework-6
Radium84 Nov 19, 2023
5cfdcdb
Merge branch 'master' of github.com:Radium84/java-reboot
Radium84 Nov 19, 2023
0843e51
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Nov 19, 2023
6131b8b
feat: homework 7 completed
Radium84 Nov 21, 2023
5c33b5b
Merge pull request #7 from Radium84/homework-7
Radium84 Nov 25, 2023
ab555ca
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Nov 25, 2023
4fac487
feat: homework 8 completed
Radium84 Nov 26, 2023
49b2cbb
Merge pull request #8 from Radium84/homework-8
Radium84 Dec 6, 2023
d5370f0
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Dec 13, 2023
08a73fa
feat: homework 9 completed
Radium84 Dec 14, 2023
6c9498e
feat: homework 9 completed
Radium84 Dec 14, 2023
75522cc
feat: homework 10 completed
Radium84 Dec 15, 2023
7680878
Merge pull request #9 from Radium84/homework-9
Radium84 Dec 17, 2023
d61684f
Merge pull request #10 from Radium84/homework-10
Radium84 Dec 17, 2023
b01b4ad
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Dec 17, 2023
83a8e85
feat: homework 11 completed
Radium84 Dec 23, 2023
b852780
fix: issues fixed
Radium84 Dec 27, 2023
93af42c
Merge pull request #11 from Radium84/homework-11
Radium84 Dec 27, 2023
131be75
Merge branch 'master' of https://github.com/rsmitt/java-reboot
Radium84 Dec 30, 2023
936f5bf
feat: homework 12 completed
Radium84 Dec 30, 2023
ceef302
feat: added role model and bd to project
Radium84 Dec 31, 2023
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
8 changes: 8 additions & 0 deletions module01/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
<packaging>jar</packaging>

<name>module01</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
18 changes: 18 additions & 0 deletions module01/src/main/java/ru/sberbank/edu/GCD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.sberbank.edu;

/**
* The Euclid's algorithm
* @author Aleksandr Kanarskiy
*/
public class GCD implements CommonDivisor{
@Override
public int getDivisor(int firstNumber, int secondNumber) {
while (secondNumber !=0) {
int tmp = firstNumber%secondNumber;
firstNumber = secondNumber;
secondNumber = tmp;
}
return firstNumber;
}
}

34 changes: 34 additions & 0 deletions module01/src/main/java/ru/sberbank/edu/GreetingImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.sberbank.edu;
/**
* About myself
* @author Aleksandr Kanarskiy
*/
public class GreetingImpl implements Greeting{
public String getName() {
return name;
}

public String getLastName() {
return lastName;
}

private String name;
private String lastName;
private String hobby;

public GreetingImpl() {

}
public GreetingImpl(String name,String lastName,String hobby) {
this.hobby = hobby;
this.lastName = lastName;
this.name = name;

}

@Override
public String getBestHobby() {
return this.hobby;
}

}
19 changes: 19 additions & 0 deletions module01/src/test/java/ru/sberbank/edu/GCDTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.sberbank.edu;


import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class GCDTest {
@Test
void validateGCDTest(){
GCD gcd = new GCD();
assertAll(
()->assertEquals(28,gcd.getDivisor(616,364)),
()->assertEquals(123,gcd.getDivisor(123,0))
);
}

}
20 changes: 20 additions & 0 deletions module01/src/test/java/ru/sberbank/edu/GreetingImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.sberbank.edu;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class GreetingImplTest {
@Test
void validateGettersTest() {
GreetingImpl greetingImpl = new GreetingImpl("Alesandr", "Kanarskiy", "Snorking");
assertAll(
() -> assertEquals("Alesandr", greetingImpl.getName()),
() -> assertEquals("Kanarskiy", greetingImpl.getLastName()),
() -> assertEquals("Snorking", greetingImpl.getBestHobby())
);

}

}
4 changes: 4 additions & 0 deletions module02/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<packaging>jar</packaging>

<name>module02</name>
<dependencies>


</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
6 changes: 6 additions & 0 deletions module02/src/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sdasdasd dsadas sadsdasd sdasda
12sdsad dsad sd sda sad
dsa s

asda
в ыф ы ы
36 changes: 31 additions & 5 deletions module02/src/main/java/ru/sberbank/edu/App.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
package ru.sberbank.edu;

import java.io.IOException;
import java.sql.SQLException;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
public class App {
public static void main(String[] args) {
String inputFilePath = "module02/src/input.txt";
String outputFilePath = "module02/src/output.txt";

try {
// Создаем экземпляр FileResource с указанием пути к файлу входных данных
DataResource fileResource = new FileResource(inputFilePath);

// Создаем экземпляр DataResourceProcessor с передачей ему FileResource
DataResourceProcessor processor = new DataResourceProcessor(fileResource);

// Получаем статистику из ресурса
String statistics = processor.processResource();

// Записываем статистику в файл output.txt
fileResource.writeResultToFile(outputFilePath, statistics);

// Закрываем ресурс
fileResource.close();

System.out.println("Статистика записана в файл " + outputFilePath);
} catch (IOException e) {
System.out.println("Ошибка при работе с файлом: " + e.getMessage());
} catch (SQLException e) {
System.out.println("Ошибка при работе с базой данных: " + e.getMessage());
}
}

}
11 changes: 11 additions & 0 deletions module02/src/main/java/ru/sberbank/edu/DataResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.sberbank.edu;

import java.io.IOException;
import java.sql.SQLException;

public interface DataResource {
String readData() throws IOException, SQLException;
void close() throws IOException, SQLException;
void writeResultToFile(String outputFilePath, String statistics) throws IOException;

}
41 changes: 41 additions & 0 deletions module02/src/main/java/ru/sberbank/edu/DataResourceProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.sberbank.edu;

import java.io.IOException;
import java.sql.SQLException;

public class DataResourceProcessor {
private final DataResource resource;

public DataResourceProcessor(DataResource resource) {
this.resource = resource;
}

public String processResource() throws IOException, SQLException {
int lineCount = 0;
String longestLine = "";
int totalSpaces = 0;

String line;
while ((line = resource.readData()) != null) {
lineCount++;
if (line.length() > longestLine.length()) {
longestLine = line;
}
totalSpaces += countSpaces(line);
}

resource.close();
return String.format("Line count: %s, longest line: %s, total spaces: %s",lineCount,longestLine,totalSpaces);

}

int countSpaces(String line) {
int totalSpaces = 0;
for (char c : line.toCharArray()) {
if (c == ' ') {
totalSpaces++;
}
}
return totalSpaces;
}
}
32 changes: 32 additions & 0 deletions module02/src/main/java/ru/sberbank/edu/DatabaseResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.sberbank.edu;

import java.sql.*;

public class DatabaseResource extends OutputData implements DataResource {
private final Connection connection;
private final Statement statement;
private final ResultSet resultSet;

public DatabaseResource(String url, String user, String password) throws SQLException {
connection = DriverManager.getConnection(url, user, password);
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM my_table");
}

@Override
public String readData() throws SQLException {
if (resultSet.next()) {
return resultSet.getString("data");
}
return null;
}

@Override
public void close() throws SQLException {
resultSet.close();
statement.close();
connection.close();
}


}
25 changes: 25 additions & 0 deletions module02/src/main/java/ru/sberbank/edu/FileResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.sberbank.edu;

import java.io.*;

public class FileResource extends OutputData implements DataResource {
private final BufferedReader reader;

private final String filePath;

public FileResource(String filePath) throws IOException {
reader = new BufferedReader(new FileReader(filePath));
this.filePath = filePath;
}

@Override
public String readData() throws IOException {
validateFile(filePath);
return reader.readLine();
}

@Override
public void close() throws IOException {
reader.close();
}
}
35 changes: 35 additions & 0 deletions module02/src/main/java/ru/sberbank/edu/OutputData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.sberbank.edu;

import java.io.*;
import java.sql.SQLException;


public abstract class OutputData implements DataResource{
@Override
public String readData() throws IOException, SQLException {
return null;
}

@Override
public void close() throws IOException, SQLException {

}
public void writeResultToFile(String filePath, String content) throws IOException {
validateFile(filePath);
try( BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))){
writer.write(content);
}


}
protected void validateFile(String filePath) throws FileNotFoundException {
File file = new File(filePath);
if (!file.exists()) {
throw new FileNotFoundException("File does not exist.");
}

if (!file.isFile()) {
throw new IllegalArgumentException("Specified path does not lead to a file.");
}
}
}
11 changes: 0 additions & 11 deletions module02/src/main/java/ru/sberbank/edu/Statistic.java

This file was deleted.

1 change: 1 addition & 0 deletions module02/src/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Line count: 6, longest line: sdasdasd dsadas sadsdasd sdasda, total spaces: 16
38 changes: 0 additions & 38 deletions module02/src/test/java/ru/sberbank/edu/AppTest.java

This file was deleted.

Loading