├── .gitignore
├── LICENSE
├── README.md
├── collections
├── pom.xml
└── src
│ └── com
│ └── github
│ └── vedenin
│ ├── eng
│ └── collections
│ │ ├── bimap
│ │ ├── ApacheBidiMapTest.java
│ │ ├── GsHashBiMapTest.java
│ │ ├── GuavaBiMapTest.java
│ │ ├── GuavaEnumBiMapTest.java
│ │ ├── GuavaEnumHashBiMapTest.java
│ │ └── JDKBiMapTest.java
│ │ ├── multimap
│ │ ├── ApacheMultiValueMapLinkedTest.java
│ │ ├── ApacheMultiValueMapTest.java
│ │ ├── ApacheMultiValueMapTreeTest.java
│ │ ├── GsFastListMultimapTest.java
│ │ ├── GsHashBagMultimapTest.java
│ │ ├── GsTreeSortedSetMultimapTest.java
│ │ ├── GsUnifiedSetMultimapTest.java
│ │ ├── GuavaArrayListMultimapTest.java
│ │ ├── GuavaHashMultiMapTest.java
│ │ ├── GuavaLinkedHashMultimapTest.java
│ │ ├── GuavaLinkedListMultimapTest.java
│ │ ├── GuavaTreeMultimapTest.java
│ │ └── JDKMultimapTest.java
│ │ ├── multiset
│ │ ├── ApacheHashBagTest.java
│ │ ├── ApacheSynchronizedBagTest.java
│ │ ├── ApacheSynchronizedSortedBagTest.java
│ │ ├── ApacheTreeBagTest.java
│ │ ├── GsMutableBagTest.java
│ │ ├── GsMutableSortedBagTest.java
│ │ ├── GuavaConcurrentHashMultisetTest.java
│ │ ├── GuavaHashMultisetTest.java
│ │ ├── GuavaLinkedHashMultisetTest.java
│ │ ├── GuavaTreeMultisetTest.java
│ │ └── JDKMultisetTest.java
│ │ └── utils
│ │ ├── CollectionCompareTests.java
│ │ ├── CollectionSearchTests.java
│ │ ├── CreateCollectionTest.java
│ │ └── JavaTransformTest.java
│ └── rus
│ ├── collections
│ ├── bimap
│ │ ├── ApacheBidiMapTest.java
│ │ ├── GsHashBiMapTest.java
│ │ ├── GuavaBiMapTest.java
│ │ ├── GuavaEnumBiMapTest.java
│ │ ├── GuavaEnumHashBiMapTest.java
│ │ └── JDKBiMapTest.java
│ ├── multimap
│ │ ├── ApacheMultiValueMapLinkedTest.java
│ │ ├── ApacheMultiValueMapTest.java
│ │ ├── ApacheMultiValueMapTreeTest.java
│ │ ├── GsFastListMultimapTest.java
│ │ ├── GsHashBagMultimapTest.java
│ │ ├── GsTreeSortedSetMultimapTest.java
│ │ ├── GsUnifiedSetMultimapTest.java
│ │ ├── GuavaArrayListMultimapTest.java
│ │ ├── GuavaHashMultiMapTest.java
│ │ ├── GuavaLinkedHashMultimapTest.java
│ │ ├── GuavaLinkedListMultimapTest.java
│ │ ├── GuavaTreeMultimapTest.java
│ │ └── JDKMultimapTest.java
│ ├── multiset
│ │ ├── ApacheHashBagTest.java
│ │ ├── ApacheSynchronizedBagTest.java
│ │ ├── ApacheSynchronizedSortedBagTest.java
│ │ ├── ApacheTreeBagTest.java
│ │ ├── GsMutableBagTest.java
│ │ ├── GsMutableSortedBagTest.java
│ │ ├── GuavaConcurrentHashMultisetTest.java
│ │ ├── GuavaHashMultisetTest.java
│ │ ├── GuavaLinkedHashMultisetTest.java
│ │ ├── GuavaTreeMultisetTest.java
│ │ └── JDKMultisetTest.java
│ └── utils
│ │ ├── CollectionCompareTests.java
│ │ ├── CollectionSearchTests.java
│ │ ├── CreateCollectionTest.java
│ │ └── JavaTransformTest.java
│ └── readme.md
├── dependency_injection
├── dependency-injection-dagger
│ ├── pom.xml
│ └── src
│ │ └── com
│ │ └── github
│ │ └── vedenin
│ │ └── dagger
│ │ └── rus
│ │ └── SimpleTest.java
├── dependency-injection-guice
│ ├── pom.xml
│ └── src
│ │ └── com
│ │ └── github
│ │ └── vedenin
│ │ └── guice
│ │ └── rus
│ │ ├── GuiceConstructorTest.java
│ │ ├── GuiceFieldInjectTest.java
│ │ └── GuiceSetterInjectTest.java
├── dependency-injection-spring
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── vedenin
│ │ │ └── rus
│ │ │ ├── spring_java
│ │ │ ├── SpringConstructorAutowiredTest.java
│ │ │ ├── SpringFieldAutowiredTest.java
│ │ │ ├── SpringSetterAutowiredTest.java
│ │ │ └── jsr300
│ │ │ │ └── SpringSimpleInjectTest.java
│ │ │ └── spring_xml
│ │ │ ├── XmlConstructorAutowiredTest.java
│ │ │ ├── XmlFieldAutowiredTest.java
│ │ │ ├── XmlSetterAutowiredTest.java
│ │ │ └── jsr300
│ │ │ └── XmlConstructorInjectTest.java
│ │ └── resources
│ │ ├── constructorAutowired.xml
│ │ ├── constructorInject.xml
│ │ ├── fieldAutowired.xml
│ │ └── setterAutowired.xml
└── pom.xml
├── html_parser
├── pom.xml
└── src
│ └── com.github
│ └── vedenin
│ └── url_parser
│ ├── GithubDownLoadTests.java
│ ├── URLDownloadTests.java
│ ├── URLDownloadWithProxySelector.java
│ └── URLDownloadWithProxyTests.java
├── machine-learning
├── pom.xml
└── src
│ └── com
│ └── github
│ └── vedenin
│ └── machine_learning
│ └── Test.java
├── natural-language-processing
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── vedenin
│ │ └── nlp
│ │ ├── OpenNLPSentenceDetectionTest.java
│ │ ├── SentenceDetectors.java
│ │ └── StanfordCoreNLPTest.java
│ └── resources
│ └── en-sent.bin
├── other
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── vedenin
│ ├── eng
│ ├── ReturnsMultiValuesFromMethodTest.java
│ ├── arrays
│ │ └── ConvertArrayToStringAndPrintTest.java
│ └── string_and_stream
│ │ ├── ConvertStringAndInputStreamTest.java
│ │ └── StringUtilsTest.java
│ └── rus
│ ├── arrays
│ └── ConvertArrayToStringAndPrintTest.java
│ └── string_and_stream
│ ├── ConvertStringAndInputStreamTest.java
│ └── StringUtilsTest.java
├── perfomance_test
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── vedenin
│ └── perfomace_test
│ ├── ConvertBigStringToInputStreamBenchmark.java
│ ├── ConvertInputStreamToStringBenchmark.java
│ ├── ConvertInputStreamToStringBigBenchmark.java
│ ├── ConvertStringToInputStreamBenchmark.java
│ ├── FindCountOfOccurrencesBenchmark.java
│ └── iteratemap
│ └── IterateThroughHashMapTest.java
├── pom.xml
├── spring
├── pom.xml
└── spring_core
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── vedenin
│ │ ├── eng
│ │ └── springcore
│ │ │ └── SpringBeanScopeTest.java
│ │ └── rus
│ │ └── springcore
│ │ └── SpringBeanScopeTest.java
│ └── resources
│ ├── constructorAutowired.xml
│ ├── constructorInject.xml
│ ├── fieldAutowired.xml
│ └── setterAutowired.xml
├── stream_api
├── pom.xml
└── src
│ └── com
│ └── github
│ └── vedenin
│ ├── eng
│ └── stream_api
│ │ ├── BuildTests.java
│ │ ├── CollectAndToArrayTests.java
│ │ ├── DistinctTests.java
│ │ ├── FindAndMatchTests.java
│ │ ├── FiterAndCountTests.java
│ │ ├── ForEachAndPeekTests.java
│ │ ├── LimitAndSkipTests.java
│ │ ├── MapTests.java
│ │ ├── MaxMinTests.java
│ │ ├── ReduceTests.java
│ │ └── SortedTests.java
│ └── rus
│ └── stream_api
│ ├── BuildTests.java
│ ├── CollectAndToArrayTests.java
│ ├── DistinctTests.java
│ ├── FindAndMatchTests.java
│ ├── FiterAndCountTests.java
│ ├── ForEachAndPeekTests.java
│ ├── LimitAndSkipTests.java
│ ├── MapTests.java
│ ├── MaxMinTests.java
│ ├── ReduceTests.java
│ ├── SortedTests.java
│ └── readme.md
└── web
├── pom.xml
└── tomcat_plugin
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Example user template template
2 | ### Example user template
3 |
4 | # IntelliJ project files
5 | .idea
6 | *.iml
7 | out
8 | gen
9 | # Created by .ignore support plugin (hsz.mobi)
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Moved to https://github.com/Vedenin/useful-java-links/tree/master/helloworlds
2 |
3 |
4 |
--------------------------------------------------------------------------------
/collections/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | collections-in-examples
9 | 0.01
10 | Java In Examples :: Collections
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.google.guava
29 | guava
30 | 29.0-jre
31 |
32 |
33 | org.apache.commons
34 | commons-collections4
35 | 4.1
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.7
41 |
42 |
43 | com.goldmansachs
44 | gs-collections-api
45 | 6.2.0
46 |
47 |
48 |
49 | com.goldmansachs
50 | gs-collections
51 | 6.2.0
52 |
53 |
54 |
55 | com.goldmansachs
56 | gs-collections-testutils
57 | 6.2.0
58 | test
59 |
60 |
61 |
62 | com.goldmansachs
63 | gs-collections-forkjoin
64 | 6.2.0
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/bimap/ApacheBidiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.bimap;
2 |
3 |
4 | import org.apache.commons.collections4.BidiMap;
5 | import org.apache.commons.collections4.bidimap.DualHashBidiMap;
6 |
7 | // Attention: version with russian comments in "rus" package
8 | public class ApacheBidiMapTest {
9 |
10 | // Task: create collection to translate Polish-English words in two ways
11 | public static void main(String[] args) {
12 | String[] englishWords = {"one", "two", "three","ball","snow"};
13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
14 |
15 | // Create Multiset
16 | BidiMap biMap = new DualHashBidiMap();
17 | // Create Polish-English dictionary
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMap.put(englishWord, russianWords[i]);
21 | i++;
22 | }
23 |
24 | // Print count words
25 | System.out.println(biMap); // Print "{ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}" - in random orders
26 | // Print unique words
27 | System.out.println(biMap.keySet()); // print "[ball, snow, one, two, three]"- in random orders
28 | System.out.println(biMap.values()); // print "[kula, snieg, jeden, dwa, trzy]" - in random orders
29 |
30 | // Print translate by words
31 | System.out.println("one = " + biMap.get("one")); // print one = jeden
32 | System.out.println("two = " + biMap.get("two")); // print two = dwa
33 | System.out.println("kula = " + biMap.getKey("kula")); // print kula = ball
34 | System.out.println("snieg = " + biMap.getKey("snieg")); // print snieg = snow
35 | System.out.println("empty = " + biMap.get("empty")); // print empty = null
36 |
37 | // Print count word's pair
38 | System.out.println(biMap.size()); //print 5
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/bimap/GsHashBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.bimap;
2 |
3 |
4 | import com.gs.collections.api.bimap.MutableBiMap;
5 | import com.gs.collections.impl.bimap.mutable.HashBiMap;
6 |
7 | // Attention: version with russian comments in "rus" package
8 | public class GsHashBiMapTest {
9 |
10 | // Task: create collection to translate Polish-English words in two ways
11 | public static void main(String[] args) {
12 | String[] englishWords = {"one", "two", "three","ball","snow"};
13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
14 |
15 | // Create Multiset
16 | MutableBiMap biMap = new HashBiMap(englishWords.length);
17 | // Create English-Polish dictionary
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMap.put(englishWord, russianWords[i]);
21 | i++;
22 | }
23 |
24 | // Print count words
25 | System.out.println(biMap); // print {two=dwa, ball=kula, one=jeden, snow=snieg, three=trzy} - in random orders
26 | // Print all unique words
27 | System.out.println(biMap.keySet()); // print [snow, two, one, three, ball] - in random orders
28 | System.out.println(biMap.values()); // print [dwa, kula, jeden, snieg, trzy] - in random orders
29 |
30 | // Print translate by words
31 | System.out.println("one = " + biMap.get("one")); // print one = jeden
32 | System.out.println("two = " + biMap.get("two")); // print two = dwa
33 | System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = ball
34 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = snow
35 | System.out.println("empty = " + biMap.get("empty")); // print empty = null
36 |
37 | // Print count word's pair
38 | System.out.println(biMap.size()); //print 5
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/bimap/GuavaBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.bimap;
2 |
3 | import com.google.common.collect.BiMap;
4 | import com.google.common.collect.HashBiMap;
5 |
6 |
7 | // Attention: version with russian comments in "rus" package
8 | public class GuavaBiMapTest {
9 |
10 | // Task: create collection to translate Polish-English words in two ways
11 | public static void main(String[] args) {
12 | String[] englishWords = {"one", "two", "three","ball","snow"};
13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
14 |
15 | // Create Multiset
16 | BiMap biMap = HashBiMap.create(englishWords.length);
17 | // Create English-Polish dictionary
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMap.put(englishWord, russianWords[i]);
21 | i++;
22 | }
23 |
24 | // Print count words
25 | System.out.println(biMap); // print {two=dwa, three=trzy, snow=snieg, ball=kula, one=jeden} - in random orders
26 | // Print all unique words
27 | System.out.println(biMap.keySet()); // print [two, three, snow, ball, one] - in random orders
28 | System.out.println(biMap.values()); // print [dwa, trzy, snieg, kula, jeden]- in random orders
29 |
30 | // Print translate by words
31 | System.out.println("one = " + biMap.get("one")); // print one = jeden
32 | System.out.println("two = " + biMap.get("two")); // print two = dwa
33 | System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = ball
34 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = snow
35 | System.out.println("empty = " + biMap.get("empty")); // print empty = null
36 |
37 | // Print count word's pair
38 | System.out.println(biMap.size()); //print 5
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/bimap/GuavaEnumBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.bimap;
2 |
3 | import com.google.common.collect.BiMap;
4 | import com.google.common.collect.EnumBiMap;
5 |
6 | // Attention: version with russian comments in "rus" package
7 | public class GuavaEnumBiMapTest {
8 | enum ENGLISH_WORD {
9 | ONE, TWO, THREE, BALL, SNOW
10 | }
11 | enum POLISH_WORD {
12 | JEDEN, DWA, TRZY, KULA, SNIEG
13 | }
14 |
15 | // Task: create collection to translate Polish-English words in two ways
16 | public static void main(String[] args) {
17 | ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
18 | POLISH_WORD[] polishWords = POLISH_WORD.values();
19 |
20 | // Create Multiset
21 | BiMap biMap = EnumBiMap.create(ENGLISH_WORD.class, POLISH_WORD.class);
22 | // Create English-Polish dictionary
23 | int i = 0;
24 | for(ENGLISH_WORD englishWord: englishWords) {
25 | biMap.put(englishWord, polishWords[i]);
26 | i++;
27 | }
28 |
29 | // Print count words
30 | System.out.println(biMap); // print {ONE=JEDEN, TWO=DWA, THREE=TRZY, BALL=KULA, SNOW=SNIEG}
31 | // Print all unique words
32 | System.out.println(biMap.keySet()); // print [ONE, TWO, THREE, BALL, SNOW]
33 | System.out.println(biMap.values()); // print [JEDEN, DWA, TRZY, KULA, SNIEG]
34 |
35 | // Print translate by words
36 | System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE)); // print one = JEDEN
37 | System.out.println("two = " + biMap.get(ENGLISH_WORD.TWO)); // print two = DWA
38 | System.out.println("kula = " + biMap.inverse().get(POLISH_WORD.KULA)); // print kula = BALL
39 | System.out.println("snieg = " + biMap.inverse().get(POLISH_WORD.SNIEG)); // print snieg = SNOW
40 | System.out.println("empty = " + biMap.get("empty")); // print empty = null
41 |
42 | // Print count word's pair
43 | System.out.println(biMap.size()); //print 5
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/bimap/GuavaEnumHashBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.bimap;
2 |
3 | import com.google.common.collect.BiMap;
4 | import com.google.common.collect.EnumHashBiMap;
5 |
6 | // Attention: version with russian comments in "rus" package
7 | public class GuavaEnumHashBiMapTest {
8 | enum ENGLISH_WORD {
9 | ONE, TWO, THREE, BALL, SNOW
10 | }
11 |
12 | // Task: create collection to translate Polish-English words in two ways
13 | public static void main(String[] args) {
14 | ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
15 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
16 |
17 | // Create Multiset
18 | BiMap biMap = EnumHashBiMap.create(ENGLISH_WORD.class);
19 | // Create English-Polish dictionary
20 | int i = 0;
21 | for(ENGLISH_WORD englishWord: englishWords) {
22 | biMap.put(englishWord, russianWords[i]);
23 | i++;
24 | }
25 |
26 | // Print count words
27 | System.out.println(biMap); // print {ONE=jeden, TWO=dwa, THREE=trzy, BALL=kula, SNOW=snieg}
28 | // Print all unique words
29 | System.out.println(biMap.keySet()); // print [ONE, TWO, THREE, BALL, SNOW]
30 | System.out.println(biMap.values()); // print [jeden, dwa, trzy, kula, snieg]
31 |
32 | // Print translate by words
33 | System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE)); // print one = jeden
34 | System.out.println("two = " + biMap.get(ENGLISH_WORD.TWO)); // print two = dwa
35 | System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = BALL
36 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = SNOW
37 | System.out.println("empty = " + biMap.get("empty")); // print empty = null
38 |
39 | // Print count word's pair
40 | System.out.println(biMap.size()); //print 5
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/bimap/JDKBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.bimap;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | // Attention: version with russian comments in "rus" package
7 | public class JDKBiMapTest {
8 |
9 | // Task: create collection to translate Polish-English words in two ways
10 | public static void main(String[] args) {
11 | String[] englishWords = {"one", "two", "three","ball","snow"};
12 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
13 |
14 | // Create analog BiMap
15 | Map biMapKeys = new HashMap(englishWords.length);
16 | Map biMapValues = new HashMap(russianWords.length);
17 | // Create English-Polish dictionary
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMapKeys.put(englishWord, russianWords[i]);
21 | biMapValues.put(russianWords[i], englishWord);
22 | i++;
23 | }
24 |
25 | // Print count words
26 | System.out.println(biMapKeys); // print {ball=kula, two=dwa, three=trzy, snow=snieg, one=jeden}- in random orders
27 | // Print all unique words
28 | System.out.println(biMapKeys.keySet()); // print [ball, two, three, snow, one] - in random orders
29 | System.out.println(biMapValues.keySet()); // print [dwa, trzy, kula, snieg, jeden] - in random orders
30 |
31 | // Print translate by words
32 | System.out.println("one = " + biMapKeys.get("one")); // print one = jeden
33 | System.out.println("two = " + biMapKeys.get("two")); // print two = dwa
34 | System.out.println("kula = " + biMapValues.get("kula")); // print kula = ball
35 | System.out.println("snieg = " + biMapValues.get("snieg")); // print snieg = snow
36 | System.out.println("empty = " + biMapValues.get("empty")); // print empty = null
37 |
38 | // Print count word's pair
39 | System.out.println(biMapKeys.size()); //print 5
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/ApacheMultiValueMapLinkedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import org.apache.commons.collections4.MultiMap;
4 | import org.apache.commons.collections4.map.MultiValueMap;
5 |
6 | import java.util.*;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class ApacheMultiValueMapLinkedTest {
10 |
11 | // Task: parser string with text and show all indexes of all words
12 | public static void main(String[] args) {
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Parse text to words and index
15 | List words = Arrays.asList(INPUT_TEXT.split(" "));
16 | // Create Multimap
17 | MultiMap multiMap = MultiValueMap.multiValueMap(new LinkedHashMap(), LinkedHashSet.class);
18 |
19 | // Fill Multimap
20 | int i = 0;
21 | for(String word: words) {
22 | multiMap.put(word, i);
23 | i++;
24 | }
25 |
26 | // Print all words
27 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]} - in predictable iteration order
28 | // Print all unique words
29 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi] - in predictable iteration order
30 |
31 | // Print all indexes
32 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
33 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
34 | System.out.println("All = " + multiMap.get("All!")); // print [3]
35 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
36 | System.out.println("Empty = " + multiMap.get("Empty")); // print null
37 |
38 | // Print count unique words
39 | System.out.println(multiMap.keySet().size()); //print 4
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/ApacheMultiValueMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import org.apache.commons.collections4.MultiMap;
4 | import org.apache.commons.collections4.map.MultiValueMap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class ApacheMultiValueMapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | MultiMap multiMap = new MultiValueMap();
19 |
20 |
21 | // Fill Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Print all words
29 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - in random orders
30 | // Print all unique words
31 | System.out.println(multiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders
32 |
33 | // Print all indexes
34 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // print [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // print null
39 |
40 | // Print count unique words
41 | System.out.println(multiMap.keySet().size()); //print 4
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/ApacheMultiValueMapTreeTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import org.apache.commons.collections4.MultiMap;
4 | import org.apache.commons.collections4.map.MultiValueMap;
5 |
6 | import java.util.*;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class ApacheMultiValueMapTreeTest {
10 |
11 | // Task: parser string with text and show all indexes of all words
12 | public static void main(String[] args) {
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Parse text to words and index
15 | List words = Arrays.asList(INPUT_TEXT.split(" "));
16 | // Create Multimap
17 | MultiMap multiMap = MultiValueMap.multiValueMap(new TreeMap(), TreeSet.class);
18 |
19 | // Fill Multimap
20 | int i = 0;
21 | for(String word: words) {
22 | multiMap.put(word, i);
23 | i++;
24 | }
25 |
26 | // Print all words
27 | System.out.println(multiMap); // print {All!=[3], Hello=[0, 2], Hi=[4], World!=[1, 5]} -in natural order
28 | // Print all unique words
29 | System.out.println(multiMap.keySet()); // print [All!, Hello, Hi, World!] in natural order
30 |
31 | // Print all indexes
32 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
33 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
34 | System.out.println("All = " + multiMap.get("All!")); // print [3]
35 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
36 | System.out.println("Empty = " + multiMap.get("Empty")); // print null
37 |
38 | // Print count unique words
39 | System.out.println(multiMap.keySet().size()); //print 4
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GsFastListMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.list.MutableListMultimap;
4 | import com.gs.collections.impl.multimap.list.FastListMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GsFastListMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | MutableListMultimap multiMap = new FastListMultimap();
19 |
20 |
21 | // Fill Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Print all words
29 | System.out.println(multiMap); // print {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- in random orders
30 | // Print all unique words
31 | System.out.println(multiMap.keysView()); // print [Hi, Hello, World!, All!] - in random orders
32 |
33 | // Print all indexes
34 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // print [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
39 |
40 | // Print count all words
41 | System.out.println(multiMap.size()); //print 6
42 |
43 | // Print count all unique words
44 | System.out.println(multiMap.keysView().size()); //print 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GsHashBagMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.bag.MutableBagMultimap;
4 | import com.gs.collections.impl.multimap.bag.HashBagMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GsHashBagMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | MutableBagMultimap multiMap = new HashBagMultimap();
19 |
20 |
21 | // Fill Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Print all words
29 | System.out.println(multiMap); // print {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- in random orders
30 | // Print all unique words
31 | System.out.println(multiMap.keysView()); // print [Hi, Hello, World!, All!] - in random orders
32 |
33 | // Print all indexes
34 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // print [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
39 |
40 | // Print count all words
41 | System.out.println(multiMap.size()); //print 6
42 |
43 | // Print count all unique words
44 | System.out.println(multiMap.keysView().size()); //print 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GsTreeSortedSetMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap;
4 | import com.gs.collections.impl.multimap.set.sorted.TreeSortedSetMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GsTreeSortedSetMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | MutableSortedSetMultimap multiMap = new TreeSortedSetMultimap();
19 |
20 |
21 | // Fill Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Print all words
29 | System.out.println(multiMap); // print {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- in random orders
30 | // Print all unique words
31 | System.out.println(multiMap.keysView()); // print [Hi, Hello, World!, All!] - in random orders
32 |
33 | // Print all indexes
34 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // print [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
39 |
40 | // Print count all words
41 | System.out.println(multiMap.size()); //print 6
42 |
43 | // Print count all unique words
44 | System.out.println(multiMap.keysView().size()); //print 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GsUnifiedSetMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.set.MutableSetMultimap;
4 | import com.gs.collections.impl.multimap.set.UnifiedSetMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GsUnifiedSetMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | MutableSetMultimap multiMap = new UnifiedSetMultimap();
19 |
20 |
21 | // Fill Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Print all words
29 | System.out.println(multiMap); // print {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- in random orders
30 | // Print all unique words
31 | System.out.println(multiMap.keysView()); // print [Hi, Hello, World!, All!] - in random orders
32 |
33 | // Print all indexes
34 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // print [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
39 |
40 | // Print count all words
41 | System.out.println(multiMap.size()); //print 6
42 |
43 | // Print count all unique words
44 | System.out.println(multiMap.keysView().size()); //print 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GuavaArrayListMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.google.common.collect.ArrayListMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GuavaArrayListMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | Multimap multiMap = ArrayListMultimap.create();
19 |
20 | // Fill Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Print all words
28 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - keys in random orders, values in predictable iteration order
29 | // Print all unique words
30 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in random orders
31 |
32 | // Print all indexes
33 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // print [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
38 |
39 | // Print count all words
40 | System.out.println(multiMap.size()); //print 6
41 |
42 | // Print count unique words
43 | System.out.println(multiMap.keySet().size()); //print 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GuavaHashMultiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.google.common.collect.HashMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GuavaHashMultiMapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | Multimap multiMap = HashMultimap.create();
19 |
20 | // Fill Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Print all words
28 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - keys and values in random orders
29 | // Print all unique words
30 | System.out.println(multiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders
31 |
32 | // Print all indexes
33 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // print [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
38 |
39 | // Print count all words
40 | System.out.println(multiMap.size()); //print 6
41 |
42 | // Print count unique words
43 | System.out.println(multiMap.keySet().size()); //print 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GuavaLinkedHashMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.google.common.collect.LinkedHashMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GuavaLinkedHashMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | Multimap multiMap = LinkedHashMultimap.create();
19 |
20 | // Fill Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Print all words
28 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in predictable iteration order
29 | // Print all unique words
30 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in predictable iteration order
31 |
32 | // Print all indexes
33 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // print [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
38 |
39 | // Print count all words
40 | System.out.println(multiMap.size()); //print 6
41 |
42 | // Print count unique words
43 | System.out.println(multiMap.keySet().size()); //print 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GuavaLinkedListMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.google.common.collect.LinkedListMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GuavaLinkedListMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | Multimap multiMap = LinkedListMultimap.create();
19 |
20 | // Fill Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Print all words
28 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in predictable iteration order
29 | // Print all unique words
30 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in predictable iteration order
31 |
32 | // Print all indexes
33 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // print [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
38 |
39 | // Print count all words
40 | System.out.println(multiMap.size()); //print 6
41 |
42 | // Print count unique words
43 | System.out.println(multiMap.keySet().size()); //print 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/GuavaTreeMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import com.google.common.collect.Multimap;
4 | import com.google.common.collect.TreeMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class GuavaTreeMultimapTest {
11 |
12 | // Task: parser string with text and show all indexes of all words
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Parse text to words and index
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Create Multimap
18 | Multimap multiMap = TreeMultimap.create();
19 |
20 | // Fill Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Print all words
28 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in natural order
29 | // Print all unique words
30 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in natural order
31 |
32 | // Print all indexes
33 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // print [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // print []
38 |
39 | // Print count all words
40 | System.out.println(multiMap.size()); //print 6
41 |
42 | // Print count unique words
43 | System.out.println(multiMap.keySet().size()); //print 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multimap/JDKMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multimap;
2 |
3 | import java.util.*;
4 |
5 | // Attention: version with russian comments in "rus" package
6 | public class JDKMultimapTest {
7 |
8 | // Task: parser string with text and show all indexes of all words
9 | public static void main(String[] args) {
10 | final int LIST_INDEXES_CAPACITY = 50;
11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
12 | // Parse text to words and index
13 | List words = Arrays.asList(INPUT_TEXT.split(" "));
14 | // Create analog Multimap
15 | Map> fakeMultiMap = new HashMap>(words.size());
16 |
17 |
18 | // Fill map
19 | int i = 0;
20 | for(String word: words) {
21 | List indexes = fakeMultiMap.get(word);
22 | if(indexes == null) {
23 | indexes = new ArrayList(LIST_INDEXES_CAPACITY);
24 | fakeMultiMap.put(word, indexes);
25 | }
26 | indexes.add(i);
27 | i++;
28 | }
29 |
30 | // Print all words
31 | System.out.println(fakeMultiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - in random orders
32 | // Print all unique words
33 | System.out.println(fakeMultiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders
34 |
35 | // Print all indexes
36 | System.out.println("Hello = " + fakeMultiMap.get("Hello")); // print [0, 2]
37 | System.out.println("World = " + fakeMultiMap.get("World!")); // print [1, 5]
38 | System.out.println("All = " + fakeMultiMap.get("All!")); // print [3]
39 | System.out.println("Hi = " + fakeMultiMap.get("Hi")); // print [4]
40 | System.out.println("Empty = " + fakeMultiMap.get("Empty")); // print null
41 |
42 | // Print count all words
43 | int cnt = 0;
44 | for(List lists: fakeMultiMap.values()) {
45 | cnt += lists.size();
46 | }
47 | System.out.println(cnt); //print 6
48 |
49 | // Print count all unique words
50 | System.out.println(fakeMultiMap.keySet().size()); //print 4
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/ApacheHashBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.HashBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class ApacheHashBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
19 | // Print all unique words
20 | System.out.println(bag.uniqueSet()); // print [Hi, Hello, World!, All!] - in random orders
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2
24 | System.out.println("World = " + bag.getCount("World!")); // print 2
25 | System.out.println("All = " + bag.getCount("All!")); // print 1
26 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1
27 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(bag.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(bag.uniqueSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/ApacheSynchronizedBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.HashBag;
5 | import org.apache.commons.collections4.bag.SynchronizedBag;
6 |
7 | import java.util.Arrays;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class ApacheSynchronizedBagTest {
11 |
12 | public static void main(String[] args) {
13 | // Parse text to separate words
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Create Multiset
16 | Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));
17 |
18 | // Print count words
19 | System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
20 | // Print all unique words
21 | System.out.println(bag.uniqueSet()); // print [Hi, Hello, World!, All!] - in random orders
22 |
23 | // Print count occurrences of words
24 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2
25 | System.out.println("World = " + bag.getCount("World!")); // print 2
26 | System.out.println("All = " + bag.getCount("All!")); // print 1
27 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1
28 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0
29 |
30 | // Print count all words
31 | System.out.println(bag.size()); //print 6
32 |
33 | // Print count unique words
34 | System.out.println(bag.uniqueSet().size()); //print 4
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/ApacheSynchronizedSortedBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.SynchronizedSortedBag;
5 | import org.apache.commons.collections4.bag.TreeBag;
6 |
7 | import java.util.Arrays;
8 |
9 | // Attention: version with russian comments in "rus" package
10 | public class ApacheSynchronizedSortedBagTest {
11 |
12 | public static void main(String[] args) {
13 | // Parse text to separate words
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Create Multiset
16 | Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(" "))));
17 |
18 | // Print count words
19 | System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order
20 | // Print all unique words
21 | System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order
22 |
23 |
24 | // Print count occurrences of words
25 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2
26 | System.out.println("World = " + bag.getCount("World!")); // print 2
27 | System.out.println("All = " + bag.getCount("All!")); // print 1
28 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1
29 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0
30 |
31 | // Print count all words
32 | System.out.println(bag.size()); //print 6
33 |
34 | // Print count unique words
35 | System.out.println(bag.uniqueSet().size()); //print 4
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/ApacheTreeBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.TreeBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class ApacheTreeBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | Bag bag = new TreeBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order
19 | // Print all unique words
20 | System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2
24 | System.out.println("World = " + bag.getCount("World!")); // print 2
25 | System.out.println("All = " + bag.getCount("All!")); // print 1
26 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1
27 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(bag.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(bag.uniqueSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/GsMutableBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import com.gs.collections.api.bag.MutableBag;
4 | import com.gs.collections.impl.bag.mutable.HashBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class GsMutableBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | MutableBag bag = HashBag.newBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(bag); // print [Hi, World!, World!, Hello, Hello, All!]- in random orders
19 | // Print all unique words
20 | System.out.println(bag.toSet()); // print [Hi, Hello, World!, All!] - in random orders
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + bag.occurrencesOf("Hello")); // print 2
24 | System.out.println("World = " + bag.occurrencesOf("World!")); // print 2
25 | System.out.println("All = " + bag.occurrencesOf("All!")); // print 1
26 | System.out.println("Hi = " + bag.occurrencesOf("Hi")); // print 1
27 | System.out.println("Empty = " + bag.occurrencesOf("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(bag.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(bag.toSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/GsMutableSortedBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import com.gs.collections.api.bag.sorted.MutableSortedBag;
4 | import com.gs.collections.impl.bag.sorted.mutable.TreeBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class GsMutableSortedBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | MutableSortedBag bag = TreeBag.newBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(bag); // print [All!, Hello, Hello, Hi, World!, World!]- in natural order
19 | // Print all unique words
20 | System.out.println(bag.toSortedSet()); // print [All!, Hello, Hi, World!]- in natural order
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + bag.occurrencesOf("Hello")); // print 2
24 | System.out.println("World = " + bag.occurrencesOf("World!")); // print 2
25 | System.out.println("All = " + bag.occurrencesOf("All!")); // print 1
26 | System.out.println("Hi = " + bag.occurrencesOf("Hi")); // print 1
27 | System.out.println("Empty = " + bag.occurrencesOf("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(bag.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(bag.toSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/GuavaConcurrentHashMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import com.google.common.collect.ConcurrentHashMultiset;
4 | import com.google.common.collect.Multiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class GuavaConcurrentHashMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | Multiset multiset = ConcurrentHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(multiset); // print [Hi, Hello x 2, World! x 2, All!] - in random orders
19 | // Print all unique words
20 | System.out.println(multiset.elementSet()); // print [Hi, Hello, World!, All!] - in random orders
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + multiset.count("Hello")); // print 2
24 | System.out.println("World = " + multiset.count("World!")); // print 2
25 | System.out.println("All = " + multiset.count("All!")); // print 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // print 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(multiset.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(multiset.elementSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/GuavaHashMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import com.google.common.collect.HashMultiset;
4 | import com.google.common.collect.Multiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class GuavaHashMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | Multiset multiset = HashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(multiset); // print [Hi, Hello x 2, World! x 2, All!] - in random orders
19 | // Print all unique words
20 | System.out.println(multiset.elementSet()); // print [Hi, Hello, World!, All!] - in random orders
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + multiset.count("Hello")); // print 2
24 | System.out.println("World = " + multiset.count("World!")); // print 2
25 | System.out.println("All = " + multiset.count("All!")); // print 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // print 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(multiset.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(multiset.elementSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/GuavaLinkedHashMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import com.google.common.collect.LinkedHashMultiset;
4 | import com.google.common.collect.Multiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class GuavaLinkedHashMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | Multiset multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(multiset); // print [Hello x 2, World! x 2, All!, Hi]- in predictable iteration order
19 | // Print all unique words
20 | System.out.println(multiset.elementSet()); // print [Hello, World!, All!, Hi] - in predictable iteration order
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + multiset.count("Hello")); // print 2
24 | System.out.println("World = " + multiset.count("World!")); // print 2
25 | System.out.println("All = " + multiset.count("All!")); // print 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // print 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(multiset.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(multiset.elementSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/GuavaTreeMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import com.google.common.collect.Multiset;
4 | import com.google.common.collect.TreeMultiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class GuavaTreeMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Create Multiset
15 | Multiset multiset = TreeMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Print count words
18 | System.out.println(multiset); // print [All!, Hello x 2, Hi, World! x 2]- in natural (alphabet) order
19 | // Print all unique words
20 | System.out.println(multiset.elementSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order
21 |
22 | // Print count occurrences of words
23 | System.out.println("Hello = " + multiset.count("Hello")); // print 2
24 | System.out.println("World = " + multiset.count("World!")); // print 2
25 | System.out.println("All = " + multiset.count("All!")); // print 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // print 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // print 0
28 |
29 | // Print count all words
30 | System.out.println(multiset.size()); //print 6
31 |
32 | // Print count unique words
33 | System.out.println(multiset.elementSet().size()); //print 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/eng/collections/multiset/JDKMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.collections.multiset;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | // Attention: version with russian comments in "rus" package
9 | public class JDKMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Parse text to separate words
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | List listResult = Arrays.asList(INPUT_TEXT.split(" "));
15 | // Create analog Multiset using HashMap and fill it
16 | Map fakeMultiset = new HashMap(listResult.size());
17 |
18 | for(String word: listResult) {
19 | Integer cnt = fakeMultiset.get(word);
20 | fakeMultiset.put(word, cnt == null ? 1 : cnt + 1);
21 | }
22 |
23 | // Print count words
24 | System.out.println(fakeMultiset); // print {World!=2, Hi=1, Hello=2, All!=1}- in random orders
25 | // Print all unique words
26 | System.out.println(fakeMultiset.keySet()); // print [World!, Hi, Hello, All!] - in random orders
27 |
28 | // Print count occurrences of words
29 | System.out.println("Hello = " + fakeMultiset.get("Hello")); // print 2
30 | System.out.println("World = " + fakeMultiset.get("World!")); // print 2
31 | System.out.println("All = " + fakeMultiset.get("All!")); // print 1
32 | System.out.println("Hi = " + fakeMultiset.get("Hi")); // print 1
33 | System.out.println("Empty = " + fakeMultiset.get("Empty")); // print null
34 |
35 | // Print count all words
36 | Integer cnt = 0;
37 | for (Integer wordCount : fakeMultiset.values()){
38 | cnt += wordCount;
39 | }
40 | System.out.println(cnt); //print 6
41 |
42 | // Print count all unique words
43 | System.out.println(fakeMultiset.size()); //print 4
44 |
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/bimap/ApacheBidiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.bimap;
2 |
3 |
4 | import org.apache.commons.collections4.BidiMap;
5 | import org.apache.commons.collections4.bidimap.DualHashBidiMap;
6 |
7 | // Attention: version with english comments in "eng" package
8 | public class ApacheBidiMapTest {
9 |
10 | // Задача даны массивы польского-английского перевода, сделать коллекцию для перевода слова в двух напрявлениях
11 | public static void main(String[] args) {
12 | String[] englishWords = {"one", "two", "three","ball","snow"};
13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
14 |
15 | // Создаем Multiset
16 | BidiMap biMap = new DualHashBidiMap();
17 | // создаем англо-польский словарь
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMap.put(englishWord, russianWords[i]);
21 | i++;
22 | }
23 |
24 | // Выводим кол-вом вхождений слов
25 | System.out.println(biMap); // напечатает {ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}- в произвольном порядке
26 | // Выводим все уникальные слова
27 | System.out.println(biMap.keySet()); // напечатает [ball, snow, one, two, three]- в произвольном порядке
28 | System.out.println(biMap.values()); // напечатает [kula, snieg, jeden, dwa, trzy]- в произвольном порядке
29 |
30 | // Выводим перевод по каждому слову
31 | System.out.println("one = " + biMap.get("one")); // напечатает one = jeden
32 | System.out.println("two = " + biMap.get("two")); // напечатает two = dwa
33 | System.out.println("kula = " + biMap.getKey("kula")); // напечатает kula = ball
34 | System.out.println("snieg = " + biMap.getKey("snieg")); // напечатает snieg = snow
35 | System.out.println("empty = " + biMap.get("empty")); // напечатает empty = null
36 |
37 | // Выводим общее количество переводов в словаре
38 | System.out.println(biMap.size()); //напечатает 5
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/bimap/GsHashBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.bimap;
2 |
3 |
4 | import com.gs.collections.api.bimap.MutableBiMap;
5 | import com.gs.collections.impl.bimap.mutable.HashBiMap;
6 |
7 | // Attention: version with english comments in "eng" package
8 | public class GsHashBiMapTest {
9 |
10 | // Задача даны массивы польского-английского перевода, сделать коллекцию для перевода слова в двух напрявлениях
11 | public static void main(String[] args) {
12 | String[] englishWords = {"one", "two", "three","ball","snow"};
13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
14 |
15 | // Создаем Multiset
16 | MutableBiMap biMap = new HashBiMap(englishWords.length);
17 | // создаем англо-польский словарь
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMap.put(englishWord, russianWords[i]);
21 | i++;
22 | }
23 |
24 | // Выводим кол-вом вхождений слов
25 | System.out.println(biMap); // напечатает {two=dwa, ball=kula, one=jeden, snow=snieg, three=trzy} - в произвольном порядке
26 | // Выводим все уникальные слова
27 | System.out.println(biMap.keySet()); // напечатает [snow, two, one, three, ball] - в произвольном порядке
28 | System.out.println(biMap.values()); // напечатает [dwa, kula, jeden, snieg, trzy] - в произвольном порядке
29 |
30 | // Выводим перевод по каждому слову
31 | System.out.println("one = " + biMap.get("one")); // напечатает one = jeden
32 | System.out.println("two = " + biMap.get("two")); // напечатает two = dwa
33 | System.out.println("kula = " + biMap.inverse().get("kula")); // напечатает kula = ball
34 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // напечатает snieg = snow
35 | System.out.println("empty = " + biMap.get("empty")); // напечатает empty = null
36 |
37 | // Выводим общее количество переводов в словаре
38 | System.out.println(biMap.size()); //напечатает 5
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/bimap/GuavaBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.bimap;
2 |
3 | import com.google.common.collect.BiMap;
4 | import com.google.common.collect.HashBiMap;
5 |
6 | // Attention: version with english comments in "eng" package
7 | public class GuavaBiMapTest {
8 |
9 | // Задача даны массивы польского-английского перевода,сделать коллекцию для перевода слова в двух напрявлениях
10 | public static void main(String[] args) {
11 | String[] englishWords = {"one", "two", "three","ball","snow"};
12 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
13 |
14 | // Создаем Multiset
15 | BiMap biMap = HashBiMap.create(englishWords.length);
16 | // создаем англо-польский словарь
17 | int i = 0;
18 | for(String englishWord: englishWords) {
19 | biMap.put(englishWord, russianWords[i]);
20 | i++;
21 | }
22 |
23 | // Выводим кол-вом вхождений слов
24 | System.out.println(biMap); // напечатает {two=dwa, three=trzy, snow=snieg, ball=kula, one=jeden} - в произвольном порядке
25 | // Выводим все уникальные слова
26 | System.out.println(biMap.keySet()); // напечатает [two, three, snow, ball, one] - в произвольном порядке
27 | System.out.println(biMap.values()); // напечатает [dwa, trzy, snieg, kula, jeden]- в произвольном порядке
28 |
29 | // Выводим перевод по каждому слову
30 | System.out.println("one = " + biMap.get("one")); // напечатает one = jeden
31 | System.out.println("two = " + biMap.get("two")); // напечатает two = dwa
32 | System.out.println("kula = " + biMap.inverse().get("kula")); // напечатает kula = ball
33 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // напечатает snieg = snow
34 | System.out.println("empty = " + biMap.get("empty")); // напечатает empty = null
35 |
36 | // Выводим общее количество переводов в словаре
37 | System.out.println(biMap.size()); //напечатает 5
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/bimap/GuavaEnumBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.bimap;
2 |
3 | import com.google.common.collect.BiMap;
4 | import com.google.common.collect.EnumBiMap;
5 |
6 | // Attention: version with english comments in "eng" package
7 | public class GuavaEnumBiMapTest {
8 | enum ENGLISH_WORD {
9 | ONE, TWO, THREE, BALL, SNOW
10 | }
11 | enum POLISH_WORD {
12 | JEDEN, DWA, TRZY, KULA, SNIEG
13 | }
14 | // Задача даны массивы польского-английского перевода, сделать коллекцию для перевода слова в двух напрявлениях
15 | public static void main(String[] args) {
16 | ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
17 | POLISH_WORD[] polishWords = POLISH_WORD.values();
18 |
19 | // Создаем Multiset
20 | BiMap biMap = EnumBiMap.create(ENGLISH_WORD.class, POLISH_WORD.class);
21 | // создаем англо-польский словарь
22 | int i = 0;
23 | for(ENGLISH_WORD englishWord: englishWords) {
24 | biMap.put(englishWord, polishWords[i]);
25 | i++;
26 | }
27 |
28 | // Выводим кол-вом вхождений слов
29 | System.out.println(biMap); // напечатает {ONE=JEDEN, TWO=DWA, THREE=TRZY, BALL=KULA, SNOW=SNIEG}
30 | // Выводим все уникальные слова
31 | System.out.println(biMap.keySet()); // напечатает [ONE, TWO, THREE, BALL, SNOW]
32 | System.out.println(biMap.values()); // напечатает [JEDEN, DWA, TRZY, KULA, SNIEG]
33 |
34 | // Выводим перевод по каждому слову
35 | System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE)); // напечатает one = JEDEN
36 | System.out.println("two = " + biMap.get(ENGLISH_WORD.TWO)); // напечатает two = DWA
37 | System.out.println("kula = " + biMap.inverse().get(POLISH_WORD.KULA)); // напечатает kula = BALL
38 | System.out.println("snieg = " + biMap.inverse().get(POLISH_WORD.SNIEG)); // напечатает snieg = SNOW
39 | System.out.println("empty = " + biMap.get("empty")); // напечатает empty = null
40 |
41 | // Выводим общее количество переводов в словаре
42 | System.out.println(biMap.size()); //напечатает 5
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/bimap/GuavaEnumHashBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.bimap;
2 |
3 | import com.google.common.collect.BiMap;
4 | import com.google.common.collect.EnumHashBiMap;
5 |
6 | // Attention: version with english comments in "eng" package
7 | public class GuavaEnumHashBiMapTest {
8 | enum ENGLISH_WORD {
9 | ONE, TWO, THREE, BALL, SNOW
10 | }
11 | // Задача даны массивы польского-английского перевода, сделать коллекцию для перевода слова в двух напрявлениях
12 | public static void main(String[] args) {
13 | ENGLISH_WORD[] englishWords = ENGLISH_WORD.values();
14 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
15 |
16 | // Создаем Multiset
17 | BiMap biMap = EnumHashBiMap.create(ENGLISH_WORD.class);
18 | // создаем англо-польский словарь
19 | int i = 0;
20 | for(ENGLISH_WORD englishWord: englishWords) {
21 | biMap.put(englishWord, russianWords[i]);
22 | i++;
23 | }
24 |
25 | // Выводим кол-вом вхождений слов
26 | System.out.println(biMap); // напечатает {ONE=один, TWO=dwa, THREE=trzy, BALL=kula, SNOW=snieg}
27 | // Выводим все уникальные слова
28 | System.out.println(biMap.keySet()); // напечатает [ONE, TWO, THREE, BALL, SNOW]
29 | System.out.println(biMap.values()); // напечатает [jeden, dwa, trzy, kula, snieg]
30 |
31 | // Выводим перевод по каждому слову
32 | System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE)); // напечатает one = jeden
33 | System.out.println("two = " + biMap.get(ENGLISH_WORD.TWO)); // напечатает two = dwa
34 | System.out.println("kula = " + biMap.inverse().get("kula")); // напечатает kula = BALL
35 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // напечатает snieg = SNOW
36 | System.out.println("empty = " + biMap.get("empty")); // напечатает empty = null
37 |
38 | // Выводим общее количество переводов в словаре
39 | System.out.println(biMap.size()); //напечатает 5
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/bimap/JDKBiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.bimap;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | // Attention: version with english comments in "eng" package
7 | public class JDKBiMapTest {
8 |
9 | // Задача даны массивы польского-английского перевода, сделать коллекцию для перевода слова в двух напрявлениях
10 | public static void main(String[] args) {
11 | String[] englishWords = {"one", "two", "three","ball","snow"};
12 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
13 |
14 | // Создаем аналог BiMap
15 | Map biMapKeys = new HashMap(englishWords.length);
16 | Map biMapValues = new HashMap(russianWords.length);
17 | // создаем англо-польский словарь
18 | int i = 0;
19 | for(String englishWord: englishWords) {
20 | biMapKeys.put(englishWord, russianWords[i]);
21 | biMapValues.put(russianWords[i], englishWord);
22 | i++;
23 | }
24 |
25 | // Выводим кол-вом вхождений слов
26 | System.out.println(biMapKeys); // напечатает {ball=kula, two=dwa, three=trzy, snow=snieg, one=jeden}- в произвольном порядке
27 | // Выводим все уникальные слова
28 | System.out.println(biMapKeys.keySet()); // напечатает [ball, two, three, snow, one] - в произвольном порядке
29 | System.out.println(biMapValues.keySet()); // напечатает [dwa, trzy, kula, snieg, jeden] - в произвольном порядке
30 |
31 | // Выводим перевод по каждому слову
32 | System.out.println("one = " + biMapKeys.get("one")); // напечатает one = jeden
33 | System.out.println("two = " + biMapKeys.get("two")); // напечатает two = dwa
34 | System.out.println("kula = " + biMapValues.get("kula")); // напечатает kula = ball
35 | System.out.println("snieg = " + biMapValues.get("snieg")); // напечатает snieg = snow
36 | System.out.println("empty = " + biMapValues.get("empty")); // напечатает empty = null
37 |
38 | // Выводим общее количество переводов в словаре
39 | System.out.println(biMapKeys.size()); //напечатает 5
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/ApacheMultiValueMapLinkedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import org.apache.commons.collections4.MultiMap;
4 | import org.apache.commons.collections4.map.MultiValueMap;
5 |
6 | import java.util.*;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class ApacheMultiValueMapLinkedTest {
10 |
11 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
12 | public static void main(String[] args) {
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Разберем текст на слова и индексы
15 | List words = Arrays.asList(INPUT_TEXT.split(" "));
16 | // Создаем Multimap
17 | MultiMap multiMap = MultiValueMap.multiValueMap(new LinkedHashMap(), LinkedHashSet.class);
18 |
19 | // Заполним Multimap
20 | int i = 0;
21 | for(String word: words) {
22 | multiMap.put(word, i);
23 | i++;
24 | }
25 |
26 | // Выводим все вхождения слов в текст
27 | System.out.println(multiMap); // напечатает {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]} - в порядке добавления
28 | // Выводим все уникальные слова
29 | System.out.println(multiMap.keySet()); // напечатает [Hello, World!, All!, Hi] - в порядке добавления
30 |
31 | // Выводим все индексы вхождения слова в текст
32 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
33 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
34 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
35 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
36 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает null
37 |
38 | // Выводим общее количество всех уникальных слов
39 | System.out.println(multiMap.keySet().size()); //напечатает 4
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/ApacheMultiValueMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import org.apache.commons.collections4.MultiMap;
4 | import org.apache.commons.collections4.map.MultiValueMap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class ApacheMultiValueMapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | MultiMap multiMap = new MultiValueMap();
19 |
20 |
21 | // Заполним Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Выводим все вхождения слов в текст
29 | System.out.println(multiMap); // напечатает {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - в произвольном порядке
30 | // Выводим все уникальные слова
31 | System.out.println(multiMap.keySet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
32 |
33 | // Выводим все индексы вхождения слова в текст
34 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает null
39 |
40 | // Выводим общее количество всех уникальных слов
41 | System.out.println(multiMap.keySet().size()); //напечатает 4
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/ApacheMultiValueMapTreeTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import org.apache.commons.collections4.MultiMap;
4 | import org.apache.commons.collections4.map.MultiValueMap;
5 |
6 | import java.util.*;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class ApacheMultiValueMapTreeTest {
10 |
11 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
12 | public static void main(String[] args) {
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Разберем текст на слова и индексы
15 | List words = Arrays.asList(INPUT_TEXT.split(" "));
16 | // Создаем Multimap
17 | MultiMap multiMap = MultiValueMap.multiValueMap(new TreeMap(), TreeSet.class);
18 |
19 | // Заполним Multimap
20 | int i = 0;
21 | for(String word: words) {
22 | multiMap.put(word, i);
23 | i++;
24 | }
25 |
26 | // Выводим все вхождения слов в текст
27 | System.out.println(multiMap); // напечатает {All!=[3], Hello=[0, 2], Hi=[4], World!=[1, 5]} -в натуральном порядке
28 | // Выводим все уникальные слова
29 | System.out.println(multiMap.keySet()); // напечатает [All!, Hello, Hi, World!] в натуральном порядке
30 |
31 | // Выводим все индексы вхождения слова в текст
32 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
33 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
34 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
35 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
36 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает null
37 |
38 | // Выводим общее количество всех уникальных слов
39 | System.out.println(multiMap.keySet().size()); //напечатает 4
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GsFastListMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.list.MutableListMultimap;
4 | import com.gs.collections.impl.multimap.list.FastListMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GsFastListMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | MutableListMultimap multiMap = new FastListMultimap();
19 |
20 |
21 | // Заполним Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Выводим все вхождения слов в текст
29 | System.out.println(multiMap); // напечатает {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- в произвольном порядке
30 | // Выводим все уникальные слова
31 | System.out.println(multiMap.keysView()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
32 |
33 | // Выводим все индексы вхождения слова в текст
34 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
39 |
40 | // Выводим общее количество всех слов в тексте
41 | System.out.println(multiMap.size()); //напечатает 6
42 |
43 | // Выводим общее количество уникальных слов в тексте
44 | System.out.println(multiMap.keysView().size()); //напечатает 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GsHashBagMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.bag.MutableBagMultimap;
4 | import com.gs.collections.impl.multimap.bag.HashBagMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GsHashBagMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | MutableBagMultimap multiMap = new HashBagMultimap();
19 |
20 |
21 | // Заполним Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Выводим все вхождения слов в текст
29 | System.out.println(multiMap); // напечатает {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- в произвольном порядке
30 | // Выводим все уникальные слова
31 | System.out.println(multiMap.keysView()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
32 |
33 | // Выводим все индексы вхождения слова в текст
34 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
39 |
40 | // Выводим общее количество всех слов в тексте
41 | System.out.println(multiMap.size()); //напечатает 6
42 |
43 | // Выводим общее количество уникальных слов в тексте
44 | System.out.println(multiMap.keysView().size()); //напечатает 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GsTreeSortedSetMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.sortedset.MutableSortedSetMultimap;
4 | import com.gs.collections.impl.multimap.set.sorted.TreeSortedSetMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GsTreeSortedSetMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | MutableSortedSetMultimap multiMap = new TreeSortedSetMultimap();
19 |
20 |
21 | // Заполним Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Выводим все вхождения слов в текст
29 | System.out.println(multiMap); // напечатает {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- в произвольном порядке
30 | // Выводим все уникальные слова
31 | System.out.println(multiMap.keysView()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
32 |
33 | // Выводим все индексы вхождения слова в текст
34 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
39 |
40 | // Выводим общее количество всех слов в тексте
41 | System.out.println(multiMap.size()); //напечатает 6
42 |
43 | // Выводим общее количество уникальных слов в тексте
44 | System.out.println(multiMap.keysView().size()); //напечатает 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GsUnifiedSetMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.gs.collections.api.multimap.set.MutableSetMultimap;
4 | import com.gs.collections.impl.multimap.set.UnifiedSetMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GsUnifiedSetMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | MutableSetMultimap multiMap = new UnifiedSetMultimap();
19 |
20 |
21 | // Заполним Multimap
22 | int i = 0;
23 | for(String word: words) {
24 | multiMap.put(word, i);
25 | i++;
26 | }
27 |
28 | // Выводим все вхождения слов в текст
29 | System.out.println(multiMap); // напечатает {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- в произвольном порядке
30 | // Выводим все уникальные слова
31 | System.out.println(multiMap.keysView()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
32 |
33 | // Выводим все индексы вхождения слова в текст
34 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
35 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
36 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
37 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
38 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
39 |
40 | // Выводим общее количество всех слов в тексте
41 | System.out.println(multiMap.size()); //напечатает 6
42 |
43 | // Выводим общее количество уникальных слов в тексте
44 | System.out.println(multiMap.keysView().size()); //напечатает 4
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GuavaArrayListMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.google.common.collect.ArrayListMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GuavaArrayListMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | Multimap multiMap = ArrayListMultimap.create();
19 |
20 | // Заполним Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Выводим все вхождения слов в текст
28 | System.out.println(multiMap); // напечатает {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - ключи в произвольном порядке, значения в порядке добавления
29 | // Выводим все уникальные слова
30 | System.out.println(multiMap.keySet()); // напечатает [Hello, World!, All!, Hi]- в произвольном порядке
31 |
32 | // Выводим все индексы вхождения слова в текст
33 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
38 |
39 | // Выводим общее количества всех слов в тексте
40 | System.out.println(multiMap.size()); //напечатает 6
41 |
42 | // Выводим общее количество всех уникальных слов
43 | System.out.println(multiMap.keySet().size()); //напечатает 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GuavaHashMultiMapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.google.common.collect.HashMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GuavaHashMultiMapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | Multimap multiMap = HashMultimap.create();
19 |
20 | // Заполним Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Выводим все вхождения слов в текст
28 | System.out.println(multiMap); // напечатает {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - в произвольном порядке, как ключи так и значения
29 | // Выводим все уникальные слова
30 | System.out.println(multiMap.keySet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
31 |
32 | // Выводим все индексы вхождения слова в текст
33 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
38 |
39 | // Выводим общее количества всех слов в тексте
40 | System.out.println(multiMap.size()); //напечатает 6
41 |
42 | // Выводим общее количество всех уникальных слов
43 | System.out.println(multiMap.keySet().size()); //напечатает 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GuavaLinkedHashMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.google.common.collect.LinkedHashMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GuavaLinkedHashMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | Multimap multiMap = LinkedHashMultimap.create();
19 |
20 | // Заполним Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Выводим все вхождения слов в текст
28 | System.out.println(multiMap); // напечатает {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-в порядке добавления
29 | // Выводим все уникальные слова
30 | System.out.println(multiMap.keySet()); // напечатает [Hello, World!, All!, Hi]- в порядке добавления
31 |
32 | // Выводим все индексы вхождения слова в текст
33 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
38 |
39 | // Выводим общее количества всех слов в тексте
40 | System.out.println(multiMap.size()); //напечатает 6
41 |
42 | // Выводим общее количество всех уникальных слов
43 | System.out.println(multiMap.keySet().size()); //напечатает 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GuavaLinkedListMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.google.common.collect.LinkedListMultimap;
4 | import com.google.common.collect.Multimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GuavaLinkedListMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | Multimap multiMap = LinkedListMultimap.create();
19 |
20 | // Заполним Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Выводим все вхождения слов в текст
28 | System.out.println(multiMap); // напечатает {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-в порядке добавления
29 | // Выводим все уникальные слова
30 | System.out.println(multiMap.keySet()); // напечатает [Hello, World!, All!, Hi]- в порядке добавления
31 |
32 | // Выводим все индексы вхождения слова в текст
33 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
38 |
39 | // Выводим общее количества всех слов в тексте
40 | System.out.println(multiMap.size()); //напечатает 6
41 |
42 | // Выводим общее количество всех уникальных слов
43 | System.out.println(multiMap.keySet().size()); //напечатает 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/GuavaTreeMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import com.google.common.collect.Multimap;
4 | import com.google.common.collect.TreeMultimap;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class GuavaTreeMultimapTest {
11 |
12 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
13 | public static void main(String[] args) {
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Разберем текст на слова и индексы
16 | List words = Arrays.asList(INPUT_TEXT.split(" "));
17 | // Создаем Multimap
18 | Multimap multiMap = TreeMultimap.create();
19 |
20 | // Заполним Multimap
21 | int i = 0;
22 | for(String word: words) {
23 | multiMap.put(word, i);
24 | i++;
25 | }
26 |
27 | // Выводим все вхождения слов в текст
28 | System.out.println(multiMap); // напечатает {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-в натуральном порядке
29 | // Выводим все уникальные слова
30 | System.out.println(multiMap.keySet()); // напечатает [Hello, World!, All!, Hi]- в натуральном порядке
31 |
32 | // Выводим все индексы вхождения слова в текст
33 | System.out.println("Hello = " + multiMap.get("Hello")); // напечатает [0, 2]
34 | System.out.println("World = " + multiMap.get("World!")); // напечатает [1, 5]
35 | System.out.println("All = " + multiMap.get("All!")); // напечатает [3]
36 | System.out.println("Hi = " + multiMap.get("Hi")); // напечатает [4]
37 | System.out.println("Empty = " + multiMap.get("Empty")); // напечатает []
38 |
39 | // Выводим общее количества всех слов в тексте
40 | System.out.println(multiMap.size()); //напечатает 6
41 |
42 | // Выводим общее количество всех уникальных слов
43 | System.out.println(multiMap.keySet().size()); //напечатает 4
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multimap/JDKMultimapTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multimap;
2 |
3 | import java.util.*;
4 |
5 | // Attention: version with english comments in "eng" package
6 | public class JDKMultimapTest {
7 | // Задача вывести разобрать текст и вывести все индексы для каждого слова
8 | public static void main(String[] args) {
9 | final int LIST_INDEXES_CAPACITY = 50;
10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
11 | // Разберем текст на слова и индексы
12 | List words = Arrays.asList(INPUT_TEXT.split(" "));
13 | // Создаем Multimap
14 | Map> fakeMultiMap = new HashMap>(words.size());
15 |
16 |
17 | // Заполним map
18 | int i = 0;
19 | for(String word: words) {
20 | List indexes = fakeMultiMap.get(word);
21 | if(indexes == null) {
22 | indexes = new ArrayList(LIST_INDEXES_CAPACITY);
23 | fakeMultiMap.put(word, indexes);
24 | }
25 | indexes.add(i);
26 | i++;
27 | }
28 |
29 | // Выводим все вхождения слов в текст
30 | System.out.println(fakeMultiMap); // напечатает {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - в произвольном порядке
31 | // Выводим все уникальные слова
32 | System.out.println(fakeMultiMap.keySet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
33 |
34 | // Выводим все индексы вхождения слова в текст
35 | System.out.println("Hello = " + fakeMultiMap.get("Hello")); // напечатает [0, 2]
36 | System.out.println("World = " + fakeMultiMap.get("World!")); // напечатает [1, 5]
37 | System.out.println("All = " + fakeMultiMap.get("All!")); // напечатает [3]
38 | System.out.println("Hi = " + fakeMultiMap.get("Hi")); // напечатает [4]
39 | System.out.println("Empty = " + fakeMultiMap.get("Empty")); // напечатает null
40 |
41 | // Выводим общее количество всех слов в тексте
42 | int cnt = 0;
43 | for(List lists: fakeMultiMap.values()) {
44 | cnt += lists.size();
45 | }
46 | System.out.println(cnt); //напечатает 6
47 |
48 | // Выводим общее количество уникальных слов в тексте
49 | System.out.println(fakeMultiMap.keySet().size()); //напечатает 4
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/ApacheHashBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.HashBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class ApacheHashBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(bag); // напечатает [1:Hi,2:Hello,2:World!,1:All!] - в произвольном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(bag.uniqueSet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + bag.getCount("Hello")); // напечатает 2
24 | System.out.println("World = " + bag.getCount("World!")); // напечатает 2
25 | System.out.println("All = " + bag.getCount("All!")); // напечатает 1
26 | System.out.println("Hi = " + bag.getCount("Hi")); // напечатает 1
27 | System.out.println("Empty = " + bag.getCount("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(bag.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(bag.uniqueSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/ApacheSynchronizedBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.HashBag;
5 | import org.apache.commons.collections4.bag.SynchronizedBag;
6 |
7 | import java.util.Arrays;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class ApacheSynchronizedBagTest {
11 |
12 | public static void main(String[] args) {
13 | // Разберем текст на слова
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Создаем Multiset
16 | Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));
17 |
18 | // Выводим кол-вом вхождений слов
19 | System.out.println(bag); // напечатает [1:Hi,2:Hello,2:World!,1:All!] - в произвольном порядке
20 | // Выводим все уникальные слова
21 | System.out.println(bag.uniqueSet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
22 |
23 | // Выводим количество по каждому слову
24 | System.out.println("Hello = " + bag.getCount("Hello")); // напечатает 2
25 | System.out.println("World = " + bag.getCount("World!")); // напечатает 2
26 | System.out.println("All = " + bag.getCount("All!")); // напечатает 1
27 | System.out.println("Hi = " + bag.getCount("Hi")); // напечатает 1
28 | System.out.println("Empty = " + bag.getCount("Empty")); // напечатает 0
29 |
30 | // Выводим общее количества всех слов в тексте
31 | System.out.println(bag.size()); //напечатает 6
32 |
33 | // Выводим общее количество всех уникальных слов
34 | System.out.println(bag.uniqueSet().size()); //напечатает 4
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/ApacheSynchronizedSortedBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.SynchronizedSortedBag;
5 | import org.apache.commons.collections4.bag.TreeBag;
6 |
7 | import java.util.Arrays;
8 |
9 | // Attention: version with english comments in "eng" package
10 | public class ApacheSynchronizedSortedBagTest {
11 |
12 | public static void main(String[] args) {
13 | // Разберем текст на слова
14 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
15 | // Создаем Multiset
16 | Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(" "))));
17 |
18 | // Выводим кол-вом вхождений слов
19 | System.out.println(bag); // напечатает [1:All!,2:Hello,1:Hi,2:World!]- в алфавитном порядке
20 | // Выводим все уникальные слова
21 | System.out.println(bag.uniqueSet()); // напечатает [All!, Hello, Hi, World!]- в алфавитном порядке
22 |
23 |
24 | // Выводим количество по каждому слову
25 | System.out.println("Hello = " + bag.getCount("Hello")); // напечатает 2
26 | System.out.println("World = " + bag.getCount("World!")); // напечатает 2
27 | System.out.println("All = " + bag.getCount("All!")); // напечатает 1
28 | System.out.println("Hi = " + bag.getCount("Hi")); // напечатает 1
29 | System.out.println("Empty = " + bag.getCount("Empty")); // напечатает 0
30 |
31 | // Выводим общее количества всех слов в тексте
32 | System.out.println(bag.size()); //напечатает 6
33 |
34 | // Выводим общее количество всех уникальных слов
35 | System.out.println(bag.uniqueSet().size()); //напечатает 4
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/ApacheTreeBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import org.apache.commons.collections4.Bag;
4 | import org.apache.commons.collections4.bag.TreeBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class ApacheTreeBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | Bag bag = new TreeBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(bag); // напечатает [1:All!,2:Hello,1:Hi,2:World!]- в алфавитном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(bag.uniqueSet()); // напечатает [All!, Hello, Hi, World!]- в алфавитном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + bag.getCount("Hello")); // напечатает 2
24 | System.out.println("World = " + bag.getCount("World!")); // напечатает 2
25 | System.out.println("All = " + bag.getCount("All!")); // напечатает 1
26 | System.out.println("Hi = " + bag.getCount("Hi")); // напечатает 1
27 | System.out.println("Empty = " + bag.getCount("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(bag.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(bag.uniqueSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/GsMutableBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import com.gs.collections.api.bag.MutableBag;
4 | import com.gs.collections.impl.bag.mutable.HashBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class GsMutableBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | MutableBag bag = HashBag.newBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(bag); // напечатает [Hi, World!, World!, Hello, Hello, All!]- в произвольном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(bag.toSet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + bag.occurrencesOf("Hello")); // напечатает 2
24 | System.out.println("World = " + bag.occurrencesOf("World!")); // напечатает 2
25 | System.out.println("All = " + bag.occurrencesOf("All!")); // напечатает 1
26 | System.out.println("Hi = " + bag.occurrencesOf("Hi")); // напечатает 1
27 | System.out.println("Empty = " + bag.occurrencesOf("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(bag.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(bag.toSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/GsMutableSortedBagTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import com.gs.collections.api.bag.sorted.MutableSortedBag;
4 | import com.gs.collections.impl.bag.sorted.mutable.TreeBag;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class GsMutableSortedBagTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | MutableSortedBag bag = TreeBag.newBag(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(bag); // напечатает [All!, Hello, Hello, Hi, World!, World!]- в натуральном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(bag.toSortedSet()); // напечатает [All!, Hello, Hi, World!]- в натуральном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + bag.occurrencesOf("Hello")); // напечатает 2
24 | System.out.println("World = " + bag.occurrencesOf("World!")); // напечатает 2
25 | System.out.println("All = " + bag.occurrencesOf("All!")); // напечатает 1
26 | System.out.println("Hi = " + bag.occurrencesOf("Hi")); // напечатает 1
27 | System.out.println("Empty = " + bag.occurrencesOf("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(bag.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(bag.toSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/GuavaConcurrentHashMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import com.google.common.collect.ConcurrentHashMultiset;
4 | import com.google.common.collect.Multiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class GuavaConcurrentHashMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | Multiset multiset = ConcurrentHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(multiset); // напечатает [Hi, Hello x 2, World! x 2, All!] - в произвольном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(multiset.elementSet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + multiset.count("Hello")); // напечатает 2
24 | System.out.println("World = " + multiset.count("World!")); // напечатает 2
25 | System.out.println("All = " + multiset.count("All!")); // напечатает 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // напечатает 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(multiset.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(multiset.elementSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/GuavaHashMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import com.google.common.collect.HashMultiset;
4 | import com.google.common.collect.Multiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class GuavaHashMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | Multiset multiset = HashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(multiset); // напечатает [Hi, Hello x 2, World! x 2, All!] - в произвольном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(multiset.elementSet()); // напечатает [Hi, Hello, World!, All!] - в произвольном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + multiset.count("Hello")); // напечатает 2
24 | System.out.println("World = " + multiset.count("World!")); // напечатает 2
25 | System.out.println("All = " + multiset.count("All!")); // напечатает 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // напечатает 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(multiset.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(multiset.elementSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/GuavaLinkedHashMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import com.google.common.collect.LinkedHashMultiset;
4 | import com.google.common.collect.Multiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class GuavaLinkedHashMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | Multiset multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(multiset); // напечатает [Hello x 2, World! x 2, All!, Hi]- в порядке первого добавления элемента
19 | // Выводим все уникальные слова
20 | System.out.println(multiset.elementSet()); // напечатает [Hello, World!, All!, Hi] - в порядке первого добавления элемента
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + multiset.count("Hello")); // напечатает 2
24 | System.out.println("World = " + multiset.count("World!")); // напечатает 2
25 | System.out.println("All = " + multiset.count("All!")); // напечатает 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // напечатает 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(multiset.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(multiset.elementSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/GuavaTreeMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import com.google.common.collect.Multiset;
4 | import com.google.common.collect.TreeMultiset;
5 |
6 | import java.util.Arrays;
7 |
8 | // Attention: version with english comments in "eng" package
9 | public class GuavaTreeMultisetTest {
10 |
11 | public static void main(String[] args) {
12 | // Разберем текст на слова
13 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
14 | // Создаем Multiset
15 | Multiset multiset = TreeMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
16 |
17 | // Выводим кол-вом вхождений слов
18 | System.out.println(multiset); // напечатает [All!, Hello x 2, Hi, World! x 2]- в алфавитном порядке
19 | // Выводим все уникальные слова
20 | System.out.println(multiset.elementSet()); // напечатает [All!, Hello, Hi, World!]- в алфавитном порядке
21 |
22 | // Выводим количество по каждому слову
23 | System.out.println("Hello = " + multiset.count("Hello")); // напечатает 2
24 | System.out.println("World = " + multiset.count("World!")); // напечатает 2
25 | System.out.println("All = " + multiset.count("All!")); // напечатает 1
26 | System.out.println("Hi = " + multiset.count("Hi")); // напечатает 1
27 | System.out.println("Empty = " + multiset.count("Empty")); // напечатает 0
28 |
29 | // Выводим общее количества всех слов в тексте
30 | System.out.println(multiset.size()); //напечатает 6
31 |
32 | // Выводим общее количество всех уникальных слов
33 | System.out.println(multiset.elementSet().size()); //напечатает 4
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/collections/src/com/github/vedenin/rus/collections/multiset/JDKMultisetTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.collections.multiset;
2 |
3 | import java.util.*;
4 |
5 | // Attention: version with english comments in "eng" package
6 | public class JDKMultisetTest {
7 |
8 | public static void main(String[] args) {
9 | // Разберем текст на слова
10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!";
11 | List listResult = Arrays.asList(INPUT_TEXT.split(" "));
12 | // Создаем эмуляцию Multiset c помощью HashMap и заполняем
13 | Map fakeMultiset = new HashMap(listResult.size());
14 |
15 | for(String word: listResult) {
16 | Integer cnt = fakeMultiset.get(word);
17 | fakeMultiset.put(word, cnt == null ? 1 : cnt + 1);
18 | }
19 |
20 | // Выводим кол-вом вхождений слов
21 | System.out.println(fakeMultiset); // напечатает {World!=2, Hi=1, Hello=2, All!=1}- в произвольном порядке
22 | // Выводим все уникальные слова
23 | System.out.println(fakeMultiset.keySet()); // напечатает [World!, Hi, Hello, All!] - в произвольном порядке
24 |
25 | // Выводим количество по каждому слову
26 | System.out.println("Hello = " + fakeMultiset.get("Hello")); // напечатает 2
27 | System.out.println("World = " + fakeMultiset.get("World!")); // напечатает 2
28 | System.out.println("All = " + fakeMultiset.get("All!")); // напечатает 1
29 | System.out.println("Hi = " + fakeMultiset.get("Hi")); // напечатает 1
30 | System.out.println("Empty = " + fakeMultiset.get("Empty")); // напечатает null
31 |
32 | // Выводим общее количества всех слов в тексте
33 | Integer cnt = 0;
34 | for (Integer wordCount : fakeMultiset.values()){
35 | cnt += wordCount;
36 | }
37 | System.out.println(cnt); //напечатает 6
38 |
39 | // Выводим общее количество уникальных слов
40 | System.out.println(fakeMultiset.size()); //напечатает 4
41 |
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-dagger/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.vedenin
8 | dependency-injection-dagger
9 | 0.1-SNAPSHOT
10 | Dependency injections :: Dagger
11 |
12 |
13 |
14 |
15 |
16 | org.apache.maven.plugins
17 | maven-compiler-plugin
18 | 3.1
19 |
20 | 1.8
21 | 1.8
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | sonatype snapshots
32 | https://oss.sonatype.org/content/repositories/snapshots/
33 |
34 |
35 |
36 |
37 |
38 | com.google.inject
39 | guice
40 | 4.0
41 |
42 |
43 |
44 | org.springframework
45 | spring-context
46 | 4.2.2.RELEASE
47 |
48 |
49 |
50 | org.springframework.security
51 | spring-security-web
52 | 5.2.10.RELEASE
53 |
54 |
55 |
56 | com.google.guava
57 | guava
58 | 29.0-jre
59 |
60 |
61 |
62 | com.google.auto
63 | auto-common
64 | 0.6
65 |
66 |
67 |
68 | com.google.dagger
69 | dagger
70 | 2.0
71 | compile
72 |
73 |
74 |
75 | com.google.dagger
76 | dagger-compiler
77 | 2.0
78 | compile
79 |
80 |
81 |
82 | org.glassfish
83 | javax.annotation
84 | 10.0-b28
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-dagger/src/com/github/vedenin/dagger/rus/SimpleTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.dagger.rus;
2 |
3 |
4 | import dagger.Component;
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import javax.inject.Inject;
9 |
10 | /**
11 | * Простейший пример использования DI dagger
12 | *
13 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
14 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
15 | *
16 | * Created by vvedenin on 11/14/2015.
17 | */
18 | public class SimpleTest {
19 | public static class Notifier {
20 | private final NotificationService service;
21 |
22 | @Inject
23 | public Notifier(NotificationService service) {
24 | this.service = service;
25 | }
26 |
27 | public void send(String message) {
28 | service.send("email: " + message);
29 | }
30 | }
31 |
32 | public static class EMailService implements NotificationService {
33 | public void send(String message) {
34 | System.out.println("I send " + message);
35 | }
36 | }
37 |
38 | public interface NotificationService {
39 | void send(String message);
40 | }
41 |
42 | @Module
43 | public static class TestModule {
44 | @Provides
45 | NotificationService provideNotificationService() {
46 | return new EMailService();
47 | }
48 |
49 | @Provides Notifier provideNotifier(NotificationService service) {
50 | return new Notifier(service);
51 | }
52 | }
53 |
54 | @Component(modules = TestModule.class)
55 | interface TestComponent {
56 | Notifier getNotifier();
57 | }
58 |
59 | public static void main(String[] args) throws Exception {
60 | TestComponent testComponent = DaggerSimpleTest_TestComponent.create();
61 | Notifier notifier = testComponent.getNotifier();
62 | notifier.send("test email"); // Напечатает "I send email: test email"
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-guice/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.vedenin
8 | dependency-injection-guice
9 | 0.1-SNAPSHOT
10 | Dependency injections :: Guice
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.google.inject
29 | guice
30 | 4.0
31 |
32 |
33 |
34 | com.google.guava
35 | guava
36 | 29.0-jre
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-guice/src/com/github/vedenin/guice/rus/GuiceConstructorTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.guice.rus;
2 |
3 |
4 | import com.google.inject.AbstractModule;
5 | import com.google.inject.Guice;
6 | import com.google.inject.Injector;
7 |
8 | import javax.inject.Inject;
9 |
10 | /**
11 | * Пример использования DI guice через инъекцию в конструктор
12 | *
13 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
14 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
15 | * инъекцию в конструктор
16 | *
17 | * Created by vvedenin on 11/14/2015.
18 | */
19 | public class GuiceConstructorTest {
20 | public static class Notifier {
21 | private final NotificationService service;
22 |
23 | @Inject
24 | public Notifier(NotificationService service) {
25 | this.service = service;
26 | }
27 |
28 | public void send(String message) {
29 | service.send("email: " + message);
30 | }
31 | }
32 |
33 | public static class EMailService implements NotificationService {
34 | public void send(String message) {
35 | System.out.println("I send " + message);
36 | }
37 | }
38 |
39 | public interface NotificationService {
40 | void send(String message);
41 | }
42 |
43 |
44 | public static class TestModule extends AbstractModule {
45 | @Override
46 | protected void configure() {
47 | bind(NotificationService.class).to(EMailService.class);
48 | }
49 | }
50 |
51 | public static void main(String[] args) throws Exception {
52 | Injector injector = Guice.createInjector(new TestModule());
53 | Notifier notifier = injector.getInstance(Notifier.class);
54 | notifier.send("test email"); // Print "I send email: test email"
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-guice/src/com/github/vedenin/guice/rus/GuiceFieldInjectTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.guice.rus;
2 |
3 |
4 | import com.google.inject.AbstractModule;
5 | import com.google.inject.Guice;
6 | import com.google.inject.Injector;
7 |
8 | import javax.inject.Inject;
9 |
10 | /**
11 | * Пример использования инъекции в приватное поле в DI guice
12 | *
13 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
14 | * чтобы отправить сообщение пользователю. Получим эту зависимость через
15 | * инъекцию в приватное поле
16 | *
17 | * Created by vvedenin on 11/14/2015.
18 | */
19 | public class GuiceFieldInjectTest {
20 | public static class Notifier {
21 | @Inject
22 | private NotificationService service;
23 |
24 | public void send(String message) {
25 | service.send("email: " + message);
26 | }
27 | }
28 |
29 | public static class EMailService implements NotificationService {
30 | public void send(String message) {
31 | System.out.println("I send " + message);
32 | }
33 | }
34 |
35 | public interface NotificationService {
36 | void send(String message);
37 | }
38 |
39 |
40 | public static class TestModule extends AbstractModule {
41 | @Override
42 | protected void configure() {
43 | bind(NotificationService.class).to(EMailService.class);
44 | }
45 | }
46 |
47 | public static void main(String[] args) throws Exception {
48 | Injector injector = Guice.createInjector(new TestModule());
49 | Notifier notifier = injector.getInstance(Notifier.class);
50 | notifier.send("test email"); // Print "I send email: test email"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-guice/src/com/github/vedenin/guice/rus/GuiceSetterInjectTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.guice.rus;
2 |
3 |
4 | import com.google.inject.AbstractModule;
5 | import com.google.inject.Guice;
6 | import com.google.inject.Injector;
7 |
8 | import javax.inject.Inject;
9 |
10 | /**
11 | * Пример использования инъекции в приватное поле в DI guice
12 | *
13 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
14 | * чтобы отправить сообщение пользователю. Получим эту зависимость через
15 | * инъекцию в метод-сеттер
16 | *
17 | * Created by vvedenin on 11/14/2015.
18 | */
19 | public class GuiceSetterInjectTest {
20 | public static class Notifier {
21 | private NotificationService service;
22 |
23 | @Inject
24 | public void setService(NotificationService service) {
25 | this.service = service;
26 | }
27 |
28 | public void send(String message) {
29 | service.send("email: " + message);
30 | }
31 | }
32 |
33 | public static class EMailService implements NotificationService {
34 | public void send(String message) {
35 | System.out.println("I send " + message);
36 | }
37 | }
38 |
39 | public interface NotificationService {
40 | void send(String message);
41 | }
42 |
43 |
44 | public static class TestModule extends AbstractModule {
45 | @Override
46 | protected void configure() {
47 | bind(NotificationService.class).to(EMailService.class);
48 | }
49 | }
50 |
51 | public static void main(String[] args) throws Exception {
52 | Injector injector = Guice.createInjector(new TestModule());
53 | Notifier notifier = injector.getInstance(Notifier.class);
54 | notifier.send("test email"); // Print "I send email: test email"
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.vedenin
8 | dependency-injection-spring
9 | 0.1-SNAPSHOT
10 | Dependency injections :: Spring
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.springframework
29 | spring-context
30 | 4.2.2.RELEASE
31 |
32 |
33 |
34 | org.springframework.security
35 | spring-security-web
36 | 5.2.10.RELEASE
37 |
38 |
39 |
40 | javax.inject
41 | javax.inject
42 | 1
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_java/SpringConstructorAutowiredTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_java;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * Пример использования DI Spring инъекции в конструктор,
10 | * используя аннотации Spring и конфигурацию через Java классы
11 | *
12 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
13 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
14 | *
15 | * Created by vvedenin on 11/14/2015.
16 | */
17 | public class SpringConstructorAutowiredTest {
18 | public static class Notifier {
19 | private final NotificationService service;
20 |
21 | @Autowired
22 | public Notifier(NotificationService service) {
23 | this.service = service;
24 | }
25 |
26 | public void send(String message) {
27 | service.send("email: " + message);
28 | }
29 | }
30 |
31 | public static class EMailService implements NotificationService {
32 | public void send(String message) {
33 | System.out.println("I send " + message);
34 | }
35 | }
36 |
37 | public interface NotificationService {
38 | void send(String message);
39 | }
40 |
41 | @Configuration
42 | public static class DIConfiguration {
43 | @Bean
44 | public Notifier getNotifier(NotificationService service){
45 | return new Notifier(service);
46 | }
47 |
48 | @Bean
49 | public NotificationService getNotificationService(){
50 | return new EMailService();
51 | }
52 | }
53 |
54 | public static void main(String[] args) throws Exception {
55 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class);
56 | Notifier notifier = context.getBean(Notifier.class);
57 | notifier.send("test email"); // Print "I send email: test email"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_java/SpringFieldAutowiredTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_java;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * Пример использования DI Spring инъекции в приватное поле,
10 | * используя аннотации Spring и конфигурацию через Java классы
11 | *
12 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
13 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
14 | *
15 | * Created by vvedenin on 11/14/2015.
16 | */
17 | public class SpringFieldAutowiredTest {
18 | public static class Notifier {
19 | @Autowired
20 | private NotificationService service;
21 |
22 | public void send(String message) {
23 | service.send("email: " + message);
24 | }
25 | }
26 |
27 | public static class EMailService implements NotificationService {
28 | public void send(String message) {
29 | System.out.println("I send " + message);
30 | }
31 | }
32 |
33 | public interface NotificationService {
34 | void send(String message);
35 | }
36 |
37 | @Configuration
38 | public static class DIConfiguration {
39 | @Bean
40 | public Notifier getNotifier(NotificationService service){
41 | return new Notifier();
42 | }
43 |
44 | @Bean
45 | public NotificationService getNotificationService(){
46 | return new EMailService();
47 | }
48 | }
49 |
50 | public static void main(String[] args) throws Exception {
51 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class);
52 | Notifier notifier = context.getBean(Notifier.class);
53 | notifier.send("test email"); // Print "I send email: test email"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_java/SpringSetterAutowiredTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_java;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * Пример использования DI Spring используя аннотации Spring, конфигурацию через
10 | * Java классы и инъекцию в метод-сеттер
11 | *
12 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
13 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
14 | *
15 | * Created by vvedenin on 11/14/2015.
16 | */
17 | public class SpringSetterAutowiredTest {
18 | public static class Notifier {
19 | private NotificationService service;
20 |
21 | @Autowired
22 | public void setService(NotificationService service) {
23 | this.service = service;
24 | }
25 |
26 | public void send(String message) {
27 | service.send("email: " + message);
28 | }
29 | }
30 |
31 | public static class EMailService implements NotificationService {
32 | public void send(String message) {
33 | System.out.println("I send " + message);
34 | }
35 | }
36 |
37 | public interface NotificationService {
38 | void send(String message);
39 | }
40 |
41 | @Configuration
42 | public static class DIConfiguration {
43 | @Bean
44 | public Notifier getNotifier(NotificationService service){
45 | return new Notifier();
46 | }
47 |
48 | @Bean
49 | public NotificationService getNotificationService(){
50 | return new EMailService();
51 | }
52 | }
53 |
54 | public static void main(String[] args) throws Exception {
55 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class);
56 | Notifier notifier = context.getBean(Notifier.class);
57 | notifier.send("test email"); // Print "I send email: test email"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_java/jsr300/SpringSimpleInjectTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_java.jsr300;
2 |
3 |
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | import javax.inject.Inject;
9 |
10 | /**
11 | * Простейший пример использования DI Spring
12 | *
13 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
14 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
15 | *
16 | * Created by vvedenin on 11/14/2015.
17 | */
18 | public class SpringSimpleInjectTest {
19 | public static class Notifier {
20 | private final NotificationService service;
21 |
22 | @Inject
23 | public Notifier(NotificationService service) {
24 | this.service = service;
25 | }
26 |
27 | public void send(String message) {
28 | service.send("email: " + message);
29 | }
30 | }
31 |
32 | public static class EMailService implements NotificationService {
33 | public void send(String message) {
34 | System.out.println("I send " + message);
35 | }
36 | }
37 |
38 | public interface NotificationService {
39 | void send(String message);
40 | }
41 |
42 | @Configuration
43 | public static class DIConfiguration {
44 | @Bean
45 | public Notifier getNotifier(NotificationService service){
46 | return new Notifier(service);
47 | }
48 |
49 | @Bean
50 | public NotificationService getNotificationService(){
51 | return new EMailService();
52 | }
53 | }
54 |
55 | public static void main(String[] args) throws Exception {
56 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class);
57 | Notifier notifier = context.getBean(Notifier.class);
58 | notifier.send("test email"); // Print "I send email: test email"
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_xml/XmlConstructorAutowiredTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_xml;
2 |
3 |
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | /**
8 | * Пример использования DI Spring инъекции в конструктор,
9 | * используя аннотации Spring и конфигурацию через xml файлы
10 | *
11 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
12 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
13 | *
14 | * Created by vvedenin on 11/14/2015.
15 | */
16 | public class XmlConstructorAutowiredTest {
17 | public static class Notifier {
18 | private final NotificationService service;
19 |
20 | @Autowired
21 | public Notifier(NotificationService service) {
22 | this.service = service;
23 | }
24 |
25 | public void send(String message) {
26 | service.send("email: " + message);
27 | }
28 | }
29 |
30 | public static class EMailService implements NotificationService {
31 | public void send(String message) {
32 | System.out.println("I send " + message);
33 | }
34 | }
35 |
36 | public interface NotificationService {
37 | void send(String message);
38 | }
39 |
40 | public static void main(String[] args) throws Exception {
41 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
42 | "constructorAutowired.xml");
43 | Notifier notifier = context.getBean(Notifier.class);
44 | notifier.send("test email"); // Print "I send email: test email"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_xml/XmlFieldAutowiredTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_xml;
2 |
3 |
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | /**
8 | * Пример использования DI Spring инъекции в приватное поле,
9 | * используя аннотации Spring и конфигурацию через xml файлы
10 | *
11 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
12 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
13 | *
14 | * Created by vvedenin on 11/14/2015.
15 | */
16 | public class XmlFieldAutowiredTest {
17 | public static class Notifier {
18 | @Autowired
19 | private NotificationService service;
20 |
21 | public void setService(NotificationService service) {
22 | this.service = service;
23 | }
24 |
25 | public void send(String message) {
26 | service.send("email: " + message);
27 | }
28 | }
29 |
30 | public static class EMailService implements NotificationService {
31 | public void send(String message) {
32 | System.out.println("I send " + message);
33 | }
34 | }
35 |
36 | public interface NotificationService {
37 | void send(String message);
38 | }
39 |
40 | public static void main(String[] args) throws Exception {
41 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
42 | "fieldAutowired.xml");
43 | Notifier notifier = context.getBean(Notifier.class);
44 | notifier.send("test email"); // Print "I send email: test email"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_xml/XmlSetterAutowiredTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_xml;
2 |
3 |
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | /**
8 | * Пример использования DI Spring инъекции в метод-сеттер,
9 | * используя аннотации Spring и конфигурацию через xml файлы
10 | *
11 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
12 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
13 | *
14 | * Created by vvedenin on 11/14/2015.
15 | */
16 | public class XmlSetterAutowiredTest {
17 | public static class Notifier {
18 | private NotificationService service;
19 |
20 | @Autowired
21 | public void setService(NotificationService service) {
22 | this.service = service;
23 | }
24 |
25 | public void send(String message) {
26 | service.send("email: " + message);
27 | }
28 | }
29 |
30 | public static class EMailService implements NotificationService {
31 | public void send(String message) {
32 | System.out.println("I send " + message);
33 | }
34 | }
35 |
36 | public interface NotificationService {
37 | void send(String message);
38 | }
39 |
40 | public static void main(String[] args) throws Exception {
41 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
42 | "fieldAutowired.xml");
43 | Notifier notifier = context.getBean(Notifier.class);
44 | notifier.send("test email"); // Print "I send email: test email"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/java/com/github/vedenin/rus/spring_xml/jsr300/XmlConstructorInjectTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.spring_xml.jsr300;
2 |
3 | import org.springframework.context.support.ClassPathXmlApplicationContext;
4 |
5 | import javax.inject.Inject;
6 |
7 | /**
8 | * Простейший пример использования DI Spring
9 | *
10 | * Классу Notifier нужен класс реализующий интерфейс NotificationService,
11 | * чтобы отправить сообщение пользователю. Получим эту зависимость через DI
12 | *
13 | * Created by vvedenin on 11/14/2015.
14 | */
15 | public class XmlConstructorInjectTest {
16 | public static class Notifier {
17 | private final NotificationService service;
18 |
19 | @Inject
20 | public Notifier(NotificationService service) {
21 | this.service = service;
22 | }
23 |
24 | public void send(String message) {
25 | service.send("email: " + message);
26 | }
27 | }
28 |
29 | public static class EMailService implements NotificationService {
30 | public void send(String message) {
31 | System.out.println("I send " + message);
32 | }
33 | }
34 |
35 | public interface NotificationService {
36 | void send(String message);
37 | }
38 |
39 | public static void main(String[] args) throws Exception {
40 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
41 | "constructorInject.xml");
42 | Notifier notifier = context.getBean(Notifier.class);
43 | notifier.send("test email"); // Print "I send email: test email"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/resources/constructorAutowired.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/resources/constructorInject.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/resources/fieldAutowired.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/dependency_injection/dependency-injection-spring/src/main/resources/setterAutowired.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/dependency_injection/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | dependency_injection
9 | 0.01
10 | Java In Examples :: Dependency injections
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | dependency-injection-dagger
29 |
30 |
31 | dependency-injection-guice
32 |
33 |
34 | dependency-injection-spring
35 |
36 |
37 |
--------------------------------------------------------------------------------
/html_parser/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | html-parser
9 | 0.01
10 | Java In Examples :: HTML parser
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.google.guava
29 | guava
30 | 29.0-jre
31 |
32 |
33 | org.apache.commons
34 | commons-collections4
35 | 4.1
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.7
41 |
42 |
43 | org.jsoup
44 | jsoup
45 | 1.15.3
46 |
47 |
48 | org.apache.commons
49 | commons-lang3
50 | 3.0
51 |
52 |
53 | commons-lang
54 | commons-lang
55 | 2.6
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/html_parser/src/com.github/vedenin/url_parser/URLDownloadWithProxySelector.java:
--------------------------------------------------------------------------------
1 | package github.vedenin.url_parser.eng;
2 |
3 | import org.apache.commons.io.IOUtils;
4 | import org.apache.commons.lang.StringUtils;
5 |
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.net.*;
9 | import java.nio.charset.StandardCharsets;
10 | import java.util.Collections;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by vvedenin on 2/6/2016.
15 | */
16 | public class URLDownloadWithProxySelector {
17 | private static class TestProxySelector extends ProxySelector {
18 |
19 | @Override
20 | public List select(URI uri) {
21 | return Collections.singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("104.236.222.191", 3128)));
22 | }
23 |
24 | @Override
25 | public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
26 | System.out.println("connectFailed " + uri + ", sa = " + sa + ", ioe = " + ioe);
27 | }
28 | }
29 |
30 | public static void main(String[] args) throws Exception {
31 | TestProxySelector ps = new TestProxySelector();
32 | ProxySelector.setDefault(ps);
33 | URL url = new URL("http://www.oracle.com/technetwork/java/index.html");
34 |
35 | HttpURLConnection conn = (HttpURLConnection)url.openConnection();
36 |
37 | conn.setRequestMethod("GET");
38 | if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
39 | System.out.println(conn.getResponseMessage());
40 | }
41 | else{
42 | InputStream in = conn.getInputStream();
43 | String s = IOUtils.toString(in, StandardCharsets.UTF_8);
44 | System.out.println(s.length());
45 | System.out.println(StringUtils.countMatches(s, "java"));
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/html_parser/src/com.github/vedenin/url_parser/URLDownloadWithProxyTests.java:
--------------------------------------------------------------------------------
1 | package github.vedenin.url_parser.eng;
2 |
3 | import org.apache.commons.io.IOUtils;
4 | import org.apache.commons.lang.StringUtils;
5 |
6 | import java.io.InputStream;
7 | import java.net.*;
8 | import java.nio.charset.StandardCharsets;
9 |
10 | /**
11 | * Testing using proxy in Java
12 | *
13 | * Created by vvedenin on 2/6/2016.
14 | */
15 | public class URLDownloadWithProxyTests {
16 |
17 | private static void testSystemPropertyToSetProxy(String urlString, String proxyUrl, String proxyPort) throws Exception {
18 | //Set the http proxy to webcache.mydomain.com:8080
19 |
20 | System.setProperty("http.proxyHost", proxyUrl); // proxy url
21 | System.setProperty("http.proxyPort", proxyPort); // proxy port
22 |
23 | // Next connection will be through proxy.
24 | URL url = new URL(urlString);
25 | InputStream in = url.openStream();
26 |
27 | String s = IOUtils.toString(in, StandardCharsets.UTF_8);
28 | System.out.println(s.length());
29 | System.out.println(StringUtils.countMatches(s, "java"));
30 | // Now, let's 'unset' the proxy.
31 | System.setProperty("http.proxyHost", "");
32 |
33 | // From now on http connections will be done directly.
34 | }
35 |
36 | private static void testProxyClass(String urlString, String proxyUrl, int proxyPort) throws Exception {
37 | SocketAddress addr = new InetSocketAddress(proxyUrl, proxyPort);
38 | Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
39 | URL url = new URL(urlString);
40 | URLConnection conn = url.openConnection(proxy);
41 | InputStream in = conn.getInputStream();
42 | String s = IOUtils.toString(in, StandardCharsets.UTF_8);
43 | System.out.println(s.length());
44 | System.out.println(StringUtils.countMatches(s, "java"));
45 |
46 | }
47 |
48 | public static void main(String[] args) throws Exception {
49 | testSystemPropertyToSetProxy("http://www.oracle.com/technetwork/java/index.html", "104.236.222.191", "3128");
50 | testProxyClass("http://www.oracle.com/technetwork/java/index.html", "104.236.222.191", 3128);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/machine-learning/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | machine-learning
9 | 0.01
10 | Java In Examples :: Machine Learning
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.airbnb.aerosolve
29 | core
30 | 0.1.45
31 |
32 |
33 | com.airbnb.aerosolve
34 | training
35 | 0.1.45
36 |
37 |
38 | com.github.haifengl
39 | smile-core
40 | 1.1.0
41 |
42 |
43 | com.google.guava
44 | guava
45 | 29.0-jre
46 |
47 |
48 | org.apache.commons
49 | commons-collections4
50 | 4.1
51 |
52 |
53 | commons-io
54 | commons-io
55 | 2.7
56 |
57 |
58 | org.apache.commons
59 | commons-lang3
60 | 3.0
61 |
62 |
63 | commons-lang
64 | commons-lang
65 | 2.6
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/machine-learning/src/com/github/vedenin/machine_learning/Test.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.machine_learning;
2 |
3 | import smile.data.AttributeDataset;
4 | import smile.data.parser.ArffParser;
5 |
6 | import java.io.IOException;
7 | import java.text.ParseException;
8 |
9 | /**
10 | * Created by vedenin on 07.04.16.
11 | */
12 | public class Test {
13 |
14 | private void test() throws IOException, ParseException {
15 | ArffParser arffParser = new ArffParser();
16 | arffParser.setResponseIndex(4);
17 | AttributeDataset weather = arffParser.parse(this.getClass().getResourceAsStream("/smile/data/weka/weather.nominal.arff"));
18 | double[][] x = weather.toArray(new double[weather.size()][]);
19 | int[] y = weather.toArray(new int[weather.size()]);
20 | }
21 |
22 | public static void main(String[] s) throws Exception {
23 | Test cls = new Test();
24 | cls.test();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/natural-language-processing/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | java-in-examples
7 | com.github.vedenin
8 | 0.01
9 |
10 | 4.0.0
11 | natural-language-processing
12 | Java In Examples :: Natural Language Processing
13 |
14 |
15 |
16 |
17 | org.apache.maven.plugins
18 | maven-compiler-plugin
19 | 3.1
20 |
21 | 1.8
22 | 1.8
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | edu.stanford.nlp
31 | stanford-corenlp
32 | 4.4.0
33 |
34 |
35 | edu.stanford.nlp
36 | stanford-corenlp
37 | 3.6.0
38 | models
39 |
40 |
41 | org.apache.opennlp
42 | opennlp-tools
43 | 1.6.0
44 |
45 |
46 | org.apache.opennlp
47 | opennlp-uima
48 | 1.6.0
49 |
50 |
51 | com.google.guava
52 | guava
53 | 29.0-jre
54 |
55 |
56 | org.apache.commons
57 | commons-collections4
58 | 4.1
59 |
60 |
61 | commons-io
62 | commons-io
63 | 2.7
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/natural-language-processing/src/main/java/com/github/vedenin/nlp/OpenNLPSentenceDetectionTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.nlp;
2 |
3 | import opennlp.tools.sentdetect.SentenceDetectorME;
4 | import opennlp.tools.sentdetect.SentenceModel;
5 | import opennlp.tools.util.Span;
6 |
7 | import java.io.FileInputStream;
8 | import java.io.FileNotFoundException;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.util.Arrays;
12 |
13 | /**
14 | * Created by vedenin on 04.02.16.
15 | */
16 | public class OpenNLPSentenceDetectionTest {
17 |
18 | public static final String NATURAL_LANGUAGE_PROCESSING_SRC_MAIN_RESOURCES_EN_SENT_BIN = "natural-language-processing/src/main/resources/en-sent.bin";
19 |
20 | public static void main(String[] strings) throws Exception {
21 | String text = "“But I don’t want to go among mad people,” Alice remarked. " +
22 | "“Oh, you can’t help that,” said the Cat: “we’re all mad here. I’m mad. You’re mad.” " +
23 | "“How do you know I’m mad?” said Alice. " +
24 | "“You must be,” said the Cat, “or you wouldn’t have come here.”";
25 |
26 | try (InputStream modelIn = new FileInputStream(NATURAL_LANGUAGE_PROCESSING_SRC_MAIN_RESOURCES_EN_SENT_BIN)) {
27 | SentenceModel model = new SentenceModel(modelIn);
28 | SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
29 | String sentences[] = sentenceDetector.sentDetect(text);
30 | Span sentences2[] = sentenceDetector.sentPosDetect(text);
31 | for (String sentence : sentences) {
32 | System.out.println(sentence);
33 | }
34 | System.out.println(Arrays.deepToString(sentences2));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/natural-language-processing/src/main/java/com/github/vedenin/nlp/StanfordCoreNLPTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.nlp;
2 |
3 | import edu.stanford.nlp.ling.CoreAnnotations;
4 | import edu.stanford.nlp.pipeline.Annotation;
5 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
6 | import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
7 | import edu.stanford.nlp.util.CoreMap;
8 |
9 | import java.util.List;
10 | import java.util.Properties;
11 |
12 | /**
13 | * Created by vedenin on 30.01.16.
14 | */
15 | public class StanfordCoreNLPTest {
16 |
17 | public static void main(String[] s) {
18 | Properties props = new Properties();
19 | props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
20 | StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
21 |
22 | // read some text in the text variable
23 | String text = "\"But I do not want to go among mad people,\" Alice remarked.\n" +
24 | "\"Oh, you can not help that,\" said the Cat: \"we are all mad here. I am mad. You are mad.\"\n" +
25 | "\"How do you know I am mad?\" said Alice.\n" +
26 | "\"You must be,\" said the Cat, \"or you would not have come here.\" This is awful, bad, disgusting";
27 |
28 | // create an empty Annotation just with the given text
29 | Annotation document = new Annotation(text);
30 |
31 | // run all Annotators on this text
32 | pipeline.annotate(document);
33 |
34 | List sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
35 | for (CoreMap sentence : sentences) {
36 | String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
37 | System.out.println(sentiment + "\t" + sentence);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/natural-language-processing/src/main/resources/en-sent.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vedenin/java_in_examples/1b2da2cd46729e41a8c27b57589c52cd8a5c15f4/natural-language-processing/src/main/resources/en-sent.bin
--------------------------------------------------------------------------------
/other/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | other-examples
9 | 0.01
10 | Java In Examples :: Other
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.google.guava
29 | guava
30 | 29.0-jre
31 |
32 |
33 | org.apache.commons
34 | commons-collections4
35 | 4.1
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.7
41 |
42 |
43 | org.apache.commons
44 | commons-lang3
45 | 3.0
46 |
47 |
48 | commons-lang
49 | commons-lang
50 | 2.6
51 |
52 |
53 | org.springframework
54 | spring-context
55 | 4.2.4.RELEASE
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/other/src/main/java/com/github/vedenin/eng/arrays/ConvertArrayToStringAndPrintTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.arrays;
2 |
3 | import java.util.Arrays;
4 | import java.util.stream.DoubleStream;
5 | import java.util.stream.IntStream;
6 |
7 | /**
8 | * Created by vedenin on 04.02.16.
9 | */
10 | public class ConvertArrayToStringAndPrintTest {
11 | public static void main(String[] s) throws Exception {
12 |
13 | /* (JDK 5) Using Arrays.toString or Arrays.deepToString */
14 | // simple array
15 | String[] array = new String[]{"John", "Mary", "Bob"};
16 | System.out.println(Arrays.toString(array)); //output: [John, Mary, Bob]
17 |
18 | // nested array
19 | String[][] deepArray = new String[][]{{"John", "Mary"}, {"Alice", "Bob"}};
20 | System.out.println(Arrays.toString(deepArray)); //output: [[Ljava.lang.String;@106d69c, [Ljava.lang.String;@52e922]
21 | System.out.println(Arrays.deepToString(deepArray)); //output: [[John, Mary], [Alice, Bob]]
22 |
23 | //double Array
24 | double[] arrayGiven = {7.0, 9.0, 5.0, 1.0, 3.0};
25 | System.out.println(Arrays.toString(arrayGiven)); // Output [7.0, 9.0, 5.0, 1.0, 3.0 ]
26 |
27 | //int Array
28 | int[] arrayInt = {7, 9, 5, 1, 3};
29 | System.out.println(Arrays.toString(arrayInt)); // Output [7, 9, 5, 1, 3 ]
30 |
31 | /* (JDK 8) Using Stream API */
32 | Arrays.asList(array).stream().forEach(System.out::print); // Output JohnMaryBob
33 | System.out.println();
34 | Arrays.asList(deepArray).stream().forEach(s1 -> Arrays.asList(s1).stream().forEach(System.out::print));
35 | System.out.println();
36 | DoubleStream.of(arrayGiven).forEach((d) -> System.out.print(d + " ")); // Output 7.0 9.0 5.0 1.0 3.0
37 | System.out.println();
38 | IntStream.of(arrayInt).forEach(System.out::print); // Output 79513
39 |
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/other/src/main/java/com/github/vedenin/eng/string_and_stream/ConvertStringAndInputStreamTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.string_and_stream;
2 |
3 | import java.io.*;
4 | import java.nio.charset.StandardCharsets;
5 | import java.util.stream.Collectors;
6 |
7 | import com.google.common.base.Charsets;
8 | import com.google.common.io.CharSource;
9 | import com.google.common.io.CharStreams;
10 | import org.apache.commons.io.IOUtils;
11 | import org.apache.commons.io.input.ReaderInputStream;
12 |
13 | /**
14 | * Created by vedenin on 15.01.16.
15 | */
16 | public class ConvertStringAndInputStreamTest {
17 | public static void main(String[] s) throws Exception {
18 | convertStringToOrFromInputStream();
19 | }
20 |
21 | private static void convertStringToOrFromInputStream() throws IOException {
22 | /* 1. Using Apache Utils */
23 | // convert String to InputStream
24 | InputStream inputStreamApache = IOUtils.toInputStream("test1", StandardCharsets.UTF_8);
25 | // convert InputStream to String
26 | String stringApache = IOUtils.toString(inputStreamApache, StandardCharsets.UTF_8);
27 | System.out.println(stringApache); // print test1
28 |
29 | /* 2. Using JDK */
30 | // convert String to InputStream
31 | InputStream inputStreamJDK = new ByteArrayInputStream("test2".getBytes(StandardCharsets.UTF_8));
32 |
33 | // convert InputStream to String
34 | BufferedReader str = new BufferedReader(new InputStreamReader(inputStreamJDK));
35 | String stringJDK = str.readLine();
36 | System.out.println(stringJDK); // print test2
37 |
38 | /* 3. Using guava */
39 | // convert String to InputStream
40 | InputStream targetStreamGuava = new ReaderInputStream(CharSource.wrap("test3").openStream());
41 |
42 | // convert InputStream to String
43 | String stringGuava = CharStreams.toString(new InputStreamReader(targetStreamGuava, Charsets.UTF_8));
44 | System.out.println(stringGuava); // print test3
45 |
46 |
47 | /* 4. Using JDK and Scanner*/
48 | InputStream inputStreamForScanner = new ReaderInputStream(CharSource.wrap("test4").openStream());
49 | // convert InputStream to String
50 | java.util.Scanner s = new java.util.Scanner(inputStreamForScanner).useDelimiter("\\A");
51 | String stringScanner = s.hasNext() ? s.next() : "";
52 | System.out.println(stringScanner);
53 |
54 | /* 5. Using Java 8 */
55 | InputStream inputStreamForJava8 = new ReaderInputStream(CharSource.wrap("test5").openStream());
56 | // convert InputStream to String
57 | String stringJava8 = new BufferedReader(new InputStreamReader(inputStreamForJava8)).lines().collect(Collectors.joining("\n"));
58 | System.out.println(stringJava8);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/other/src/main/java/com/github/vedenin/rus/arrays/ConvertArrayToStringAndPrintTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.arrays;
2 |
3 | import java.util.Arrays;
4 | import java.util.stream.DoubleStream;
5 | import java.util.stream.IntStream;
6 |
7 | /**
8 | * Тестирование превращения массива в строку для печати
9 | *
10 | * Created by vedenin on 04.02.16.
11 | */
12 | public class ConvertArrayToStringAndPrintTest {
13 | public static void main(String[] s) throws Exception {
14 |
15 | /* (JDK 5) Использование Arrays.toString и Arrays.deepToString */
16 | // simple array
17 | String[] array = new String[]{"John", "Mary", "Bob"};
18 | System.out.println(Arrays.toString(array)); // Напечатает: [John, Mary, Bob]
19 |
20 | // nested array
21 | String[][] deepArray = new String[][]{{"John", "Mary"}, {"Alice", "Bob"}};
22 | System.out.println(Arrays.toString(deepArray)); // Напечатает: [[Ljava.lang.String;@106d69c, [Ljava.lang.String;@52e922]
23 | System.out.println(Arrays.deepToString(deepArray)); // Напечатает: [[John, Mary], [Alice, Bob]]
24 |
25 | //double Array
26 | double[] arrayGiven = {7.0, 9.0, 5.0, 1.0, 3.0};
27 | System.out.println(Arrays.toString(arrayGiven)); // Напечатает: [7.0, 9.0, 5.0, 1.0, 3.0 ]
28 |
29 | //int Array
30 | int[] arrayInt = {7, 9, 5, 1, 3};
31 | System.out.println(Arrays.toString(arrayInt)); // Напечатает: [7, 9, 5, 1, 3 ]
32 |
33 | /* (JDK 8) Использование Stream API */
34 | Arrays.asList(array).stream().forEach(System.out::print); // Напечатает: JohnMaryBob
35 | System.out.println();
36 | Arrays.asList(deepArray).stream().forEach(s1 -> Arrays.asList(s1).stream().forEach(System.out::print));
37 | System.out.println();
38 | DoubleStream.of(arrayGiven).forEach((d) -> System.out.print(d + " ")); // Напечатает: 7.0 9.0 5.0 1.0 3.0
39 | System.out.println();
40 | IntStream.of(arrayInt).forEach(System.out::print); // Напечатает: 79513
41 |
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/other/src/main/java/com/github/vedenin/rus/string_and_stream/ConvertStringAndInputStreamTest.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.string_and_stream;
2 |
3 | import com.google.common.base.Charsets;
4 | import com.google.common.io.CharSource;
5 | import com.google.common.io.CharStreams;
6 | import org.apache.commons.io.IOUtils;
7 | import org.apache.commons.io.input.ReaderInputStream;
8 |
9 | import java.io.*;
10 | import java.nio.charset.StandardCharsets;
11 | import java.util.stream.Collectors;
12 |
13 | /**
14 | * примеры преобразование строки в InputStream и обратно
15 | *
16 | * Created by vedenin on 15.01.16.
17 | */
18 | public class ConvertStringAndInputStreamTest {
19 | public static void main(String[] s) throws Exception {
20 | convertStringToOrFromInputStream();
21 | }
22 |
23 | private static void convertStringToOrFromInputStream() throws IOException {
24 | /* 1. Using Apache Utils */
25 | // convert String to InputStream
26 | InputStream inputStreamApache = IOUtils.toInputStream("test1", StandardCharsets.UTF_8);
27 | // convert InputStream to String
28 | String stringApache = IOUtils.toString(inputStreamApache, StandardCharsets.UTF_8);
29 | System.out.println(stringApache); // print test1
30 |
31 | /* 2. Using JDK */
32 | // convert String to InputStream
33 | InputStream inputStreamJDK = new ByteArrayInputStream("test2".getBytes(StandardCharsets.UTF_8));
34 |
35 | // convert InputStream to String
36 | BufferedReader str = new BufferedReader(new InputStreamReader(inputStreamJDK));
37 | String stringJDK = str.readLine();
38 | System.out.println(stringJDK); // print test2
39 |
40 | /* 3. Using guava */
41 | // convert String to InputStream
42 | InputStream targetStreamGuava = new ReaderInputStream(CharSource.wrap("test3").openStream());
43 |
44 | // convert InputStream to String
45 | String stringGuava = CharStreams.toString(new InputStreamReader(targetStreamGuava, Charsets.UTF_8));
46 | System.out.println(stringGuava); // print test3
47 |
48 |
49 | /* 4. Using JDK and Scanner*/
50 | InputStream inputStreamForScanner = new ReaderInputStream(CharSource.wrap("test4").openStream());
51 | // convert InputStream to String
52 | java.util.Scanner s = new java.util.Scanner(inputStreamForScanner).useDelimiter("\\A");
53 | String stringScanner = s.hasNext() ? s.next() : "";
54 | System.out.println(stringScanner);
55 |
56 | /* 5. Using Java 8 */
57 | InputStream inputStreamForJava8 = new ReaderInputStream(CharSource.wrap("test5").openStream());
58 | // convert InputStream to String
59 | String stringJava8 = new BufferedReader(new InputStreamReader(inputStreamForJava8)).lines().collect(Collectors.joining("\n"));
60 | System.out.println(stringJava8);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/perfomance_test/src/main/java/com/github/vedenin/perfomace_test/ConvertBigStringToInputStreamBenchmark.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.perfomace_test;
2 |
3 | import com.google.common.io.CharSource;
4 | import org.apache.commons.io.IOUtils;
5 | import org.apache.commons.io.input.ReaderInputStream;
6 | import org.openjdk.jmh.annotations.*;
7 | import org.openjdk.jmh.runner.Runner;
8 | import org.openjdk.jmh.runner.RunnerException;
9 | import org.openjdk.jmh.runner.options.Options;
10 | import org.openjdk.jmh.runner.options.OptionsBuilder;
11 |
12 | import java.io.ByteArrayInputStream;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.nio.charset.StandardCharsets;
16 | import java.util.concurrent.TimeUnit;
17 |
18 | /**
19 | * Created by vvedenin on 2/15/2016.
20 | */
21 | @State(Scope.Benchmark)
22 | public class ConvertBigStringToInputStreamBenchmark {
23 | private static String test1;
24 |
25 | /* 1. Using ToInputStream of Apache Utils */
26 | @Benchmark
27 | public InputStream apacheToInputStream() throws IOException {
28 | return IOUtils.toInputStream(test1, StandardCharsets.UTF_8);
29 | }
30 |
31 | /* 2. Using JDK */
32 | @Benchmark
33 | public InputStream jdkByteArrayInputStream() throws IOException {
34 | return new ByteArrayInputStream(test1.getBytes(StandardCharsets.UTF_8));
35 | }
36 |
37 | /* 3. Using ReaderInputStream of Apache Utils */
38 | @Benchmark
39 | public InputStream apacheReaderInputStream() throws IOException {
40 | return new ReaderInputStream(CharSource.wrap(test1).openStream());
41 | }
42 |
43 | /* 4. Using Apache Utils and InputStreamReader*/
44 | @Benchmark
45 | public InputStream apacheInputStreamReader() throws IOException {
46 | return IOUtils.toInputStream(test1);
47 | }
48 |
49 | @TearDown(Level.Iteration)
50 | public void tearDown() {
51 | String test = "test184768612876481276487612876417826487216478216784621784672816478216784621784621786478216478216784261784621782178647281647821647821697421687126784621874621786478216478216874";
52 | StringBuilder builder = new StringBuilder(test);
53 | for(int i = 0; i< 1000; i++) {
54 | builder.append(test);
55 | }
56 | test1 = builder.toString();
57 | System.out.println(test1.length());
58 | }
59 |
60 | public static void main(String[] args) throws RunnerException {
61 | Options opt = new OptionsBuilder()
62 | .include(ConvertStringToInputStreamBenchmark.class.getSimpleName())
63 | .timeUnit(TimeUnit.MICROSECONDS)
64 | .warmupIterations(5)
65 | .measurementIterations(50)
66 | .forks(1)
67 | .mode(Mode.AverageTime)
68 | .build();
69 |
70 | new Runner(opt).run();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/perfomance_test/src/main/java/com/github/vedenin/perfomace_test/ConvertStringToInputStreamBenchmark.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.perfomace_test;
2 |
3 | import com.google.common.io.CharSource;
4 | import org.apache.commons.io.IOUtils;
5 | import org.apache.commons.io.input.ReaderInputStream;
6 | import org.openjdk.jmh.annotations.*;
7 | import org.openjdk.jmh.runner.Runner;
8 | import org.openjdk.jmh.runner.RunnerException;
9 | import org.openjdk.jmh.runner.options.Options;
10 | import org.openjdk.jmh.runner.options.OptionsBuilder;
11 |
12 | import java.io.ByteArrayInputStream;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.nio.charset.StandardCharsets;
16 | import java.util.concurrent.TimeUnit;
17 |
18 | /**
19 | * Created by vvedenin on 2/15/2016.
20 | */
21 | @BenchmarkMode(Mode.AverageTime)
22 | @OutputTimeUnit(TimeUnit.MICROSECONDS)
23 | @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
24 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
25 | @Fork(1)
26 | @State(Scope.Benchmark)
27 | public class ConvertStringToInputStreamBenchmark {
28 | private static final String test1 = "test184768612876481276487612876417826487216478216784621784672816478216784621784621786478216478216784261784621782178647281647821647821697421687126784621874621786478216478216874";
29 |
30 | /* 1. Using ToInputStream of Apache Utils */
31 | @Benchmark
32 | public InputStream apacheToInputStream() throws IOException {
33 | return IOUtils.toInputStream(test1, StandardCharsets.UTF_8);
34 | }
35 |
36 | /* 2. Using JDK */
37 | @Benchmark
38 | public InputStream jdkByteArrayInputStream() throws IOException {
39 | return new ByteArrayInputStream(test1.getBytes(StandardCharsets.UTF_8));
40 | }
41 |
42 | /* 3. Using ReaderInputStream of Apache Utils */
43 | @Benchmark
44 | public InputStream apacheReaderInputStream() throws IOException {
45 | return new ReaderInputStream(CharSource.wrap(test1).openStream());
46 | }
47 |
48 | /* 4. Using Apache Utils and InputStreamReader*/
49 | @Benchmark
50 | public InputStream apacheInputStreamReader() throws IOException {
51 | return IOUtils.toInputStream(test1);
52 | }
53 |
54 | public static void main(String[] args) throws RunnerException {
55 | Options opt = new OptionsBuilder()
56 | .include(ConvertStringToInputStreamBenchmark.class.getSimpleName())
57 | .build();
58 |
59 | new Runner(opt).run();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/perfomance_test/src/main/java/com/github/vedenin/perfomace_test/FindCountOfOccurrencesBenchmark.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.perfomace_test;
2 |
3 | import org.apache.commons.lang.StringUtils;
4 | import org.openjdk.jmh.annotations.*;
5 | import org.openjdk.jmh.runner.Runner;
6 | import org.openjdk.jmh.runner.RunnerException;
7 | import org.openjdk.jmh.runner.options.Options;
8 | import org.openjdk.jmh.runner.options.OptionsBuilder;
9 |
10 | import java.util.*;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | @BenchmarkMode(Mode.AverageTime)
14 | @OutputTimeUnit(TimeUnit.MICROSECONDS)
15 | @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
16 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
17 | @Fork(1)
18 | @State(Scope.Benchmark)
19 | public class FindCountOfOccurrencesBenchmark {
20 | public static final String testString = "a.b.c.d";
21 |
22 | @Benchmark
23 | public int countMatches() {
24 | // Using Apache Commons
25 | return StringUtils.countMatches(testString, ".");
26 | }
27 |
28 |
29 | @Benchmark
30 | public int countOccurrencesOf() {
31 | // Using Spring Framework's
32 | return org.springframework.util.StringUtils.countOccurrencesOf(testString, ".");
33 | }
34 |
35 | @Benchmark
36 | public int replace() {
37 | // Using replace
38 | return testString.length() - testString.replace(".", "").length();
39 | }
40 |
41 | @Benchmark
42 | public int replaceAll1() {
43 | // Using replaceAll case 1
44 | return testString.replaceAll("[^.]", "").length();
45 | }
46 |
47 | @Benchmark
48 | public int replaceAll2() {
49 | // Using replaceAll case 2
50 | return testString.length() - testString.replaceAll("\\.", "").length();
51 | }
52 |
53 | @Benchmark
54 | public int split() {
55 | // Using split
56 | return testString.split("\\.",-1).length-1;
57 | }
58 |
59 | @Benchmark
60 | public long java8() {
61 | // Using Java8
62 | return testString.chars().filter(ch -> ch =='.').count();
63 | }
64 |
65 | @Benchmark
66 | public long java8_1() {
67 | // Using Java8 (case 2)
68 | return testString.codePoints().filter(ch -> ch == '.').count();
69 | }
70 |
71 | @Benchmark
72 | public int stringTokenizer() {
73 | // Using StringTokenizer
74 | return new StringTokenizer(" " + testString + " ", ".").countTokens() - 1;
75 | }
76 |
77 | public static void main(String[] args) throws RunnerException {
78 | Options opt = new OptionsBuilder()
79 | .include(FindCountOfOccurrencesBenchmark.class.getSimpleName())
80 | .build();
81 |
82 | new Runner(opt).run();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | java-in-examples
9 | 0.01
10 | Java In Examples :: Main
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.google.guava
29 | guava
30 | 29.0-jre
31 |
32 |
33 | org.apache.commons
34 | commons-collections4
35 | 4.1
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.7
41 |
42 |
43 | com.goldmansachs
44 | gs-collections-api
45 | 6.2.0
46 |
47 |
48 |
49 | com.goldmansachs
50 | gs-collections
51 | 6.2.0
52 |
53 |
54 |
55 | com.goldmansachs
56 | gs-collections-testutils
57 | 6.2.0
58 | test
59 |
60 |
61 |
62 | com.goldmansachs
63 | gs-collections-forkjoin
64 | 6.2.0
65 |
66 |
67 |
68 |
69 | html_parser
70 | stream_api
71 | collections
72 | dependency_injection
73 | natural-language-processing
74 | other
75 | web
76 | spring
77 | machine-learning
78 |
79 |
80 |
--------------------------------------------------------------------------------
/spring/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | pom
7 | com.github.vedenin
8 | spring
9 | 0.01
10 |
11 |
12 | spring_core
13 |
14 |
--------------------------------------------------------------------------------
/spring/spring_core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.vedenin
8 | spring_core
9 | 0.01
10 |
11 |
12 |
13 |
14 | org.apache.maven.plugins
15 | maven-compiler-plugin
16 | 3.1
17 |
18 | 1.8
19 | 1.8
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | org.springframework
28 | spring-context
29 | 4.2.2.RELEASE
30 |
31 |
32 |
33 | org.springframework.security
34 | spring-security-web
35 | 5.2.10.RELEASE
36 |
37 |
38 |
39 | javax.inject
40 | javax.inject
41 | 1
42 |
43 |
44 |
--------------------------------------------------------------------------------
/spring/spring_core/src/main/resources/constructorAutowired.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring/spring_core/src/main/resources/constructorInject.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring/spring_core/src/main/resources/fieldAutowired.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring/spring_core/src/main/resources/setterAutowired.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/stream_api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | pom
6 |
7 | com.github.vedenin
8 | stream-api-in-examples
9 | 0.01
10 | Java In Examples :: Stream Api
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.1
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | com.google.guava
29 | guava
30 | 29.0-jre
31 |
32 |
33 | org.apache.commons
34 | commons-collections4
35 | 4.1
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.7
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/eng/stream_api/DistinctTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.stream_api;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.HashSet;
6 | import java.util.List;
7 | import java.util.stream.Collectors;
8 |
9 | /**
10 | *
11 | * Distinct method example in Stream Api
12 | *
13 | * Created by vedenin on 17 .10.15.
14 | */
15 | public class DistinctTests {
16 | private static void testDistinct() {
17 | System.out.println();
18 | System.out.println("Test distinct start");
19 | Collection ordered = Arrays.asList("a1", "a2", "a2", "a3", "a1", "a2", "a2");
20 | Collection nonOrdered = new HashSet<>(ordered);
21 |
22 | // Get collection without duplicate
23 | List distinct = nonOrdered.stream().distinct().collect(Collectors.toList());
24 | System.out.println("distinct = " + distinct); // print distinct = [a1, a2, a3] - порядок не гарантируется
25 |
26 | List distinctOrdered = ordered.stream().distinct().collect(Collectors.toList());
27 | System.out.println("distinctOrdered = " + distinctOrdered); // print distinct = [a1, a2, a3] - порядок гарантируется
28 | }
29 |
30 | public static void main(String[] args) throws Exception {
31 | testDistinct();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/eng/stream_api/FindAndMatchTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.stream_api;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | *
10 | * Find and match example of Stream Api
11 | *
12 | * Created by vedenin on 17 .10.15.
13 | */
14 | public class FindAndMatchTests {
15 | private static void testFindFirstSkipCount() {
16 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
17 |
18 | System.out.println("Test findFirst and skip start");
19 | // get first element of collection
20 | String first = collection.stream().findFirst().orElse("1");
21 | System.out.println("first = " + first); // print first = a1
22 |
23 | // get last element of collection
24 | String last = collection.stream().skip(collection.size() - 1).findAny().orElse("1");
25 | System.out.println("last = " + last ); // print last = a1
26 |
27 | // find element in collection
28 | String find = collection.stream().filter("a3"::equals).findFirst().get();
29 | System.out.println("find = " + find); // print find = a3
30 |
31 | // find 3 element in collection
32 | String third = collection.stream().skip(2).findFirst().get();
33 | System.out.println("third = " + third); // print third = a3
34 |
35 | System.out.println();
36 | System.out.println("Test collect start");
37 | // get all element according pattern
38 | List select = collection.stream().filter((s) -> s.contains("1")).collect(Collectors.toList());
39 | System.out.println("select = " + select); // print select = [a1, a1]
40 | }
41 |
42 | private static void testMatch() {
43 | System.out.println();
44 | System.out.println("Test anyMatch, allMatch, noneMatch start");
45 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
46 |
47 | // find that collection has at least one element according pattern
48 | boolean isAnyOneTrue = collection.stream().anyMatch("a1"::equals);
49 | System.out.println("anyOneTrue " + isAnyOneTrue); // print true
50 | boolean isAnyOneFalse = collection.stream().anyMatch("a8"::equals);
51 | System.out.println("anyOneFlase " + isAnyOneFalse); // print false
52 |
53 | // find that all element in collection mathed with pattern or not
54 | boolean isAll = collection.stream().allMatch((s) -> s.contains("1"));
55 | System.out.println("isAll " + isAll); // print false
56 |
57 | // compare is not equals
58 | boolean isNotEquals = collection.stream().noneMatch("a7"::equals);
59 | System.out.println("isNotEquals " + isNotEquals); // print true
60 | }
61 |
62 | public static void main(String[] args) throws Exception {
63 | testFindFirstSkipCount();
64 | testMatch();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/eng/stream_api/ForEachAndPeekTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.stream_api;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | *
10 | * ForEach and Peak example of Stream Api
11 | *
12 | * Created by vedenin on 17 .10.15.
13 | */
14 | public class ForEachAndPeekTests {
15 |
16 | private static void testForEach() {
17 | System.out.println();
18 | System.out.println("For each start");
19 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
20 | // Print debug information for every element
21 | System.out.print("forEach = ");
22 | collection.stream().map(String::toUpperCase).forEach((e) -> System.out.print(e + ",")); // print forEach = A1,A2,A3,A1,
23 | System.out.println();
24 |
25 | Collection list = Arrays.asList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
26 | list.stream().forEachOrdered((p) -> p.append("_new"));
27 | System.out.println("forEachOrdered = " + list); // print forEachOrdered = [a1_new, a2_new, a3_new]
28 | }
29 |
30 | private static void testPeek() {
31 | System.out.println();
32 | System.out.println("Test peek start");
33 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
34 | // Print debug information for every element
35 | System.out.print("peak1 = ");
36 | List peek = collection.stream().map(String::toUpperCase).peek((e) -> System.out.print(e + ",")).
37 | collect(Collectors.toList());
38 | System.out.println(); // print peak1 = A1,A2,A3,A1,
39 | System.out.println("peek2 = " + peek); // print peek2 = [A1, A2, A3, A1]
40 |
41 | Collection list = Arrays.asList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
42 | List newList = list.stream().peek((p) -> p.append("_new")).collect(Collectors.toList());
43 | System.out.println("newList = " + newList); // print newList = [a1_new, a2_new, a3_new]
44 | }
45 |
46 | public static void main(String[] args) throws Exception {
47 | testForEach();
48 | testPeek();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/eng/stream_api/LimitAndSkipTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.stream_api;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | *
10 | * Limit and skip examples of Stream Api
11 | *
12 | * Created by vedenin on 17 .10.15.
13 | */
14 | public class LimitAndSkipTests {
15 | private static void testLimit() {
16 | System.out.println();
17 | System.out.println("Test limit start");
18 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
19 |
20 | // Get the first two elements
21 | List limit = collection.stream().limit(2).collect(Collectors.toList());
22 | System.out.println("limit = " + limit); // print limit = [a1, a2]
23 |
24 | // Get two elements from second element
25 | List fromTo = collection.stream().skip(1).limit(2).collect(Collectors.toList());
26 | System.out.println("fromTo = " + fromTo); // print fromTo = [a2, a3]
27 |
28 | // Get the last element
29 | String last = collection.stream().skip(collection.size() - 1).findAny().orElse("1");
30 | System.out.println("last = " + last ); // print last = a1
31 | }
32 |
33 | public static void main(String[] args) throws Exception {
34 | testLimit();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/eng/stream_api/MapTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.eng.stream_api;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | *
10 | * Map examples of Stream Api
11 | *
12 | * Created by vedenin on 17 .10.15.
13 | */
14 | public class MapTests {
15 | private static void testMap() {
16 | System.out.println();
17 | System.out.println("Test map start");
18 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
19 | // Change all elements
20 | List transform = collection.stream().map((s) -> s + "_1").collect(Collectors.toList());
21 | System.out.println("transform = " + transform); // print transform = [a1_1, a2_1, a3_1, a1_1]
22 |
23 | // Delete first char of element and returns number
24 | List number = collection.stream().map((s) -> Integer.parseInt(s.substring(1))).collect(Collectors.toList());
25 | System.out.println("number = " + number); // print transform = [1, 2, 3, 1]
26 |
27 | }
28 |
29 | private static void testMapToInt() {
30 | System.out.println();
31 | System.out.println("Test mapToInt start");
32 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
33 | // Delete first char of element and returns number
34 | int[] number = collection.stream().mapToInt((s) -> Integer.parseInt(s.substring(1))).toArray();
35 | System.out.println("number = " + Arrays.toString(number)); // print number = [1, 2, 3, 1]
36 |
37 | }
38 |
39 | private static void testFlatMap() {
40 | System.out.println();
41 | System.out.println("Test flat map start");
42 | Collection collection = Arrays.asList("1,2,0", "4,5");
43 | // Get all digit from strings
44 | String[] number = collection.stream().flatMap((p) -> Arrays.asList(p.split(",")).stream()).toArray(String[]::new);
45 | System.out.println("number = " + Arrays.toString(number)); // print number = [1, 2, 0, 4, 5]
46 | }
47 |
48 | private static void testFlatMapToInt() {
49 | System.out.println();
50 | System.out.println("Test flat map start");
51 | Collection collection = Arrays.asList("1,2,0", "4,5");
52 | // Get sum all digit from strings
53 | int sum = collection.stream().flatMapToInt((p) -> Arrays.asList(p.split(",")).stream().mapToInt(Integer::parseInt)).sum();
54 | System.out.println("sum = " + sum); // print sum = 12
55 | }
56 |
57 | public static void main(String[] args) throws Exception {
58 | testMap();
59 | testMapToInt();
60 | testFlatMap();
61 | testFlatMapToInt();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/rus/stream_api/DistinctTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.stream_api;
2 |
3 | import java.util.*;
4 | import java.util.stream.Collectors;
5 |
6 | /**
7 | *
8 | * Примеры работы методов Stream Api
9 | *
10 | * Created by vedenin on 17 .10.15.
11 | */
12 | public class DistinctTests {
13 | // Метод distinct возвращает stream без дубликатов, при этом для упорядоченного стрима (например, коллекция на основе list) порядок стабилен , для неупорядоченного - порядок не гарантируется
14 | // Метод collect преобразует stream в коллекцию или другую структуру данных
15 | private static void testDistinct() {
16 | System.out.println();
17 | System.out.println("Test distinct start");
18 | Collection ordered = Arrays.asList("a1", "a2", "a2", "a3", "a1", "a2", "a2");
19 | Collection nonOrdered = new HashSet<>(ordered);
20 |
21 | // Получение коллекции без дубликатов
22 | List distinct = nonOrdered.stream().distinct().collect(Collectors.toList());
23 | System.out.println("distinct = " + distinct); // напечатает distinct = [a1, a2, a3] - порядок не гарантируется
24 |
25 | List distinctOrdered = ordered.stream().distinct().collect(Collectors.toList());
26 | System.out.println("distinctOrdered = " + distinctOrdered); // напечатает distinct = [a1, a2, a3] - порядок гарантируется
27 | }
28 |
29 | public static void main(String[] args) throws Exception {
30 | testDistinct();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/rus/stream_api/ForEachAndPeekTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.stream_api;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | *
10 | * Примеры работы методов Stream Api
11 | *
12 | * Created by vedenin on 17 .10.15.
13 | */
14 | public class ForEachAndPeekTests {
15 |
16 | // Метод ForEach применяет указанный метод к каждому элементу стрима и заканчивает работу со стримом
17 | private static void testForEach() {
18 | System.out.println();
19 | System.out.println("For each start");
20 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
21 | // Напечатать отладочную информацию по каждому элементу стрима
22 | System.out.print("forEach = ");
23 | collection.stream().map(String::toUpperCase).forEach((e) -> System.out.print(e + ",")); // напечатает forEach = A1,A2,A3,A1,
24 | System.out.println();
25 |
26 | Collection list = Arrays.asList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
27 | list.stream().forEachOrdered((p) -> p.append("_new"));
28 | System.out.println("forEachOrdered = " + list); // напечатает forEachOrdered = [a1_new, a2_new, a3_new]
29 | }
30 |
31 | // Метод Peek возвращает тот же стрим, но при этом применяет указанный метод к каждому элементу стрима
32 | private static void testPeek() {
33 | System.out.println();
34 | System.out.println("Test peek start");
35 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
36 | // Напечатать отладочную информацию по каждому элементу стрима
37 | System.out.print("peak1 = ");
38 | List peek = collection.stream().map(String::toUpperCase).peek((e) -> System.out.print(e + ",")).
39 | collect(Collectors.toList());
40 | System.out.println(); // напечатает peak1 = A1,A2,A3,A1,
41 | System.out.println("peek2 = " + peek); // напечатает peek2 = [A1, A2, A3, A1]
42 |
43 | Collection list = Arrays.asList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
44 | List newList = list.stream().peek((p) -> p.append("_new")).collect(Collectors.toList());
45 | System.out.println("newList = " + newList); // напечатает newList = [a1_new, a2_new, a3_new]
46 | }
47 |
48 | public static void main(String[] args) throws Exception {
49 | testForEach();
50 | testPeek();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/stream_api/src/com/github/vedenin/rus/stream_api/LimitAndSkipTests.java:
--------------------------------------------------------------------------------
1 | package com.github.vedenin.rus.stream_api;
2 |
3 | import java.util.*;
4 | import java.util.stream.Collectors;
5 |
6 | /**
7 | *
8 | * Примеры работы методов Stream Api
9 | *
10 | * Created by vedenin on 17 .10.15.
11 | */
12 | public class LimitAndSkipTests {
13 | // Метод Limit позволяет ограничить выборку определенным количеством первых элементов
14 | private static void testLimit() {
15 | System.out.println();
16 | System.out.println("Test limit start");
17 | Collection collection = Arrays.asList("a1", "a2", "a3", "a1");
18 |
19 | // Вернуть первые два элемента
20 | List limit = collection.stream().limit(2).collect(Collectors.toList());
21 | System.out.println("limit = " + limit); // напечатает limit = [a1, a2]
22 |
23 | // Вернуть два элемента начиная со второго
24 | List fromTo = collection.stream().skip(1).limit(2).collect(Collectors.toList());
25 | System.out.println("fromTo = " + fromTo); // напечатает fromTo = [a2, a3]
26 |
27 | // вернуть последний элемент коллекции
28 | String last = collection.stream().skip(collection.size() - 1).findAny().orElse("1");
29 | System.out.println("last = " + last ); // напечатает last = a1
30 | }
31 |
32 | public static void main(String[] args) throws Exception {
33 | testLimit();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/web/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.github.vedenin
7 | pom
8 | web
9 | Java In Examples :: Web
10 | 0.01
11 |
12 |
13 | tomcat_plugin
14 |
15 |
--------------------------------------------------------------------------------
/web/tomcat_plugin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.vedenin
8 | tomcat_plugin
9 | 0.01
10 |
11 |
12 |
13 |
14 | org.apache.tomcat.maven
15 | tomcat7-maven-plugin
16 | 2.3-SNAPSHOT
17 |
18 | http://www.mydomain.com:1234/mymanager
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------