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
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,11 @@
package com.epam.izh.rd.online.repository;

import java.io.*;
import java.nio.file.Files;
import java.util.List;

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

public class SimpleFileRepository implements FileRepository {

/**
Expand All @@ -10,7 +16,16 @@ public class SimpleFileRepository implements FileRepository {
*/
@Override
public long countFilesInDirectory(String path) {
return 0;
File dir = new File("src/main/resources/" + path);
long counter = 0;
if (dir.isDirectory()) {
for (File file : dir.listFiles()) {
counter += countFilesInDirectory(path + "/" + file.getName());
}
} else {
counter++;
}
return counter;
}

/**
Expand All @@ -21,7 +36,16 @@ public long countFilesInDirectory(String path) {
*/
@Override
public long countDirsInDirectory(String path) {
return 0;
long counter = 1;
File dir = new File("src/main/resources/" + path);
if (dir.isDirectory()) {
for (File file : dir.listFiles()){
if (file.isDirectory()){
counter += countDirsInDirectory(path + "/" + file.getName());
}
}
}
return counter;
}

/**
Expand All @@ -32,9 +56,19 @@ public long countDirsInDirectory(String path) {
*/
@Override
public void copyTXTFiles(String from, String to) {
return;
File originalDir = new File(from);
File finalDir = new File(to);
if (!finalDir.exists()) {
finalDir.mkdir();
}
try {
Files.copy(originalDir.toPath(), finalDir.toPath(), REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}


/**
* Метод создает файл на диске с расширением txt
*
Expand All @@ -44,6 +78,18 @@ public void copyTXTFiles(String from, String to) {
*/
@Override
public boolean createFile(String path, String name) {
File directory = new File(getClass().getResource("/").getPath() + "/" + path);

if (!directory.exists()) {
directory.mkdir();
}

File file = new File(directory + "/" + name);
try {
return file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}

Expand All @@ -55,6 +101,13 @@ public boolean createFile(String path, String name) {
*/
@Override
public String readFileFromResources(String fileName) {
return null;
File file = new File("src/main/resources/", fileName);
try {
List<String> result = Files.readAllLines(file.toPath());
return result.get(0);
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

public class SimpleBigNumbersService implements BigNumbersService {

Expand All @@ -13,7 +14,9 @@ public class SimpleBigNumbersService implements BigNumbersService {
*/
@Override
public BigDecimal getPrecisionNumber(int a, int b, int range) {
return null;
BigDecimal aNew = new BigDecimal(a);
BigDecimal bNew = new BigDecimal(b);
return aNew.divide(bNew, range, RoundingMode.HALF_UP);
}

/**
Expand All @@ -24,6 +27,10 @@ public BigDecimal getPrecisionNumber(int a, int b, int range) {
*/
@Override
public BigInteger getPrimaryNumber(int range) {
return null;
BigInteger primaryNumber = new BigInteger("2");
for(int i = 0; i < range; i++){
primaryNumber = primaryNumber.nextProbablePrime();
}
return primaryNumber;
}
}
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.Period;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.stream.IntStream;

import static java.time.LocalDate.now;

public class SimpleDateService implements DateService {

Expand All @@ -14,7 +19,7 @@ public class SimpleDateService implements DateService {
*/
@Override
public String parseDate(LocalDate localDate) {
return null;
return localDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
}

/**
Expand All @@ -25,7 +30,7 @@ public String parseDate(LocalDate localDate) {
*/
@Override
public LocalDateTime parseString(String string) {
return null;
return LocalDateTime.parse(string, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}

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

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

/**
Expand All @@ -57,7 +66,7 @@ public long getNextLeapYear() {
*/
@Override
public long getSecondsInYear(int year) {
return 0;
return (Year.isLeap(year) ? 3600 * 24 * 366 : 3600 * 24 * 365);
}


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SimpleRegExpService implements RegExpService {

/**
Expand All @@ -11,6 +20,24 @@ public class SimpleRegExpService implements RegExpService {
*/
@Override
public String maskSensitiveData() {
File file = new File("src/main/resources", "sensitive_data.txt");
Pattern pattern = Pattern.compile("\\d{4}\\s(\\d{4}?)\\s(\\d{4}?)\\s\\d{4}");
Matcher matcher;
int counter = 0;
try {
List<String> result = Files.readAllLines(file.toPath());
while (counter < result.size()){
matcher = pattern.matcher(result.get(counter));
while (matcher.find()) {
String[] parts = matcher.group().split(" ");
result.set(counter, result.get(counter).replaceFirst(String.valueOf(pattern), parts[0] + " **** **** " + parts[parts.length - 1]));
}
counter++;
}
return result.get(0);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

Expand All @@ -22,6 +49,21 @@ public String maskSensitiveData() {
*/
@Override
public String replacePlaceholders(double paymentAmount, double balance) {
return null;
String text = "";
try (BufferedReader reader = new BufferedReader(new FileReader("src/main/resources/sensitive_data.txt"))) {
text = reader.readLine();
Pattern pattern = Pattern.compile("\\$\\{.*?}");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
if (matcher.group().equals("${payment_amount}")) {
text = text.replaceAll("\\$\\{payment_amount}", String.valueOf((int)paymentAmount));
} else if (matcher.group().equals("${balance}")) {
text = text.replaceAll("\\$\\{balance}", String.valueOf((int)balance));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return text;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.epam.izh.rd.online.service;

import java.util.Locale;

public class SimpleTextService implements TextService {

/**
Expand All @@ -13,7 +15,7 @@ public class SimpleTextService implements TextService {
*/
@Override
public String removeString(String base, String remove) {
return null; //TODO
return base.replaceAll(remove, "");
}

/**
Expand All @@ -24,7 +26,7 @@ public String removeString(String base, String remove) {
*/
@Override
public boolean isQuestionString(String text) {
return false; //TODO
return text.endsWith("?");
}

/**
Expand All @@ -35,7 +37,11 @@ public boolean isQuestionString(String text) {
*/
@Override
public String concatenate(String... elements) {
return null; //TODO
String newStr = "";
for (String str : elements) {
newStr = newStr.concat(str);
}
return newStr;
}

/**
Expand All @@ -47,7 +53,19 @@ public String concatenate(String... elements) {
*/
@Override
public String toJumpCase(String text) {
return null; //TODO
char[] def = text.toCharArray();
text = "";
boolean flag = true;
for (char ch : def){
if (flag) {
text += Character.toLowerCase(ch);
flag = false;
} else {
text += Character.toUpperCase(ch);
flag = true;
}
}
return text;
}

/**
Expand All @@ -59,6 +77,11 @@ public String toJumpCase(String text) {
*/
@Override
public boolean isPalindrome(String string) {
return false; //TODO
String raw = string.toLowerCase(Locale.ROOT).replace(" ", "").replace(",", "");
String palindrome = new StringBuilder(raw).reverse().toString();
if (raw.isEmpty()) {
return false;
}
return palindrome.equals(raw);
}
}
Empty file.
Empty file.
Empty file added testDirCreateFile/newFile.txt
Empty file.