Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature branch #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions java-collections.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<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>
19 changes: 19 additions & 0 deletions src/main/java/com/epam/izh/rd/online/service/ForEx.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.epam.izh.rd.online.service;

import java.util.ArrayList;
import java.util.List;

public class ForEx {
public static void main(String[] args) {
String text ="первое слово, дороже второго";
List<String> list = new ArrayList<>();
String[] subStr;
String delimeter = "\\."; // Разделитель
subStr = text.split(delimeter);
// Вывод результата на экран
for(int i = 0; i < subStr.length; i++) {
list.add(subStr[i]);
}
System.out.println(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.epam.izh.rd.online.helper.Direction;

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

import static java.util.Collections.*;

Expand All @@ -23,7 +27,11 @@ public class SimpleTextStatisticsAnalyzer implements TextStatisticsAnalyzer {
*/
@Override
public int countSumLengthOfWords(String text) {
return 0;
List<String> list = getWords(text);
int count = 0;
for(int i = 0; i<list.size(); i++)
count = count + list.get(i).length();
return count;
}

/**
Expand All @@ -34,7 +42,9 @@ public int countSumLengthOfWords(String text) {
*/
@Override
public int countNumberOfWords(String text) {
return 0;
List<String> list = getWords(text);
int count = list.size();
return count;
}

/**
Expand All @@ -44,7 +54,11 @@ public int countNumberOfWords(String text) {
*/
@Override
public int countNumberOfUniqueWords(String text) {
return 0;
List<String> list = getWords(text);
Set<String> set = new HashSet<>();
for(int i = 0; i<list.size();i++)
set.add(list.get(i));
return set.size();
}

/**
Expand All @@ -57,7 +71,16 @@ public int countNumberOfUniqueWords(String text) {
*/
@Override
public List<String> getWords(String text) {
return emptyList();
Pattern pattern1 = Pattern.compile("[^A-Z a-z\n]");
Matcher matcher = pattern1.matcher(text);
String str = matcher.replaceAll("");
List<String> list = new ArrayList<>();
String strList[];
strList=str.split("[ \n]+");
for (int i=0; i<strList.length; i++){
list.add(strList[i]);
}
return list;
}

/**
Expand All @@ -70,7 +93,11 @@ public List<String> getWords(String text) {
*/
@Override
public Set<String> getUniqueWords(String text) {
return emptySet();
List<String> list = getWords(text);
Set<String> set = new HashSet<>();
for(int i = 0; i<list.size();i++)
set.add(list.get(i));
return set;
}

/**
Expand All @@ -82,7 +109,15 @@ public Set<String> getUniqueWords(String text) {
*/
@Override
public Map<String, Integer> countNumberOfWordsRepetitions(String text) {
return emptyMap();
List<String> list = getWords(text);
Map<String, Integer> map = new HashMap<>();
for(int i = 0; i<list.size(); i++){
if(map.containsKey(list.get(i))){
map.put(list.get(i), map.get(list.get(i))+1);
}
else map.put(list.get(i), 1);
}
return map;
}

/**
Expand All @@ -95,6 +130,16 @@ public Map<String, Integer> countNumberOfWordsRepetitions(String text) {
*/
@Override
public List<String> sortWordsByLength(String text, Direction direction) {
return emptyList();
List<String> list = getWords(text);
Comparator<String> comp = Comparator.comparing(String::length);

if (direction==Direction.ASC) {
list.sort(comp);
}
else if (direction==Direction.DESC) {
list.sort(comp.reversed());
}

return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.epam.izh.rd.online.helper.Direction;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Collections.*;

Expand All @@ -16,36 +17,63 @@
public class StreamApiTextStatisticsAnalyzer implements TextStatisticsAnalyzer {
@Override
public int countSumLengthOfWords(String text) {
return 0;
List<String> list = getWords(text);
return list.stream().reduce(0, (sum, s) -> sum += s.length(), Integer::sum);
}

@Override
public int countNumberOfWords(String text) {
return 0;
List<String> list = getWords(text);
return list.stream().reduce(0, (sum, s) -> sum += 1, Integer::sum);
}

@Override
public int countNumberOfUniqueWords(String text) {
return 0;
List<String> list = getWords(text);
List<String> listApi = list.stream().distinct().collect(Collectors.toList());
return listApi.size();
}

@Override
public List<String> getWords(String text) {
return emptyList();
Pattern pattern1 = Pattern.compile("[^A-Z a-z\n]");
Matcher matcher = pattern1.matcher(text);
String str = matcher.replaceAll("");
String strList[];
strList=str.split("[ \n]+");
List<String> list = Arrays.stream(strList).collect(Collectors.toList());
return list;
}

@Override
public Set<String> getUniqueWords(String text) {
return emptySet();
Set<String> set = getWords(text).stream().collect(Collectors.toSet());
return set;
}

@Override
public Map<String, Integer> countNumberOfWordsRepetitions(String text) {
return emptyMap();
List<String> list = getWords(text);
Set<String> set = list.stream().collect(Collectors.toSet());
Map<String, Integer> map = new HashMap<>();
set.stream().forEach((s) -> map.put(s, counter(s, list)));
return map;
}

private int counter(String word, List<String> list) {
return (int) list.stream().filter(s -> s.equals(word)).count();
}

@Override
public List<String> sortWordsByLength(String text, Direction direction) {
return emptyList();
Comparator<String> comp = Comparator.comparing(String::length);

if (direction==Direction.ASC) {
return getWords(text).stream().sorted(comp).collect(Collectors.toList());
}
else if (direction==Direction.DESC) {
return getWords(text).stream().sorted(comp.reversed()).collect(Collectors.toList());
}
return null;
}
}