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

import java.io.*;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


public class SimpleFileRepository implements FileRepository {

/**
Expand All @@ -10,7 +17,17 @@ public class SimpleFileRepository implements FileRepository {
*/
@Override
public long countFilesInDirectory(String path) {
return 0;
long sum = 0 ;

File[] files = new File("./src/main/resources/" + path).listFiles() ;

for (File file : files ) {
if(file.isFile())
sum++;
else
sum+= countFilesInDirectory(path + "/" + file.getName());
}
return sum;
}

/**
Expand All @@ -21,7 +38,15 @@ public long countFilesInDirectory(String path) {
*/
@Override
public long countDirsInDirectory(String path) {
return 0;
long sum = 1 ;

File[] files = new File("./src/main/resources/" + path).listFiles() ;

for (File file : files ) {
if(file.isDirectory())
sum+= countDirsInDirectory(path + "/" + file.getName());
}
return sum;
}

/**
Expand All @@ -32,7 +57,26 @@ public long countDirsInDirectory(String path) {
*/
@Override
public void copyTXTFiles(String from, String to) {
return;
Path file = Paths.get(from) ;
Path fileName = file.getFileName() ;
System.out.println(fileName);
Path fileCopy = Paths.get(to) ;
System.out.println(fileCopy);
System.out.println(fileName.toString().endsWith(".txt"));
Path directory = fileCopy.getParent() ;
try {
Files.createDirectories(directory) ;
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(Files.exists(Paths.get(String.valueOf(directory))));


try {
Files.copy(file, fileCopy) ;
} catch (IOException e) {
e.printStackTrace();
}
}

/**
Expand All @@ -44,7 +88,21 @@ public void copyTXTFiles(String from, String to) {
*/
@Override
public boolean createFile(String path, String name) {
return false;
try {
Path pathAbs = Paths.get(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()) ;
path = pathAbs.toString() + "/" + path ;
} catch (URISyntaxException e) {
e.printStackTrace();
}
File fold = new File(path) ;
File file = new File(path + "/" + name) ;
fold.mkdir() ;
try {
file.createNewFile() ;
} catch (IOException e) {
e.printStackTrace();
}
return file.exists() ;
}

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

}
}
4 changes: 2 additions & 2 deletions src/main/java/com/epam/izh/rd/online/service/DateService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.epam.izh.rd.online.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public interface DateService {

String parseDate(LocalDate localDate);

LocalDateTime parseString(String string);
TemporalAccessor parseString(String string);

String convertToCustomFormat(LocalDate localDate, DateTimeFormatter formatter);

Expand Down
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,8 @@ public class SimpleBigNumbersService implements BigNumbersService {
*/
@Override
public BigDecimal getPrecisionNumber(int a, int b, int range) {
return null;
BigDecimal result = new BigDecimal(a).divide(new BigDecimal(b),2, RoundingMode.HALF_UP) ;
return result;
}

/**
Expand All @@ -24,6 +26,10 @@ public BigDecimal getPrecisionNumber(int a, int b, int range) {
*/
@Override
public BigInteger getPrimaryNumber(int range) {
return null;
BigInteger result = new BigInteger("2") ;
for (int i = 1; i<=range ; i++){
result = result.nextProbablePrime();
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.format.DateTimeFormatter;

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

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

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

/**
Expand All @@ -47,6 +50,9 @@ public String convertToCustomFormat(LocalDate localDate, DateTimeFormatter forma
*/
@Override
public long getNextLeapYear() {
for(int i = 2021; i<2025;i++){
if(Year.of(i).isLeap()) return i ;
}
return 0;
}

Expand All @@ -57,7 +63,7 @@ public long getNextLeapYear() {
*/
@Override
public long getSecondsInYear(int year) {
return 0;
return LocalDate.of(year,1,1).lengthOfYear()*3600*24;
}


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

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SimpleRegExpService implements RegExpService {

/**
Expand All @@ -11,7 +18,23 @@ public class SimpleRegExpService implements RegExpService {
*/
@Override
public String maskSensitiveData() {
return null;

try (FileReader con = new FileReader("src/main/resources/sensitive_data.txt")){
BufferedReader cont = new BufferedReader (con) ;
String text = cont.readLine();
StringBuilder file = new StringBuilder(text);
Pattern pat = Pattern.compile("\\s*\\d{4}\\s+(\\d{4}\\s+\\d{4})\\s+\\d{4}") ;
Matcher mat = pat.matcher(file) ;
while (mat.find()) {
file.replace(mat.start(1),mat.end(1),"**** ****") ;
}
return file.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null ;
}

/**
Expand All @@ -22,6 +45,17 @@ public String maskSensitiveData() {
*/
@Override
public String replacePlaceholders(double paymentAmount, double balance) {
return null;
String payment = "${payment_amount}";
String balance1 = "${balance}";
String pay = String.valueOf((int)paymentAmount);
String bal = String.valueOf((int)balance) ;
Path path = Paths.get("src/main/resources/sensitive_data.txt");
try {
String path1 = new String(Files.readAllBytes(path)).replace(payment,pay).replace(balance1,bal) ;
return path1;
} catch (IOException e) {
e.printStackTrace();
}
return null ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SimpleTextService implements TextService {
*/
@Override
public String removeString(String base, String remove) {
return null; //TODO
return base.replaceAll(remove,""); //TODO
}

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

/**
Expand All @@ -35,7 +35,11 @@ public boolean isQuestionString(String text) {
*/
@Override
public String concatenate(String... elements) {
return null; //TODO
StringBuilder text = new StringBuilder();
for (String element: elements ) {
text.append(element);
}
return text.toString(); //TODO
}

/**
Expand All @@ -47,7 +51,15 @@ public String concatenate(String... elements) {
*/
@Override
public String toJumpCase(String text) {
return null; //TODO
char [] jump = text.toCharArray() ;
for (int i = 0 ; i < text.length() ; i++ ){
if ((i+2)%2 ==0) {
jump[i] = Character.toLowerCase(text.charAt(i)) ;
} else {
jump[i] = Character.toUpperCase(text.charAt(i)) ;
}
}
return new String(jump); //TODO
}

/**
Expand All @@ -59,6 +71,8 @@ public String toJumpCase(String text) {
*/
@Override
public boolean isPalindrome(String string) {
return false; //TODO
StringBuilder revString = new StringBuilder(string.replaceAll(" ","")).reverse() ;

return string.replaceAll(" ","").equalsIgnoreCase(String.valueOf(revString))&&!string.equals(""); //TODO
}
}
2 changes: 1 addition & 1 deletion src/main/resources/sensitive_data.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Вчера вечером со счета номер 4301 0234 2145 2140 был совершен перевод на счет 5042 2012 0532 2043 в размере ${payment_amount} рублей. На счету осталось ${balance} рублей
Вчера вечером со счета номер 4301 0234 2145 2140 был совершен перевод на счет 5042 2012 0532 2043 в размере ${payment_amount} рублей. На счету осталось ${balance} рублей