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

Done #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #19

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>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import java.util.*;

import static java.util.Collections.*;

/**
* Совет:
* Начните с реализации метода {@link SimpleTextStatisticsAnalyzer#getWords(String)}.
Expand All @@ -21,9 +19,16 @@ public class SimpleTextStatisticsAnalyzer implements TextStatisticsAnalyzer {
*
* @param text текст
*/

@Override
public int countSumLengthOfWords(String text) {
return 0;
ArrayList<String> words = (ArrayList<String>) getWords(text);
int lengthOfWords = 0;
for (String word : words) {
lengthOfWords = word.length() + lengthOfWords;
}
return lengthOfWords;

}

/**
Expand All @@ -34,7 +39,7 @@ public int countSumLengthOfWords(String text) {
*/
@Override
public int countNumberOfWords(String text) {
return 0;
return getWords(text).size();
}

/**
Expand All @@ -44,7 +49,7 @@ public int countNumberOfWords(String text) {
*/
@Override
public int countNumberOfUniqueWords(String text) {
return 0;
return getUniqueWords(text).size();
}

/**
Expand All @@ -57,7 +62,7 @@ public int countNumberOfUniqueWords(String text) {
*/
@Override
public List<String> getWords(String text) {
return emptyList();
return new ArrayList<>(Arrays.asList(text.split("\\W+")));
}

/**
Expand All @@ -70,7 +75,7 @@ public List<String> getWords(String text) {
*/
@Override
public Set<String> getUniqueWords(String text) {
return emptySet();
return new HashSet<>(getWords(text));
}

/**
Expand All @@ -82,7 +87,13 @@ public Set<String> getUniqueWords(String text) {
*/
@Override
public Map<String, Integer> countNumberOfWordsRepetitions(String text) {
return emptyMap();
List<String> words = getWords(text);
Map<String, Integer> countNumberOfWordsRepetitionsMap = new LinkedHashMap<>();
for (String word : words) {
int repetitionCount = Collections.frequency(words, word);
countNumberOfWordsRepetitionsMap.put(word, repetitionCount);
}
return countNumberOfWordsRepetitionsMap;
}

/**
Expand All @@ -95,6 +106,16 @@ public Map<String, Integer> countNumberOfWordsRepetitions(String text) {
*/
@Override
public List<String> sortWordsByLength(String text, Direction direction) {
return emptyList();
ArrayList<String> words = (ArrayList<String>) getWords(text);
words.sort(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return direction == Direction.ASC ? o1.length() - o2.length() : o2.length() - o1.length();
}
});

return words;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

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.util.*;
import java.util.stream.Collectors;

import static java.util.Collections.*;

/**
* Данный класс обязан использовать StreamApi из функционала Java 8. Функциональность должна быть идентична
Expand All @@ -16,36 +13,46 @@
public class StreamApiTextStatisticsAnalyzer implements TextStatisticsAnalyzer {
@Override
public int countSumLengthOfWords(String text) {
return 0;
return getWords(text).stream().mapToInt(String::length).sum();
}

@Override
public int countNumberOfWords(String text) {
return 0;
return (int) getWords(text).stream().count();
}

@Override
public int countNumberOfUniqueWords(String text) {
return 0;
return (int) getWords(text).stream().distinct().count();

}

@Override
public List<String> getWords(String text) {
return emptyList();
ArrayList<String> words = new ArrayList<>();
String[] wordsArray = text.split("\\W+");
Arrays.stream(wordsArray).forEach(words::add);
return words;

}

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

}

@Override
public Map<String, Integer> countNumberOfWordsRepetitions(String text) {
return emptyMap();
return getUniqueWords(text).stream().collect(Collectors.toMap(e -> e,
e -> Collections.frequency(getWords(text), e)));

}

@Override
public List<String> sortWordsByLength(String text, Direction direction) {
return emptyList();
return getWords(text).stream().sorted((o1, o2) -> direction == Direction.ASC ? o1.length() - o2.length() : o2.length() - o1.length())
.collect(Collectors.toList());

}
}