Skip to content
Open
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
Binary file not shown.
Binary file added .gradle/6.5.1/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/6.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Empty file added .gradle/6.5.1/gc.properties
Empty file.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Mon Dec 21 19:42:28 MSK 2020
gradle.version=6.5.1
Binary file added .gradle/checksums/checksums.lock
Binary file not shown.
Empty file added .gradle/vcs-1/gc.properties
Empty file.
23 changes: 23 additions & 0 deletions java-data-handling-template.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.5.2" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.epam.izh.rd.online.repository;

import java.io.IOException;

public interface FileRepository {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
package com.epam.izh.rd.online.repository;

import java.io.*;
import java.nio.file.*;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

public class SimpleFileRepository implements FileRepository {
private static String prePathForCountFiles = "src/main/resources/";
private static String prePathForCountDirectory = "src/main/resources/";

/**
* Метод рекурсивно подсчитывает количество файлов в директории
*
* @param path путь до директори
* @param path путь до директории
* @return файлов, в том числе скрытых
*/
@Override
public long countFilesInDirectory(String path) {
return 0;
long count = 0;
File dir = new File(prePathForCountFiles + path);
if (dir.exists()) {
File[] files = dir.listFiles();
for (File file : files) {
if (file.isFile()) {
count++;
}
if (file.isDirectory()) {
prePathForCountFiles = "";
count = count + countFilesInDirectory(file.getPath());
}
}
return count;
}
return count;
}

/**
Expand All @@ -21,9 +43,26 @@ public long countFilesInDirectory(String path) {
*/
@Override
public long countDirsInDirectory(String path) {
return 0;
long count = 0;
if (!prePathForCountDirectory.equals("")) {
count++;
}
File dir = new File(prePathForCountDirectory + path);
if (dir.exists()) {
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
count++;
prePathForCountDirectory = "";
count = count + countDirsInDirectory(file.getPath());
}
}
return count;
}
return count;
}


/**
* Метод копирует все файлы с расширением .txt
*
Expand All @@ -32,9 +71,20 @@ public long countDirsInDirectory(String path) {
*/
@Override
public void copyTXTFiles(String from, String to) {
return;
File src = new File(from);
File copyFile = new File(to);
File copyFileDirectory = new File(copyFile.getParent());
if (!copyFileDirectory.isDirectory()) {
copyFileDirectory.mkdirs();
}
try {
Files.copy(src.toPath(), copyFile.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}


/**
* Метод создает файл на диске с расширением txt
*
Expand All @@ -44,6 +94,16 @@ public void copyTXTFiles(String from, String to) {
*/
@Override
public boolean createFile(String path, String name) {
File dir = new File(getClass().getResource("/" + path).getPath());
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir.getPath() + "/" + name);
try {
return file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}

Expand All @@ -55,6 +115,15 @@ public boolean createFile(String path, String name) {
*/
@Override
public String readFileFromResources(String fileName) {
return null;
String content = "";
try (BufferedReader bufferedReader = new BufferedReader(new FileReader("src/main/resources/" + fileName))) {
content = bufferedReader.readLine();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;

public class SimpleBigNumbersService implements BigNumbersService {


/**
* Метод делит первое число на второе с заданной точностью
* Например 1/3 с точностью 2 = 0.33
*
* @param range точность
* @return результат
*/
@Override
public BigDecimal getPrecisionNumber(int a, int b, int range) {
return null;
BigDecimal firstNumber = BigDecimal.valueOf(a);
BigDecimal secondNumber = BigDecimal.valueOf(b);
return firstNumber.divide(secondNumber, range, BigDecimal.ROUND_HALF_UP);
}

/**
Expand All @@ -24,6 +29,14 @@ public BigDecimal getPrecisionNumber(int a, int b, int range) {
*/
@Override
public BigInteger getPrimaryNumber(int range) {
return null;
int[] numbers = new int[range * range];
ArrayList<BigInteger> arrayNumbers = new ArrayList<>();
for (int i = 2; i < numbers.length; i++) {
numbers[i] = i;
if (BigInteger.valueOf(numbers[i]).isProbablePrime(i)) {
arrayNumbers.add(BigInteger.valueOf(numbers[i]));
}
}
return arrayNumbers.get(range);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalField;
import java.util.GregorianCalendar;
import java.util.regex.Pattern;

public class SimpleDateService implements DateService {

Expand All @@ -14,9 +19,16 @@ public class SimpleDateService implements DateService {
*/
@Override
public String parseDate(LocalDate localDate) {
return null;
String month = "0";
if (localDate.getMonthValue() < 10) {
month = month + localDate.getMonthValue();
} else {
month = "" + localDate.getMonthValue();
}
return String.format("%d-%2s-%d", localDate.getDayOfMonth(), month, localDate.getYear());
}


/**
* Метод парсит строку в дату
*
Expand All @@ -25,7 +37,12 @@ public String parseDate(LocalDate localDate) {
*/
@Override
public LocalDateTime parseString(String string) {
return null;
int year = Integer.parseInt(string.substring(0, 4));
int mount = Integer.parseInt(string.substring(5, 7));
int days = Integer.parseInt(string.substring(8, 10));
int hours = Integer.parseInt(string.substring(11, 13));
int minutes = Integer.parseInt(string.substring(14, 16));
return LocalDateTime.of(year, mount, days, hours, minutes);
}

/**
Expand All @@ -37,7 +54,7 @@ public LocalDateTime parseString(String string) {
*/
@Override
public String convertToCustomFormat(LocalDate localDate, DateTimeFormatter formatter) {
return null;
return localDate.format(formatter);
}

/**
Expand All @@ -47,7 +64,12 @@ public String convertToCustomFormat(LocalDate localDate, DateTimeFormatter forma
*/
@Override
public long getNextLeapYear() {
return 0;
long year = Year.now().getValue();
do {
year++;
} while (!Year.isLeap(year));

return year;
}

/**
Expand All @@ -57,7 +79,14 @@ public long getNextLeapYear() {
*/
@Override
public long getSecondsInYear(int year) {
return 0;
int daysInYear = 365;
int hoursInDay = 24;
int minutesInHours = 60;
int secondsInMinutes = 60;
if (Year.isLeap(year)) {
daysInYear = 366;
}
return daysInYear * hoursInDay * minutesInHours * secondsInMinutes;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.epam.izh.rd.online.service;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SimpleRegExpService implements RegExpService {

/**
Expand All @@ -11,17 +15,55 @@ public class SimpleRegExpService implements RegExpService {
*/
@Override
public String maskSensitiveData() {
return null;
String allMaskedText = "";
try (FileReader fileReader = new FileReader("src/main/resources/sensitive_data.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
) {
String allText = bufferedReader.readLine();
Pattern pattern = Pattern.compile("\\b([0-9]{4})\\s[0-9]{0,9}\\s[0-9]{0,9}\\s([0-9]{4})\\b");
Matcher matcher = pattern.matcher(allText);
String maskForCard = "$1 **** **** $2";
if (matcher.find()) {
allMaskedText = matcher.replaceAll(maskForCard);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return allMaskedText;
}

/**
* Метод должен считыввать файл sensitive_data.txt (из директории resources) и заменять плейсхолдер ${payment_amount} и ${balance} на заданные числа. Метод должен
* Метод должен считывать файл sensitive_data.txt (из директории resources) и заменять плейсхолдер ${payment_amount} и ${balance} на заданные числа. Метод должен
* содержать регулярное выражение для поиска плейсхолдеров
*
* @return обработанный текст
*/
@Override
public String replacePlaceholders(double paymentAmount, double balance) {
return null;
String replacePlaceholderAllText = "";
try (FileReader fileReader = new FileReader("src/main/resources/sensitive_data.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
) {
String allText = bufferedReader.readLine();
Pattern patternForBalance = Pattern.compile("\\$\\{balance\\}");
Matcher matcherBalance = patternForBalance.matcher(allText);
String balanceReplace = String.format("%.0f", balance);
String paymentReplace = String.format("%.0f", paymentAmount);
if (matcherBalance.find()) {
String replacePlaceholderBalance = matcherBalance.replaceAll(balanceReplace);
Pattern patternForPayment = Pattern.compile("\\$\\{payment_amount\\}");
Matcher matcherPayment = patternForPayment.matcher(replacePlaceholderBalance);
if (matcherPayment.find()) {
replacePlaceholderAllText = matcherPayment.replaceAll(paymentReplace);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return replacePlaceholderAllText;
}
}
Loading