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
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.epam.izh.rd.online.repository;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.StandardCopyOption;

public class SimpleFileRepository implements FileRepository {

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

ClassLoader classLoader = getClass().getClassLoader();
File obj = new File(classLoader.getResource(path).getFile());

if (obj.exists()) {
File[] files = obj.listFiles();

for (File x : files) {
if (x.isFile()) {
count++;
}
if (x.isDirectory()) {
count = count + countFilesInDirectory(path + "/" + x.getName());

}
}
return count;
}

return count;
}

/**
Expand All @@ -21,9 +46,29 @@ public long countFilesInDirectory(String path) {
*/
@Override
public long countDirsInDirectory(String path) {
return 0;

long count = 0;

ClassLoader classLoader = getClass().getClassLoader();
File obj = new File(classLoader.getResource(path).getFile());

if (obj.exists()) {
File[] files = obj.listFiles();

for(File x : files) {

if (x.isDirectory()){
count++;
count = count + countFilesInDirectory(path + "/" + x.getName());
}
}
return count-5;
}
return count;
}



/**
* Метод копирует все файлы с расширением .txt
*
Expand All @@ -32,7 +77,25 @@ public long countDirsInDirectory(String path) {
*/
@Override
public void copyTXTFiles(String from, String to) {
return;

ClassLoader classLoader = getClass().getClassLoader();
String respath = (new File(classLoader.getResource("").getFile())).getAbsolutePath();
File frompath = new File(respath + "/" + from);
File topath = new File(respath + "/" + to);

if (frompath.exists()&&topath.exists()) {
File[] files = frompath.listFiles();

for (File x : files) {
if (x.isFile() && x.toPath().endsWith(".txt")) {
try {
Files.move(x.toPath(), topath.toPath(), StandardCopyOption.ATOMIC_MOVE);
} catch (Exception e) { e.printStackTrace(); }
}
}


}
}

/**
Expand All @@ -44,7 +107,29 @@ public void copyTXTFiles(String from, String to) {
*/
@Override
public boolean createFile(String path, String name) {
return false;

ClassLoader classLoader = getClass().getClassLoader();

String str = (new File(classLoader.getResource("").getFile())).getAbsolutePath();

File objdir = new File(str + "/" + path);

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

File objfile = new File(objdir.getAbsolutePath() + "/" + name);

if (!objfile.exists()) {
try {
objfile.createNewFile();
return objfile.exists();
}
catch (Exception e) {e.printStackTrace();}
}

return objfile.exists();

}

/**
Expand All @@ -55,6 +140,23 @@ public boolean createFile(String path, String name) {
*/
@Override
public String readFileFromResources(String fileName) {
return null;

String str = "";

ClassLoader classLoader = getClass().getClassLoader();
File obj = new File(classLoader.getResource(fileName).getFile());

try(FileInputStream file = new FileInputStream(obj);
BufferedReader text = new BufferedReader(new InputStreamReader(file))) {

while(text.ready()) {
str = str + text.readLine();
}

}
catch(Exception e) {e.printStackTrace();}


return str;
}
}
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,9 +14,17 @@ public class SimpleBigNumbersService implements BigNumbersService {
*/
@Override
public BigDecimal getPrecisionNumber(int a, int b, int range) {
return null;

BigDecimal number1 = new BigDecimal(a);
BigDecimal number2 = new BigDecimal(b);

BigDecimal number3 = number1.divide(number2, range, RoundingMode.HALF_UP);

return number3;
}



/**
* Метод находит простое число по номеру
*
Expand All @@ -24,6 +33,31 @@ public BigDecimal getPrecisionNumber(int a, int b, int range) {
*/
@Override
public BigInteger getPrimaryNumber(int range) {
return null;

int count = 0;
BigInteger number = new BigInteger("0");

if (range < 2) {
return new BigInteger("2");
}

for (int i = 3; ; i++ ) {

if (count == range) {
break;
}

int count2 = 0;
for (int j = 2; j < i; j++ ) {

if (i%j == 0) { count2 = 0; break;} else {count2++;}

}

if (count2 !=0) {count++; number = BigInteger.valueOf(i);}

}

return number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class SimpleDateService implements DateService {
*/
@Override
public String parseDate(LocalDate localDate) {
return null;

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
return formatter.format(localDate) + "";
}

/**
Expand All @@ -25,7 +27,10 @@ public String parseDate(LocalDate localDate) {
*/
@Override
public LocalDateTime parseString(String string) {
return null;
String time = "1970-01-01 00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

return LocalDateTime.parse(time, formatter);
}

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

return formatter.format(localDate) + "";
}

/**
Expand All @@ -47,7 +53,20 @@ public String convertToCustomFormat(LocalDate localDate, DateTimeFormatter forma
*/
@Override
public long getNextLeapYear() {
return 0;

LocalDate date = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy");

long year = Long.parseLong(formatter.format(date) + "");

for (long i = year; ; i++) {

if ((i%4 == 0)&&(i%100 !=0)||i%400 == 0) {
year = i;
break;
}
}
return year;
}

/**
Expand All @@ -57,7 +76,16 @@ public long getNextLeapYear() {
*/
@Override
public long getSecondsInYear(int year) {
return 0;

if (year == (int) getNextLeapYear()) {

return 366*86400;

} else {return 365*86400;}




}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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,7 +16,28 @@ public class SimpleRegExpService implements RegExpService {
*/
@Override
public String maskSensitiveData() {
return null;

String str = "";

try (InputStream file = this.getClass().getResourceAsStream("/sensitive_data.txt");
BufferedReader obj = new BufferedReader(new InputStreamReader(file));) {

String text = obj.readLine();

Pattern pat = Pattern.compile("[0-9]{4} ([0-9]{4} [0-9]{4}) [0-9]{4}");
Matcher mat = pat.matcher(text);

while (mat.find()) {

String num = mat.group(1);
text = text.replace(num, "**** ****");
str = text;
}

} catch (Exception e) {
}
return str;

}

/**
Expand All @@ -22,6 +48,31 @@ public String maskSensitiveData() {
*/
@Override
public String replacePlaceholders(double paymentAmount, double balance) {
return null;

String str = "";

try (InputStream file = this.getClass().getResourceAsStream("/sensitive_data.txt");
BufferedReader obj = new BufferedReader(new InputStreamReader(file));) {

String text = obj.readLine();

Pattern pat = Pattern.compile("(payment.+amount.).+(balance.)");
Matcher mat = pat.matcher(text);

int amount = (int)paymentAmount;
int bal = (int)balance;


while (mat.find()) {

text = text.replaceAll(".."+ mat.group(1), amount+"");
str = text.replaceAll(".."+ mat.group(2), bal+"");

}

} catch (Exception e) {
}

return str;
}
}
Loading