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>
7 changes: 7 additions & 0 deletions src/main/java/com/epam/izh/rd/online/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package com.epam.izh.rd.online;

import com.epam.izh.rd.online.repository.FileRepository;
import com.epam.izh.rd.online.repository.SimpleFileRepository;

public class Main {
public static void main(String[] args) {
// SimpleFileRepository simpleFileRepository = new SimpleFileRepository();
// simpleFileRepository.createFile("testDirCreateFile/", "sex.txt");
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package com.epam.izh.rd.online.repository;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class SimpleFileRepository implements FileRepository {

/**
* Метод рекурсивно подсчитывает количество файлов в директории
*
* @param path путь до директори
* @param path путь до директории
* @return файлов, в том числе скрытых
*/
@Override
public long countFilesInDirectory(String path) {
return 0;
File dir = new File(path); //path указывает на директорию
File[] arrFiles = dir.listFiles();
assert arrFiles != null;
List<File> lst = Arrays.asList(arrFiles);
return lst.size();
}

/**
Expand All @@ -21,7 +30,12 @@ public long countFilesInDirectory(String path) {
*/
@Override
public long countDirsInDirectory(String path) {
return 0;

File dir = new File(path); //path указывает на директорию
File[] arrFiles = dir.listFiles();
assert arrFiles != null;
List<File> lst = Arrays.asList(arrFiles);
return lst.size() + 1;
}

/**
Expand All @@ -44,9 +58,19 @@ public void copyTXTFiles(String from, String to) {
*/
@Override
public boolean createFile(String path, String name) {
return false;
File file = new File(path + name);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if (file.exists()){
}return true;
}




/**
* Метод считывает тело файла .txt из папки src/main/resources
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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

public class SimpleBigNumbersService implements BigNumbersService {

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

/**
Expand All @@ -24,6 +29,35 @@ public BigDecimal getPrecisionNumber(int a, int b, int range) {
*/
@Override
public BigInteger getPrimaryNumber(int range) {
return null;
int primaryNumber = 0;

List<Integer> primes = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
if (isPrime(i)) {
primes.add(i);
primaryNumber++;
if (primaryNumber == range + 1){
primaryNumber = i;
break;
}
}
}
return BigInteger.valueOf(primaryNumber);
}

private boolean isPrime(int n) {
if (n == 2 || n == 3) {
return true;
} else if (n <= 1 || (n % 2) == 0 || (n % 3) == 0) {
return false;
}
int i = 5;
while (i * i <= n) {
if ((n % i) == 0 || (n % (i + 2)) == 0) {
return false;
}
i += 6;
}
return true;
}
}
}
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,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,9 +26,11 @@ public String parseDate(LocalDate localDate) {
*/
@Override
public LocalDateTime parseString(String string) {
return null;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return LocalDateTime.parse(string, formatter);
}


/**
* Метод конвертирует дату в строку с заданным форматом
*
Expand All @@ -37,7 +40,7 @@ public LocalDateTime parseString(String string) {
*/
@Override
public String convertToCustomFormat(LocalDate localDate, DateTimeFormatter formatter) {
return null;
return localDate.format(formatter);
}

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

/**
Expand All @@ -57,8 +66,7 @@ public long getNextLeapYear() {
*/
@Override
public long getSecondsInYear(int year) {
return 0;
Year year1 = Year.of(year);
return year1.length()*86400;
}


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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SimpleRegExpService implements RegExpService {

/**
Expand All @@ -11,7 +17,19 @@ public class SimpleRegExpService implements RegExpService {
*/
@Override
public String maskSensitiveData() {
return null;
String path = "src/main/resources/sensitive_data.txt";
String text = null;
String newText = null;

try (BufferedReader br = new BufferedReader(new FileReader(path))) {
text = br.readLine();
} catch (IOException e) {
System.out.println("Файл не найден");
}
Pattern pattern = Pattern.compile("(\\s\\d{4}\\s)\\d{4}\\s\\d{4}\\s(\\d{4}\\s)"); //("[0-9]\\s[\\d]{4}\\s[\\d]{4}\\s")
Matcher matcher = pattern.matcher(text);
newText = matcher.replaceAll("$1**** **** $2");
return newText;
}

/**
Expand All @@ -22,6 +40,27 @@ public String maskSensitiveData() {
*/
@Override
public String replacePlaceholders(double paymentAmount, double balance) {
return null;
String path = "src/main/resources/sensitive_data.txt";
String text = null;
String newText = null;

try (BufferedReader br = new BufferedReader(new FileReader(path))) {
text = br.readLine();
} catch (IOException e) {
System.out.println("Файл не найден");
}

String stringPaymentAmount = String.valueOf((int) paymentAmount);
Pattern paymentPattern = Pattern.compile("\\$\\{payment_amount\\}");
Matcher paymentMatcher = paymentPattern.matcher(text);
newText = paymentMatcher.replaceFirst(stringPaymentAmount);

String stringBalance = String.valueOf((int) balance);
Pattern balancePattern = Pattern.compile("\\$\\{balance\\}");
Matcher balanceMatcher = balancePattern.matcher(newText);
newText = balanceMatcher.replaceFirst(stringBalance);

return newText;
}
}

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,12 @@ public boolean isQuestionString(String text) {
*/
@Override
public String concatenate(String... elements) {
return null; //TODO
StringBuilder string = new StringBuilder();

for (String element : elements) {
string.append(element);
}
return string.toString();
}

/**
Expand All @@ -47,8 +54,16 @@ public String concatenate(String... elements) {
*/
@Override
public String toJumpCase(String text) {
return null; //TODO
}
char[] chars = text.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (i % 2 == 0) {
chars[i] = Character.toLowerCase(chars[i]);
} else {
chars[i] = Character.toUpperCase(chars[i]);
}
}
return String.valueOf(chars);
}

/**
* Метод определяет, является ли строка палиндромом.
Expand All @@ -59,6 +74,10 @@ public String toJumpCase(String text) {
*/
@Override
public boolean isPalindrome(String string) {
return false; //TODO
StringBuilder stringBuilder = new StringBuilder(string);
String str1 = stringBuilder.reverse().toString();
if (string.equals("")){
return false;
}else return string.replaceAll("\\s+", "").toLowerCase(Locale.ROOT).equals(str1.toLowerCase(Locale.ROOT).replaceAll("\\s+", ""));
}
}