├── .gitignore ├── article.md ├── contributing.md ├── hello world ├── helloooo world ├── helloworlds ├── 1.1-common-frameworks-and-lib │ ├── apache-commons-lib │ │ ├── pom.xml │ │ └── src │ │ │ ├── ApacheBidiMap.java │ │ │ ├── ApacheCollectionCompare.java │ │ │ ├── ApacheCollectionSearch.java │ │ │ ├── ApacheCollectionTransform.java │ │ │ ├── ApacheHashBag.java │ │ │ ├── ApacheMultiValueMap.java │ │ │ ├── ApacheMultiValueMapLinked.java │ │ │ ├── ApacheMultiValueMapTree.java │ │ │ ├── ApacheSynchronizedBag.java │ │ │ ├── ApacheSynchronizedSortedBag.java │ │ │ └── ApacheTreeBag.java │ ├── guava-lib │ │ ├── pom.xml │ │ └── src │ │ │ ├── GuavaArrayListMultimap.java │ │ │ ├── GuavaBiMap.java │ │ │ ├── GuavaCollectionCompare.java │ │ │ ├── GuavaCollectionSearch.java │ │ │ ├── GuavaCollectionTransform.java │ │ │ ├── GuavaConcurrentHashMultiset.java │ │ │ ├── GuavaCreateCollection.java │ │ │ ├── GuavaEnumBiMap.java │ │ │ ├── GuavaEnumHashBiMap.java │ │ │ ├── GuavaHashMultiMap.java │ │ │ ├── GuavaHashMultiset.java │ │ │ ├── GuavaLinkedHashMultimap.java │ │ │ ├── GuavaLinkedHashMultiset.java │ │ │ ├── GuavaLinkedListMultimap.java │ │ │ ├── GuavaTreeMultimap.java │ │ │ └── GuavaTreeMultiset.java │ ├── pom.xml │ ├── quasar │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ ├── FiberHelloWorld.java │ │ │ │ ├── FiberSleepHelloWorld.java │ │ │ │ └── FibersAndChanelHelloWorld.java │ │ │ └── test │ │ │ └── java │ │ │ └── HelloWordsTest.java │ └── spring │ │ ├── pom.xml │ │ ├── resources │ │ ├── constructorAutowired.xml │ │ ├── constructorInject.xml │ │ ├── fieldAutowired.xml │ │ └── setterAutowired.xml │ │ └── src │ │ ├── SpringBeanScopeTest.java │ │ ├── SpringConstructorAutowired.java │ │ ├── SpringFieldAutowired.java │ │ ├── SpringSetterAutowired.java │ │ ├── jsr330 │ │ └── SpringSimpleInject.java │ │ └── xml │ │ ├── XmlConstructorAutowired.java │ │ ├── XmlFieldAutowired.java │ │ ├── XmlSetterAutowired.java │ │ └── jsr330 │ │ └── XmlConstructorInject.java ├── 1.6-usefull-libraries │ ├── bean_mapping │ │ ├── dozer │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── dozer │ │ │ │ │ ├── DozerHelloWorldAnnotation.java │ │ │ │ │ ├── DozerHelloWorldApi.java │ │ │ │ │ └── DozerHelloWorldXML.java │ │ │ │ └── resources │ │ │ │ └── mapping.xml │ │ ├── mapstruct │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── mapstruct │ │ │ │ └── MapStructHelloWorld.java │ │ ├── modelmapper │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── modelmapper │ │ │ │ └── ModelMapperHelloWorld.java │ │ ├── orika │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── orika │ │ │ │ └── OrikaHelloWorld.java │ │ ├── pom.xml │ │ └── selma │ │ │ ├── pom.xml │ │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── selma │ │ │ ├── SelmaHelloWorld.java │ │ │ └── TestMapper.java │ ├── collections │ │ ├── apache-commons │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── ApacheBidiMapTest.java │ │ │ │ ├── ApacheHashBagTest.java │ │ │ │ ├── ApacheMultiValueMapLinkedTest.java │ │ │ │ ├── ApacheMultiValueMapTest.java │ │ │ │ ├── ApacheMultiValueMapTreeTest.java │ │ │ │ ├── ApacheSynchronizedBagTest.java │ │ │ │ ├── ApacheSynchronizedSortedBagTest.java │ │ │ │ ├── ApacheTreeBagTest.java │ │ │ │ ├── CollectionCompareTests.java │ │ │ │ ├── CollectionSearchTests.java │ │ │ │ └── JavaTransformTest.java │ │ ├── gs-eclipse │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── CollectionCompareTests.java │ │ │ │ ├── CollectionSearchTests.java │ │ │ │ ├── CreateCollectionTest.java │ │ │ │ ├── GsFastListMultimapTest.java │ │ │ │ ├── GsHashBagMultimapTest.java │ │ │ │ ├── GsHashBiMapTest.java │ │ │ │ ├── GsMutableBagTest.java │ │ │ │ ├── GsMutableSortedBagTest.java │ │ │ │ ├── GsTreeSortedSetMultimapTest.java │ │ │ │ ├── GsUnifiedSetMultimapTest.java │ │ │ │ └── JavaTransformTest.java │ │ ├── guava │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── CollectionCompareTests.java │ │ │ │ ├── CollectionSearchTests.java │ │ │ │ ├── CreateCollectionTest.java │ │ │ │ ├── GuavaArrayListMultimapTest.java │ │ │ │ ├── GuavaBiMapTest.java │ │ │ │ ├── GuavaConcurrentHashMultisetTest.java │ │ │ │ ├── GuavaEnumBiMapTest.java │ │ │ │ ├── GuavaEnumHashBiMapTest.java │ │ │ │ ├── GuavaHashMultiMapTest.java │ │ │ │ ├── GuavaHashMultisetTest.java │ │ │ │ ├── GuavaLinkedHashMultimapTest.java │ │ │ │ ├── GuavaLinkedHashMultisetTest.java │ │ │ │ ├── GuavaLinkedListMultimapTest.java │ │ │ │ ├── GuavaTreeMultimapTest.java │ │ │ │ ├── GuavaTreeMultisetTest.java │ │ │ │ └── JavaTransformTest.java │ │ ├── pom.xml │ │ ├── readme-russain.md │ │ └── readme.md │ ├── dependency_injection │ │ ├── dependency-injection-dagger │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── dagger │ │ │ │ └── SimpleDaggerDI.java │ │ ├── dependency-injection-guice │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── GuiceConstructor.java │ │ │ │ ├── GuiceFieldInject.java │ │ │ │ └── GuiceSetterInject.java │ │ ├── dependency-injection-spring │ │ │ ├── pom.xml │ │ │ ├── resources │ │ │ │ ├── constructorAutowired.xml │ │ │ │ ├── constructorInject.xml │ │ │ │ ├── fieldAutowired.xml │ │ │ │ └── setterAutowired.xml │ │ │ └── src │ │ │ │ ├── SpringConstructorAutowired.java │ │ │ │ ├── SpringFieldAutowired.java │ │ │ │ ├── SpringSetterAutowired.java │ │ │ │ ├── jsr330 │ │ │ │ └── SpringSimpleInject.java │ │ │ │ └── xml │ │ │ │ ├── XmlConstructorAutowired.java │ │ │ │ ├── XmlFieldAutowired.java │ │ │ │ ├── XmlSetterAutowired.java │ │ │ │ └── jsr330 │ │ │ │ └── XmlConstructorInject.java │ │ └── pom.xml │ ├── functional_programming │ │ ├── cyclops_react │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── cyclopsreact │ │ │ │ ├── CyclopsReactCollections.java │ │ │ │ └── CyclopsReactHelloWorld.java │ │ ├── javaslang │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── javaslang │ │ │ │ └── JavaSlangCollections.java │ │ ├── jdk_stream_api │ │ │ ├── pom.xml │ │ │ ├── readme-russian.md │ │ │ ├── readme.md │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── streamapi │ │ │ │ ├── BuildTests.java │ │ │ │ ├── CollectAndToArrayTests.java │ │ │ │ ├── DistinctTests.java │ │ │ │ ├── FindAndMatchTests.java │ │ │ │ ├── FiterAndCountTests.java │ │ │ │ ├── ForEachAndPeekTests.java │ │ │ │ ├── LimitAndSkipTests.java │ │ │ │ ├── MapTests.java │ │ │ │ ├── MaxMinTests.java │ │ │ │ ├── ReduceTests.java │ │ │ │ └── SortedTests.java │ │ └── pom.xml │ └── pom.xml ├── 2.8-machine-learning │ ├── deeplearning4j │ │ └── pom.xml │ ├── pom.xml │ └── smile │ │ ├── pom.xml │ │ ├── resources │ │ ├── supermarket.arff │ │ └── weather.nominal.arff │ │ └── src │ │ └── SmileHelloWorld.java ├── 2.8-natural-language-processing │ ├── opennlp │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── OpenNLPSentenceDetectors.java │ │ │ └── resources │ │ │ └── en-sent.bin │ ├── pom.xml │ └── stanford-core-nlp │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── StanfordCoreNLPSentenceDetectors.java ├── 3.7-web-crawling-and-html-parser │ ├── Jsoup │ │ ├── pom.xml │ │ └── src │ │ │ ├── GithubDownLoadTests.java │ │ │ └── URLDownloadTests.java │ └── pom.xml ├── 3.8-json │ ├── fastjson │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── fastjson │ │ │ ├── FastJsonHelloWorld.java │ │ │ └── JsonPathHelloWorld.java │ ├── genson │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── genson │ │ │ └── GensonHelloWorld.java │ ├── gson │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── gson │ │ │ ├── GsonHelloWorld.java │ │ │ └── advanced │ │ │ ├── StreamingAPI.java │ │ │ └── TreeModel.java │ ├── ig_json_parser │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── ig_json_parser │ │ │ ├── Human.java │ │ │ ├── IgJsonParserHelloWorld.java │ │ │ └── Place.java │ ├── jackson │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── jackson │ │ │ ├── JacksonHelloWorld.java │ │ │ └── advanced │ │ │ ├── JsonPointerHelloWorld.java │ │ │ ├── StreamingAPI.java │ │ │ └── TreeModel.java │ ├── json_java │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── json_java │ │ │ └── JsonJavaHelloWorld.java │ ├── json_path │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── json_path │ │ │ └── JsonPathHelloWorld.java │ ├── json_schema_validator │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── json_schema_validator │ │ │ │ └── JsonSchemaValidatorHelloWorld.java │ │ │ └── resources │ │ │ ├── fstab-bad.json │ │ │ ├── fstab-bad2.json │ │ │ ├── fstab-good.json │ │ │ └── fstab.json │ ├── json_simple │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── json_simple │ │ │ └── JsonSimpleHelloWorld.java │ ├── jsonschema2pojo │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── jsonschema2pojo │ │ │ │ └── JsonSchema2HelloWorld.java │ │ │ └── resources │ │ │ └── schema.json │ ├── logansquare │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── logansquare │ │ │ ├── Human.java │ │ │ ├── LoganSquarenParserHelloWorld.java │ │ │ └── Place.java │ ├── minimal-json │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── minimal_json │ │ │ └── JsonMinimalHelloWorld.java │ ├── moshi │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── moshi │ │ │ └── MoshiHelloWorld.java │ ├── pom.xml │ ├── readme-russian.md │ └── readme.md ├── 4.1-testing │ ├── cucumber │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── Belly.java │ │ │ └── test │ │ │ ├── java │ │ │ ├── HelloWorldTest.java │ │ │ └── Stepdefs.java │ │ │ └── resources │ │ │ └── belly.feature │ ├── image-comparison │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── github │ │ │ │ └── vedenin │ │ │ │ └── imagecomparison │ │ │ │ └── Sample.java │ │ │ └── resources │ │ │ ├── actual.png │ │ │ └── expected.png │ ├── mockito │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ ├── Cashier.java │ │ │ │ ├── Client.java │ │ │ │ ├── CodeError.java │ │ │ │ ├── Main.java │ │ │ │ └── Product.java │ │ │ └── test │ │ │ └── java │ │ │ ├── CashierTest.java │ │ │ ├── ClientTest.java │ │ │ └── CreateMockWithAnnotation.java │ └── pom.xml ├── 5.0-other-examples │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── other_examples │ │ ├── ConvertBigStringToInputStreamBenchmark.java │ │ ├── ConvertInputStreamToStringBenchmark.java │ │ ├── ConvertInputStreamToStringBigBenchmark.java │ │ ├── ConvertStringToInputStreamBenchmark.java │ │ ├── FindCountOfOccurrencesBenchmark.java │ │ ├── FindCountOfOccurrencesBigBenchmark.java │ │ ├── IterateThroughHashMapTest.java │ │ └── readme.md ├── 9.9-template │ ├── library_name │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── library_package │ │ │ ├── TemplateHelloWorld.java │ │ │ └── advanced │ │ │ └── AdvancedTemplate.java │ └── pom.xml ├── contributing-russian.md ├── contributing.md ├── pom.xml └── readme.md ├── img ├── business-friendly.png ├── impossible-proprietary-code-linking.png └── proprietary-license.png ├── license.md ├── link-rus ├── contributing.md ├── github_projects.md ├── img │ ├── good-proprietary.png │ ├── non-proprietary.png │ └── proprietary.png ├── readme.md └── video-links.md └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | ### Java template 2 | *.class 3 | .idea 4 | *.iml 5 | 6 | # Mobile Tools for Java (J2ME) 7 | .mtj.tmp/ 8 | 9 | # Package Files # 10 | *.jar 11 | *.war 12 | *.ear 13 | 14 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 15 | hs_err_pid* 16 | 17 | # Created by .ignore support plugin (hsz.mobi) 18 | -------------------------------------------------------------------------------- /article.md: -------------------------------------------------------------------------------- 1 | My articles (in English): 2 | 3 | 1. [Alternative java collections overview](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/1.6-usefull-libraries/collections) 4 | 1. [All Java libraries](https://github.com/Vedenin/useful-java-links) 5 | 1. [Json](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json) 6 | 1. [jdk_stream_api](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/1.6-usefull-libraries/functional_programming/jdk_stream_api) 7 | 1. [Dependency Injection and AOP: Dagger,Guava,Spring](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds) 8 | 1. [Bean Mapping and Validation: Dozer, MapStruct, ModelMapper, Orika, Selma](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds) 9 | 1. [Other](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds) 10 | 11 | My articles (in Russian): [this](https://habrahabr.ru/users/vedenin1980/topics/) 12 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | Contribution Guidelines 2 | 3 | Please ensure your pull request follows the following guidelines: 4 | 5 | 1. Please make an individual pull request for each suggestion. 6 | 2. Use the following format for libraries: [LIBRARY](LINK) - DESCRIPTION. 7 | 3. New categories, or any improvements to the existing categorization are welcome. 8 | 9 | Thank you for your suggestions! 10 | -------------------------------------------------------------------------------- /hello world: -------------------------------------------------------------------------------- 1 | class Test 2 | { 3 | // Your program begins with a call to main(). 4 | // Prints "Hello World" to the terminal window in Java. 5 | public static void main(String args[]) 6 | { 7 | System.out.println("Hello World!"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /helloooo world: -------------------------------------------------------------------------------- 1 | /* This is a simple Java program. 2 | FileName : "HelloWorld.java". */ 3 | class HelloWorld 4 | { 5 | // Your program begins with a call to main(). 6 | // Prints "Hello, World" to the terminal window. 7 | public static void main(String args[]) 8 | { 9 | System.out.println("Hello, World"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheBidiMap.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.BidiMap; 2 | import org.apache.commons.collections4.bidimap.DualHashBidiMap; 3 | 4 | /** 5 | * Hello World using Apache BidiMap 6 | */ 7 | public class ApacheBidiMap { 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 Multiset 15 | BidiMap biMap = new DualHashBidiMap(); 16 | // Create Polish-English dictionary 17 | int i = 0; 18 | for(String englishWord: englishWords) { 19 | biMap.put(englishWord, russianWords[i]); 20 | i++; 21 | } 22 | 23 | // Print count words 24 | System.out.println(biMap); // Print "{ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}" - in random orders 25 | // Print unique words 26 | System.out.println(biMap.keySet()); // print "[ball, snow, one, two, three]"- in random orders 27 | System.out.println(biMap.values()); // print "[kula, snieg, jeden, dwa, trzy]" - in random orders 28 | 29 | // Print translate by words 30 | System.out.println("one = " + biMap.get("one")); // print one = jeden 31 | System.out.println("two = " + biMap.get("two")); // print two = dwa 32 | System.out.println("kula = " + biMap.getKey("kula")); // print kula = ball 33 | System.out.println("snieg = " + biMap.getKey("snieg")); // print snieg = snow 34 | System.out.println("empty = " + biMap.get("empty")); // print empty = null 35 | 36 | // Print count word's pair 37 | System.out.println(biMap.size()); //print 5 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheHashBag.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.HashBag; 3 | 4 | import java.util.Arrays; 5 | 6 | /** 7 | * Hello World using Apache HashBag 8 | */ 9 | public class ApacheHashBag { 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 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheMultiValueMap.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.MultiMap; 2 | import org.apache.commons.collections4.map.MultiValueMap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class ApacheMultiValueMap { 8 | 9 | // Task: parser string with text and show all indexes of all words 10 | public static void main(String[] args) { 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 Multimap 15 | MultiMap multiMap = new MultiValueMap(); 16 | 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - in random orders 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print null 36 | 37 | // Print count unique words 38 | System.out.println(multiMap.keySet().size()); //print 4 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheMultiValueMapLinked.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.MultiMap; 2 | import org.apache.commons.collections4.map.MultiValueMap; 3 | 4 | import java.util.*; 5 | 6 | public class ApacheMultiValueMapLinked { 7 | 8 | // Task: parser string with text and show all indexes of all words 9 | public static void main(String[] args) { 10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 11 | // Parse text to words and index 12 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 13 | // Create Multimap 14 | MultiMap multiMap = MultiValueMap.multiValueMap(new LinkedHashMap(), LinkedHashSet.class); 15 | 16 | // Fill Multimap 17 | int i = 0; 18 | for(String word: words) { 19 | multiMap.put(word, i); 20 | i++; 21 | } 22 | 23 | // Print all words 24 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]} - in predictable iteration order 25 | // Print all unique words 26 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi] - in predictable iteration order 27 | 28 | // Print all indexes 29 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 30 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 31 | System.out.println("All = " + multiMap.get("All!")); // print [3] 32 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 33 | System.out.println("Empty = " + multiMap.get("Empty")); // print null 34 | 35 | // Print count unique words 36 | System.out.println(multiMap.keySet().size()); //print 4 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheMultiValueMapTree.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.MultiMap; 2 | import org.apache.commons.collections4.map.MultiValueMap; 3 | 4 | import java.util.*; 5 | 6 | public class ApacheMultiValueMapTree { 7 | 8 | // Task: parser string with text and show all indexes of all words 9 | public static void main(String[] args) { 10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 11 | // Parse text to words and index 12 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 13 | // Create Multimap 14 | MultiMap multiMap = MultiValueMap.multiValueMap(new TreeMap(), TreeSet.class); 15 | 16 | // Fill Multimap 17 | int i = 0; 18 | for(String word: words) { 19 | multiMap.put(word, i); 20 | i++; 21 | } 22 | 23 | // Print all words 24 | System.out.println(multiMap); // print {All!=[3], Hello=[0, 2], Hi=[4], World!=[1, 5]} -in natural order 25 | // Print all unique words 26 | System.out.println(multiMap.keySet()); // print [All!, Hello, Hi, World!] in natural order 27 | 28 | // Print all indexes 29 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 30 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 31 | System.out.println("All = " + multiMap.get("All!")); // print [3] 32 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 33 | System.out.println("Empty = " + multiMap.get("Empty")); // print null 34 | 35 | // Print count unique words 36 | System.out.println(multiMap.keySet().size()); //print 4 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheSynchronizedBag.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.HashBag; 3 | import org.apache.commons.collections4.bag.SynchronizedBag; 4 | 5 | import java.util.Arrays; 6 | 7 | public class ApacheSynchronizedBag { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" ")))); 14 | 15 | // Print count words 16 | System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders 17 | // Print all unique words 18 | System.out.println(bag.uniqueSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2 22 | System.out.println("World = " + bag.getCount("World!")); // print 2 23 | System.out.println("All = " + bag.getCount("All!")); // print 1 24 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1 25 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(bag.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(bag.uniqueSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheSynchronizedSortedBag.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.SynchronizedSortedBag; 3 | import org.apache.commons.collections4.bag.TreeBag; 4 | 5 | import java.util.Arrays; 6 | 7 | public class ApacheSynchronizedSortedBag { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(" ")))); 14 | 15 | // Print count words 16 | System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order 17 | // Print all unique words 18 | System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order 19 | 20 | 21 | // Print count occurrences of words 22 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2 23 | System.out.println("World = " + bag.getCount("World!")); // print 2 24 | System.out.println("All = " + bag.getCount("All!")); // print 1 25 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1 26 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0 27 | 28 | // Print count all words 29 | System.out.println(bag.size()); //print 6 30 | 31 | // Print count unique words 32 | System.out.println(bag.uniqueSet().size()); //print 4 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/apache-commons-lib/src/ApacheTreeBag.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.TreeBag; 3 | 4 | import java.util.Arrays; 5 | 6 | public class ApacheTreeBag { 7 | 8 | public static void main(String[] args) { 9 | // Parse text to separate words 10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 11 | // Create Multiset 12 | Bag bag = new TreeBag(Arrays.asList(INPUT_TEXT.split(" "))); 13 | 14 | // Print count words 15 | System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order 16 | // Print all unique words 17 | System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order 18 | 19 | // Print count occurrences of words 20 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2 21 | System.out.println("World = " + bag.getCount("World!")); // print 2 22 | System.out.println("All = " + bag.getCount("All!")); // print 1 23 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1 24 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0 25 | 26 | // Print count all words 27 | System.out.println(bag.size()); //print 6 28 | 29 | // Print count unique words 30 | System.out.println(bag.uniqueSet().size()); //print 4 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaArrayListMultimap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.ArrayListMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaArrayListMultimap { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = ArrayListMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - keys in random orders, values in predictable iteration order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in random orders 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaBiMap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.BiMap; 2 | import com.google.common.collect.HashBiMap; 3 | 4 | 5 | // 6 | public class GuavaBiMap { 7 | 8 | // Task: create collection to translate Polish-English words in two ways 9 | public static void main(String[] args) { 10 | String[] englishWords = {"one", "two", "three","ball","snow"}; 11 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"}; 12 | 13 | // Create Multiset 14 | BiMap biMap = HashBiMap.create(englishWords.length); 15 | // Create English-Polish dictionary 16 | int i = 0; 17 | for(String englishWord: englishWords) { 18 | biMap.put(englishWord, russianWords[i]); 19 | i++; 20 | } 21 | 22 | // Print count words 23 | System.out.println(biMap); // print {two=dwa, three=trzy, snow=snieg, ball=kula, one=jeden} - in random orders 24 | // Print all unique words 25 | System.out.println(biMap.keySet()); // print [two, three, snow, ball, one] - in random orders 26 | System.out.println(biMap.values()); // print [dwa, trzy, snieg, kula, jeden]- in random orders 27 | 28 | // Print translate by words 29 | System.out.println("one = " + biMap.get("one")); // print one = jeden 30 | System.out.println("two = " + biMap.get("two")); // print two = dwa 31 | System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = ball 32 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = snow 33 | System.out.println("empty = " + biMap.get("empty")); // print empty = null 34 | 35 | // Print count word's pair 36 | System.out.println(biMap.size()); //print 5 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaConcurrentHashMultiset.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.ConcurrentHashMultiset; 2 | import com.google.common.collect.Multiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaConcurrentHashMultiset { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = ConcurrentHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [Hi, Hello x 2, World! x 2, All!] - in random orders 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaEnumHashBiMap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.BiMap; 2 | import com.google.common.collect.EnumHashBiMap; 3 | 4 | // 5 | public class GuavaEnumHashBiMap { 6 | enum ENGLISH_WORD { 7 | ONE, TWO, THREE, BALL, SNOW 8 | } 9 | 10 | // Task: create collection to translate Polish-English words in two ways 11 | public static void main(String[] args) { 12 | ENGLISH_WORD[] englishWords = ENGLISH_WORD.values(); 13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"}; 14 | 15 | // Create Multiset 16 | BiMap biMap = EnumHashBiMap.create(ENGLISH_WORD.class); 17 | // Create English-Polish dictionary 18 | int i = 0; 19 | for(ENGLISH_WORD englishWord: englishWords) { 20 | biMap.put(englishWord, russianWords[i]); 21 | i++; 22 | } 23 | 24 | // Print count words 25 | System.out.println(biMap); // print {ONE=jeden, TWO=dwa, THREE=trzy, BALL=kula, SNOW=snieg} 26 | // Print all unique words 27 | System.out.println(biMap.keySet()); // print [ONE, TWO, THREE, BALL, SNOW] 28 | System.out.println(biMap.values()); // print [jeden, dwa, trzy, kula, snieg] 29 | 30 | // Print translate by words 31 | System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE)); // print one = jeden 32 | System.out.println("two = " + biMap.get(ENGLISH_WORD.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 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaHashMultiMap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.HashMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaHashMultiMap { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = HashMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - keys and values in random orders 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaHashMultiset.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.HashMultiset; 2 | import com.google.common.collect.Multiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaHashMultiset { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = HashMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [Hi, Hello x 2, World! x 2, All!] - in random orders 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaLinkedHashMultimap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.LinkedHashMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaLinkedHashMultimap { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = LinkedHashMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in predictable iteration order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in predictable iteration order 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaLinkedHashMultiset.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.LinkedHashMultiset; 2 | import com.google.common.collect.Multiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaLinkedHashMultiset { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [Hello x 2, World! x 2, All!, Hi]- in predictable iteration order 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [Hello, World!, All!, Hi] - in predictable iteration order 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaLinkedListMultimap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.LinkedListMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaLinkedListMultimap { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = LinkedListMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in predictable iteration order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in predictable iteration order 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaTreeMultimap.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.Multimap; 2 | import com.google.common.collect.TreeMultimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaTreeMultimap { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = TreeMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in natural order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in natural order 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/guava-lib/src/GuavaTreeMultiset.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.Multiset; 2 | import com.google.common.collect.TreeMultiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaTreeMultiset { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = TreeMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [All!, Hello x 2, Hi, World! x 2]- in natural (alphabet) order 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | 1.1-common-frameworks-and-lib 9 | 0.01 10 | Common frameworks 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 | spring 28 | quasar 29 | apache-commons-lib 30 | guava-lib 31 | 32 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/quasar/src/main/java/FiberHelloWorld.java: -------------------------------------------------------------------------------- 1 | import co.paralleluniverse.fibers.Fiber; 2 | import co.paralleluniverse.fibers.SuspendExecution; 3 | 4 | import java.util.concurrent.ExecutionException; 5 | 6 | /** 7 | * Simple HelloWorld using Fiber 8 | * 9 | * To run using "maven test" 10 | * 11 | * Created by vvedenin on 4/11/2016. 12 | */ 13 | public class FiberHelloWorld { 14 | public static Integer doTest() throws ExecutionException, InterruptedException { 15 | System.out.println("Hello world1!"); 16 | Fiber integerFiber = new Fiber() { 17 | @Override 18 | protected Integer run() throws SuspendExecution, InterruptedException { 19 | System.out.println("Hello world2!"); 20 | return 10; 21 | } 22 | }.start(); 23 | System.out.println("Hello world3!"); 24 | return integerFiber.get(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/quasar/src/main/java/FiberSleepHelloWorld.java: -------------------------------------------------------------------------------- 1 | import co.paralleluniverse.fibers.Fiber; 2 | import co.paralleluniverse.fibers.SuspendExecution; 3 | 4 | import java.util.concurrent.ExecutionException; 5 | 6 | /** 7 | * Simple HelloWorld using Fiber and sleep 8 | * 9 | * To run using "maven test" 10 | * 11 | * Created by vvedenin on 4/11/2016. 12 | */ 13 | public class FiberSleepHelloWorld { 14 | public static Integer doTest() throws ExecutionException, InterruptedException { 15 | System.out.println("Hello world1!"); 16 | Fiber integerFiber = new Fiber() { 17 | @Override 18 | protected Integer run() throws SuspendExecution, InterruptedException { 19 | System.out.println("Hello world2!"); 20 | Fiber.sleep(1000); 21 | System.out.println("Hello world3!"); 22 | return 2; 23 | } 24 | }.start(); 25 | System.out.println("Hello world4!"); 26 | Integer result = integerFiber.get(); 27 | System.out.println("Hello world5!"); 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/quasar/src/test/java/HelloWordsTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import static org.hamcrest.CoreMatchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | /** 7 | * To run using "maven test" 8 | * 9 | * Created by vvedenin on 4/11/2016. 10 | */ 11 | public class HelloWordsTest { 12 | @Test 13 | public void test() throws Exception { 14 | System.out.println("FiberHelloWorld:"); 15 | assertThat(FiberHelloWorld.doTest(), is(10)); 16 | System.out.println("FiberSleepHelloWorld:"); 17 | assertThat(FiberSleepHelloWorld.doTest(), is(2)); 18 | System.out.println("FibersAndChanelHelloWorld:"); 19 | assertThat(FibersAndChanelHelloWorld.doTest(), is(10)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | spring 9 | 0.01 10 | Common frameworks :: 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 | 5.3.19 31 | 32 | 33 | 34 | org.springframework.security 35 | spring-security-web 36 | 5.7.13 37 | 38 | 39 | 40 | javax.inject 41 | javax.inject 42 | 1 43 | 44 | 45 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/resources/constructorAutowired.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/resources/constructorInject.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/resources/fieldAutowired.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/resources/setterAutowired.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/SpringConstructorAutowired.java: -------------------------------------------------------------------------------- 1 | import org.springframework.beans.factory.annotation.Autowired; 2 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * Constructor DI injection Hello World using Java annotation 8 | * 9 | * Created by vvedenin on 11/14/2015. 10 | */ 11 | public class SpringConstructorAutowired { 12 | public static class Notifier { 13 | private final NotificationService service; 14 | 15 | @Autowired 16 | public Notifier(NotificationService service) { 17 | this.service = service; 18 | } 19 | 20 | public void send(String message) { 21 | service.send("email: " + message); 22 | } 23 | } 24 | 25 | public static class EMailService implements NotificationService { 26 | public void send(String message) { 27 | System.out.println("I send " + message); 28 | } 29 | } 30 | 31 | public interface NotificationService { 32 | void send(String message); 33 | } 34 | 35 | @Configuration 36 | public static class DIConfiguration { 37 | @Bean 38 | public Notifier getNotifier(NotificationService service){ 39 | return new Notifier(service); 40 | } 41 | 42 | @Bean 43 | public NotificationService getNotificationService(){ 44 | return new EMailService(); 45 | } 46 | } 47 | 48 | public static void main(String[] args) throws Exception { 49 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class); 50 | Notifier notifier = context.getBean(Notifier.class); 51 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/SpringFieldAutowired.java: -------------------------------------------------------------------------------- 1 | import org.springframework.beans.factory.annotation.Autowired; 2 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * Field DI injection Hello World using Java annotation 8 | * 9 | * Created by vvedenin on 11/14/2015. 10 | */ 11 | public class SpringFieldAutowired { 12 | public static class Notifier { 13 | @Autowired 14 | private NotificationService service; 15 | 16 | public void send(String message) { 17 | service.send("email: " + message); 18 | } 19 | } 20 | 21 | public static class EMailService implements NotificationService { 22 | public void send(String message) { 23 | System.out.println("I send " + message); 24 | } 25 | } 26 | 27 | public interface NotificationService { 28 | void send(String message); 29 | } 30 | 31 | @Configuration 32 | public static class DIConfiguration { 33 | @Bean 34 | public Notifier getNotifier(NotificationService service){ 35 | return new Notifier(); 36 | } 37 | 38 | @Bean 39 | public NotificationService getNotificationService(){ 40 | return new EMailService(); 41 | } 42 | } 43 | 44 | public static void main(String[] args) throws Exception { 45 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class); 46 | Notifier notifier = context.getBean(Notifier.class); 47 | notifier.send("Hello World!"); // Print "I send email: Hello World!" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/SpringSetterAutowired.java: -------------------------------------------------------------------------------- 1 | import org.springframework.beans.factory.annotation.Autowired; 2 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * Setter DI injection Hello World using Java annotation 8 | * 9 | * Created by vvedenin on 11/14/2015. 10 | */ 11 | public class SpringSetterAutowired { 12 | public static class Notifier { 13 | private NotificationService service; 14 | 15 | @Autowired 16 | public void setService(NotificationService service) { 17 | this.service = service; 18 | } 19 | 20 | public void send(String message) { 21 | service.send("email: " + message); 22 | } 23 | } 24 | 25 | public static class EMailService implements NotificationService { 26 | public void send(String message) { 27 | System.out.println("I send " + message); 28 | } 29 | } 30 | 31 | public interface NotificationService { 32 | void send(String message); 33 | } 34 | 35 | @Configuration 36 | public static class DIConfiguration { 37 | @Bean 38 | public Notifier getNotifier(NotificationService service){ 39 | return new Notifier(); 40 | } 41 | 42 | @Bean 43 | public NotificationService getNotificationService(){ 44 | return new EMailService(); 45 | } 46 | } 47 | 48 | public static void main(String[] args) throws Exception { 49 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class); 50 | Notifier notifier = context.getBean(Notifier.class); 51 | notifier.send("Hello World!"); // Print "I send email: Hello World!" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/jsr330/SpringSimpleInject.java: -------------------------------------------------------------------------------- 1 | package jsr330; 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 | * Hello World using jsr330 annotation 12 | * 13 | * Created by vvedenin on 11/14/2015. 14 | */ 15 | public class SpringSimpleInject { 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 | @Configuration 40 | public static class DIConfiguration { 41 | @Bean 42 | public Notifier getNotifier(NotificationService service){ 43 | return new Notifier(service); 44 | } 45 | 46 | @Bean 47 | public NotificationService getNotificationService(){ 48 | return new EMailService(); 49 | } 50 | } 51 | 52 | public static void main(String[] args) throws Exception { 53 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class); 54 | Notifier notifier = context.getBean(Notifier.class); 55 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/xml/XmlConstructorAutowired.java: -------------------------------------------------------------------------------- 1 | package xml; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | /** 8 | * Constructor DI injection Hello World using XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlConstructorAutowired { 13 | public static class Notifier { 14 | private final NotificationService service; 15 | 16 | @Autowired 17 | public Notifier(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "constructorAutowired.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/xml/XmlFieldAutowired.java: -------------------------------------------------------------------------------- 1 | package xml; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | /** 8 | * Field DI injection Hello World using XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlFieldAutowired { 13 | public static class Notifier { 14 | @Autowired 15 | private NotificationService service; 16 | 17 | public void setService(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "fieldAutowired.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/xml/XmlSetterAutowired.java: -------------------------------------------------------------------------------- 1 | package xml; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | /** 8 | * Setter DI injection Hello World using XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlSetterAutowired { 13 | public static class Notifier { 14 | private NotificationService service; 15 | 16 | @Autowired 17 | public void setService(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "fieldAutowired.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.1-common-frameworks-and-lib/spring/src/xml/jsr330/XmlConstructorInject.java: -------------------------------------------------------------------------------- 1 | package xml.jsr330; 2 | 3 | import org.springframework.context.support.ClassPathXmlApplicationContext; 4 | 5 | import javax.inject.Inject; 6 | 7 | /** 8 | * Hello World using jsr330 annotation and XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlConstructorInject { 13 | public static class Notifier { 14 | private final NotificationService service; 15 | 16 | @Inject 17 | public Notifier(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "constructorInject.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/dozer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | dozer 9 | 0.01 10 | Bean mapping :: Dozer 11 | 12 | 13 | 14 | 15 | net.sf.dozer 16 | dozer 17 | 5.5.1 18 | 19 | 20 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/dozer/src/main/java/dozer/DozerHelloWorldAnnotation.java: -------------------------------------------------------------------------------- 1 | package dozer; 2 | 3 | import org.dozer.DozerBeanMapper; 4 | import org.dozer.Mapper; 5 | import org.dozer.Mapping; 6 | 7 | /** 8 | * Hello World that show simple annotation mapping 9 | * 10 | * Created by vedenin on 16.04.16. 11 | */ 12 | public class DozerHelloWorldAnnotation { 13 | public static class Source { 14 | private String message; 15 | 16 | public Source(String message) { 17 | this.message = message; 18 | } 19 | 20 | @Mapping("text") 21 | public String getMessage() { 22 | return message; 23 | } 24 | } 25 | 26 | public static class Destination { 27 | private String text; 28 | 29 | public String getText() { 30 | return text; 31 | } 32 | 33 | public void setText(String text) { 34 | this.text = text; 35 | } 36 | 37 | public void print() { 38 | System.out.println(text); 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | // init mapper 44 | Mapper mapper = new DozerBeanMapper(); 45 | 46 | // convert 47 | Source source = new Source("Hello World!"); 48 | Destination destObject = mapper.map(source, Destination.class); 49 | destObject.print(); // print Hello World! 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/dozer/src/main/java/dozer/DozerHelloWorldApi.java: -------------------------------------------------------------------------------- 1 | package dozer; 2 | 3 | import org.dozer.DozerBeanMapper; 4 | import org.dozer.loader.api.BeanMappingBuilder; 5 | 6 | import static org.dozer.loader.api.TypeMappingOptions.mapNull; 7 | 8 | /** 9 | * Hello World that show simple mapping using api 10 | * 11 | * Created by vedenin on 16.04.16. 12 | */ 13 | public class DozerHelloWorldApi { 14 | public static class Source { 15 | private String message; 16 | 17 | public Source(String message) { 18 | this.message = message; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | } 25 | 26 | public static class Destination { 27 | private String text; 28 | 29 | public String getText() { 30 | return text; 31 | } 32 | 33 | public void setText(String text) { 34 | this.text = text; 35 | } 36 | 37 | public void print() { 38 | System.out.println(text); 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | // init mapper 44 | BeanMappingBuilder builder = new BeanMappingBuilder() { 45 | protected void configure() { 46 | mapping(Source.class, Destination.class) 47 | .fields("message", "text"); 48 | } 49 | }; 50 | DozerBeanMapper mapper = new DozerBeanMapper(); 51 | mapper.addMapping(builder); 52 | 53 | // convert 54 | Source source = new Source("Hello World!"); 55 | Destination destObject = mapper.map(source, Destination.class); 56 | destObject.print(); // print Hello World! 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/dozer/src/main/java/dozer/DozerHelloWorldXML.java: -------------------------------------------------------------------------------- 1 | package dozer; 2 | 3 | import org.dozer.DozerBeanMapper; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Hello World that show simple xml mapping 10 | * 11 | * Created by vedenin on 16.04.16. 12 | */ 13 | public class DozerHelloWorldXML { 14 | public static class Source { 15 | private String message; 16 | 17 | public Source(String message) { 18 | this.message = message; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | } 25 | 26 | public static class Destination { 27 | private String text; 28 | 29 | public String getText() { 30 | return text; 31 | } 32 | 33 | public void setText(String text) { 34 | this.text = text; 35 | } 36 | 37 | public void print() { 38 | System.out.println(text); 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | new DozerHelloWorldXML().test(); 44 | } 45 | 46 | private void test() { 47 | // init mapper 48 | List myMappingFiles = new ArrayList(); 49 | myMappingFiles.add("mapping.xml"); 50 | DozerBeanMapper mapper = new DozerBeanMapper(); 51 | mapper.setMappingFiles(myMappingFiles); 52 | 53 | // convert 54 | Source source = new Source("Hello World!"); 55 | Destination destObject = mapper.map(source, Destination.class); 56 | destObject.print(); // print Hello World!; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/dozer/src/main/resources/mapping.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | dozer.DozerHelloWorldXML.Source 9 | dozer.DozerHelloWorldXML.Destination 10 | 11 | message 12 | text 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/mapstruct/src/main/java/mapstruct/MapStructHelloWorld.java: -------------------------------------------------------------------------------- 1 | package mapstruct; 2 | 3 | 4 | import org.mapstruct.Mapper; 5 | import org.mapstruct.Mapping; 6 | 7 | /** 8 | * Hello World that show simple annotation mapping 9 | * 10 | * Before run use maven install 11 | * Created by vedenin on 16.04.16. 12 | */ 13 | public class MapStructHelloWorld { 14 | public static class Source { 15 | private String message; 16 | 17 | public Source(String message) { 18 | this.message = message; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | } 25 | 26 | public static class Destination { 27 | private String text; 28 | 29 | public String getText() { 30 | return text; 31 | } 32 | 33 | public void setText(String text) { 34 | this.text = text; 35 | } 36 | 37 | public void print() { 38 | System.out.println(text); 39 | } 40 | } 41 | 42 | @Mapper 43 | public interface TestMapper { 44 | @Mapping(source = "message", target = "text") 45 | Destination sourceToDestination(Source source); 46 | } 47 | 48 | public static void main(String[] args) { 49 | // convert 50 | Source source = new Source("Hello World!"); 51 | Destination destObject = new TestMapperImpl().sourceToDestination(source); 52 | destObject.print(); // print Hello World! 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/modelmapper/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | modelmapper 9 | 0.01 10 | Bean mapping :: ModelMapper 11 | 12 | 13 | 14 | 15 | org.modelmapper 16 | modelmapper 17 | 0.7.5 18 | 19 | 20 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/modelmapper/src/main/java/modelmapper/ModelMapperHelloWorld.java: -------------------------------------------------------------------------------- 1 | package modelmapper; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.modelmapper.PropertyMap; 5 | 6 | /** 7 | * Hello World that show simple annotation mapping 8 | * 9 | * Created by vedenin on 16.04.16. 10 | */ 11 | public class ModelMapperHelloWorld { 12 | public static class Source { 13 | private String message; 14 | 15 | public Source(String message) { 16 | this.message = message; 17 | } 18 | 19 | public String getMessage() { 20 | return message; 21 | } 22 | } 23 | 24 | public static class Destination { 25 | private String text; 26 | 27 | public String getText() { 28 | return text; 29 | } 30 | 31 | public void setText(String text) { 32 | this.text = text; 33 | } 34 | 35 | public void print() { 36 | System.out.println(text); 37 | } 38 | } 39 | 40 | 41 | public static void main(String[] args) { 42 | // init mapper 43 | PropertyMap orderMap = new PropertyMap() { 44 | protected void configure() { 45 | map().setText(source.getMessage()); 46 | } 47 | }; 48 | ModelMapper modelMapper = new ModelMapper(); 49 | modelMapper.addMappings(orderMap); 50 | 51 | // convert 52 | Source source = new Source("Hello World!"); 53 | Destination destObject = modelMapper.map(source, Destination.class); 54 | destObject.print(); // print Hello World! 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/orika/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | orika 9 | 0.01 10 | Bean mapping :: Orika 11 | 12 | 13 | 14 | 15 | ma.glasnost.orika 16 | orika-core 17 | 1.4.2 18 | 19 | 20 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/orika/src/main/java/orika/OrikaHelloWorld.java: -------------------------------------------------------------------------------- 1 | package orika; 2 | 3 | import ma.glasnost.orika.MapperFacade; 4 | import ma.glasnost.orika.MapperFactory; 5 | import ma.glasnost.orika.impl.DefaultMapperFactory; 6 | 7 | 8 | /** 9 | * Hello World that show simple mapping 10 | * 11 | * Created by vedenin on 16.04.16. 12 | */ 13 | public class OrikaHelloWorld { 14 | public static class Source { 15 | private String message; 16 | 17 | public Source(String message) { 18 | this.message = message; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | } 25 | 26 | public static class Destination { 27 | private String text; 28 | 29 | public String getText() { 30 | return text; 31 | } 32 | 33 | public void setText(String text) { 34 | this.text = text; 35 | } 36 | 37 | public void print() { 38 | System.out.println(text); 39 | } 40 | } 41 | 42 | 43 | public static void main(String[] args) { 44 | // init mapper 45 | MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); 46 | mapperFactory.classMap(Source.class, Destination.class). 47 | field("message", "text").register(); 48 | MapperFacade mapper = mapperFactory.getMapperFacade(); 49 | 50 | // convert 51 | Source source = new Source("Hello World!"); 52 | Destination destObject = mapper.map(source, Destination.class); 53 | destObject.print(); // print Hello World! 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | bean_mapping 9 | 0.01 10 | Bean mapping 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 | dozer 29 | 30 | 31 | mapstruct 32 | 33 | 34 | modelmapper 35 | 36 | 37 | orika 38 | 39 | 40 | selma 41 | 42 | 43 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/selma/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | selma 9 | 0.01 10 | Bean mapping :: Selma 11 | 12 | 13 | 14 | 15 | 16 | fr.xebia.extras 17 | selma-processor 18 | 0.14 19 | provided 20 | 21 | 22 | 23 | 24 | fr.xebia.extras 25 | selma 26 | 0.14 27 | 28 | 29 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/selma/src/main/java/selma/SelmaHelloWorld.java: -------------------------------------------------------------------------------- 1 | package selma; 2 | 3 | import fr.xebia.extras.selma.Field; 4 | import fr.xebia.extras.selma.Mapper; 5 | import fr.xebia.extras.selma.Selma; 6 | 7 | 8 | /** 9 | * Hello World that show simple mapping 10 | * 11 | * Before run use maven install 12 | * 13 | * Created by vedenin on 16.04.16. 14 | */ 15 | public class SelmaHelloWorld { 16 | public static class Source { 17 | private String message; 18 | 19 | public Source(String message) { 20 | this.message = message; 21 | } 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | } 27 | 28 | public static class Destination { 29 | private String text; 30 | 31 | public String getText() { 32 | return text; 33 | } 34 | 35 | public void setText(String text) { 36 | this.text = text; 37 | } 38 | 39 | public void print() { 40 | System.out.println(text); 41 | } 42 | } 43 | 44 | public static void main(String[] args) { 45 | // init mapper 46 | TestMapper mapper = Selma.builder(TestMapper.class).build(); 47 | 48 | // convert 49 | Source source = new Source("Hello World!"); 50 | Destination destObject = mapper.sourceToDestination(source); 51 | destObject.print(); // print Hello World! 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/bean_mapping/selma/src/main/java/selma/TestMapper.java: -------------------------------------------------------------------------------- 1 | package selma; 2 | 3 | import fr.xebia.extras.selma.Field; 4 | import fr.xebia.extras.selma.Mapper; 5 | 6 | /** 7 | * Created by vedenin on 17.04.16. 8 | */ 9 | @Mapper( 10 | withCustomFields = { 11 | @Field({"message", "text"}) 12 | } 13 | ) 14 | public interface TestMapper { 15 | SelmaHelloWorld.Destination sourceToDestination(SelmaHelloWorld.Source source); 16 | } 17 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheBidiMapTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.BidiMap; 2 | import org.apache.commons.collections4.bidimap.DualHashBidiMap; 3 | 4 | /** 5 | * Hello World using Apache BidiMap 6 | */ 7 | public class ApacheBidiMapTest { 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 Multiset 15 | BidiMap biMap = new DualHashBidiMap(); 16 | // Create Polish-English dictionary 17 | int i = 0; 18 | for(String englishWord: englishWords) { 19 | biMap.put(englishWord, russianWords[i]); 20 | i++; 21 | } 22 | 23 | // Print count words 24 | System.out.println(biMap); // Print "{ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}" - in random orders 25 | // Print unique words 26 | System.out.println(biMap.keySet()); // print "[ball, snow, one, two, three]"- in random orders 27 | System.out.println(biMap.values()); // print "[kula, snieg, jeden, dwa, trzy]" - in random orders 28 | 29 | // Print translate by words 30 | System.out.println("one = " + biMap.get("one")); // print one = jeden 31 | System.out.println("two = " + biMap.get("two")); // print two = dwa 32 | System.out.println("kula = " + biMap.getKey("kula")); // print kula = ball 33 | System.out.println("snieg = " + biMap.getKey("snieg")); // print snieg = snow 34 | System.out.println("empty = " + biMap.get("empty")); // print empty = null 35 | 36 | // Print count word's pair 37 | System.out.println(biMap.size()); //print 5 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheHashBagTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.HashBag; 3 | 4 | import java.util.Arrays; 5 | 6 | /** 7 | * Hello World using Apache HashBag 8 | */ 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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheMultiValueMapLinkedTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.MultiMap; 2 | import org.apache.commons.collections4.map.MultiValueMap; 3 | 4 | import java.util.*; 5 | 6 | public class ApacheMultiValueMapLinkedTest { 7 | 8 | // Task: parser string with text and show all indexes of all words 9 | public static void main(String[] args) { 10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 11 | // Parse text to words and index 12 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 13 | // Create Multimap 14 | MultiMap multiMap = MultiValueMap.multiValueMap(new LinkedHashMap(), LinkedHashSet.class); 15 | 16 | // Fill Multimap 17 | int i = 0; 18 | for(String word: words) { 19 | multiMap.put(word, i); 20 | i++; 21 | } 22 | 23 | // Print all words 24 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]} - in predictable iteration order 25 | // Print all unique words 26 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi] - in predictable iteration order 27 | 28 | // Print all indexes 29 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 30 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 31 | System.out.println("All = " + multiMap.get("All!")); // print [3] 32 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 33 | System.out.println("Empty = " + multiMap.get("Empty")); // print null 34 | 35 | // Print count unique words 36 | System.out.println(multiMap.keySet().size()); //print 4 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheMultiValueMapTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.MultiMap; 2 | import org.apache.commons.collections4.map.MultiValueMap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class ApacheMultiValueMapTest { 8 | 9 | // Task: parser string with text and show all indexes of all words 10 | public static void main(String[] args) { 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 Multimap 15 | MultiMap multiMap = new MultiValueMap(); 16 | 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - in random orders 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print null 36 | 37 | // Print count unique words 38 | System.out.println(multiMap.keySet().size()); //print 4 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheMultiValueMapTreeTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.MultiMap; 2 | import org.apache.commons.collections4.map.MultiValueMap; 3 | 4 | import java.util.*; 5 | 6 | public class ApacheMultiValueMapTreeTest { 7 | 8 | // Task: parser string with text and show all indexes of all words 9 | public static void main(String[] args) { 10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 11 | // Parse text to words and index 12 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 13 | // Create Multimap 14 | MultiMap multiMap = MultiValueMap.multiValueMap(new TreeMap(), TreeSet.class); 15 | 16 | // Fill Multimap 17 | int i = 0; 18 | for(String word: words) { 19 | multiMap.put(word, i); 20 | i++; 21 | } 22 | 23 | // Print all words 24 | System.out.println(multiMap); // print {All!=[3], Hello=[0, 2], Hi=[4], World!=[1, 5]} -in natural order 25 | // Print all unique words 26 | System.out.println(multiMap.keySet()); // print [All!, Hello, Hi, World!] in natural order 27 | 28 | // Print all indexes 29 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 30 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 31 | System.out.println("All = " + multiMap.get("All!")); // print [3] 32 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 33 | System.out.println("Empty = " + multiMap.get("Empty")); // print null 34 | 35 | // Print count unique words 36 | System.out.println(multiMap.keySet().size()); //print 4 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheSynchronizedBagTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.HashBag; 3 | import org.apache.commons.collections4.bag.SynchronizedBag; 4 | 5 | import java.util.Arrays; 6 | 7 | public class ApacheSynchronizedBagTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" ")))); 14 | 15 | // Print count words 16 | System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders 17 | // Print all unique words 18 | System.out.println(bag.uniqueSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2 22 | System.out.println("World = " + bag.getCount("World!")); // print 2 23 | System.out.println("All = " + bag.getCount("All!")); // print 1 24 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1 25 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(bag.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(bag.uniqueSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheSynchronizedSortedBagTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.SynchronizedSortedBag; 3 | import org.apache.commons.collections4.bag.TreeBag; 4 | 5 | import java.util.Arrays; 6 | 7 | public class ApacheSynchronizedSortedBagTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(" ")))); 14 | 15 | // Print count words 16 | System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order 17 | // Print all unique words 18 | System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order 19 | 20 | 21 | // Print count occurrences of words 22 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2 23 | System.out.println("World = " + bag.getCount("World!")); // print 2 24 | System.out.println("All = " + bag.getCount("All!")); // print 1 25 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1 26 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0 27 | 28 | // Print count all words 29 | System.out.println(bag.size()); //print 6 30 | 31 | // Print count unique words 32 | System.out.println(bag.uniqueSet().size()); //print 4 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/apache-commons/src/ApacheTreeBagTest.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.collections4.Bag; 2 | import org.apache.commons.collections4.bag.TreeBag; 3 | 4 | import java.util.Arrays; 5 | 6 | public class ApacheTreeBagTest { 7 | 8 | public static void main(String[] args) { 9 | // Parse text to separate words 10 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 11 | // Create Multiset 12 | Bag bag = new TreeBag(Arrays.asList(INPUT_TEXT.split(" "))); 13 | 14 | // Print count words 15 | System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order 16 | // Print all unique words 17 | System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order 18 | 19 | // Print count occurrences of words 20 | System.out.println("Hello = " + bag.getCount("Hello")); // print 2 21 | System.out.println("World = " + bag.getCount("World!")); // print 2 22 | System.out.println("All = " + bag.getCount("All!")); // print 1 23 | System.out.println("Hi = " + bag.getCount("Hi")); // print 1 24 | System.out.println("Empty = " + bag.getCount("Empty")); // print 0 25 | 26 | // Print count all words 27 | System.out.println(bag.size()); //print 6 28 | 29 | // Print count unique words 30 | System.out.println(bag.uniqueSet().size()); //print 4 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/gs-eclipse/src/GsFastListMultimapTest.java: -------------------------------------------------------------------------------- 1 | import com.gs.collections.api.multimap.list.MutableListMultimap; 2 | import com.gs.collections.impl.multimap.list.FastListMultimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GsFastListMultimapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | MutableListMultimap multiMap = new FastListMultimap(); 17 | 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 {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- in random orders 28 | // Print all unique words 29 | System.out.println(multiMap.keysView()); // print [Hi, Hello, World!, All!] - in random orders 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 [] 37 | 38 | // Print count all words 39 | System.out.println(multiMap.size()); //print 6 40 | 41 | // Print count all unique words 42 | System.out.println(multiMap.keysView().size()); //print 4 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/gs-eclipse/src/GsHashBagMultimapTest.java: -------------------------------------------------------------------------------- 1 | import com.gs.collections.api.multimap.bag.MutableBagMultimap; 2 | import com.gs.collections.impl.multimap.bag.HashBagMultimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GsHashBagMultimapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | MutableBagMultimap multiMap = new HashBagMultimap(); 17 | 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 {Hi=[4], World!=[1, 5], Hello=[0, 2], All!=[3]}- in random orders 28 | // Print all unique words 29 | System.out.println(multiMap.keysView()); // print [Hi, Hello, World!, All!] - in random orders 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 [] 37 | 38 | // Print count all words 39 | System.out.println(multiMap.size()); //print 6 40 | 41 | // Print count all unique words 42 | System.out.println(multiMap.keysView().size()); //print 4 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/gs-eclipse/src/GsHashBiMapTest.java: -------------------------------------------------------------------------------- 1 | import com.gs.collections.api.bimap.MutableBiMap; 2 | import com.gs.collections.impl.bimap.mutable.HashBiMap; 3 | 4 | // 5 | public class GsHashBiMapTest { 6 | 7 | // Task: create collection to translate Polish-English words in two ways 8 | public static void main(String[] args) { 9 | String[] englishWords = {"one", "two", "three","ball","snow"}; 10 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"}; 11 | 12 | // Create Multiset 13 | MutableBiMap biMap = new HashBiMap(englishWords.length); 14 | // Create English-Polish dictionary 15 | int i = 0; 16 | for(String englishWord: englishWords) { 17 | biMap.put(englishWord, russianWords[i]); 18 | i++; 19 | } 20 | 21 | // Print count words 22 | System.out.println(biMap); // print {two=dwa, ball=kula, one=jeden, snow=snieg, three=trzy} - in random orders 23 | // Print all unique words 24 | System.out.println(biMap.keySet()); // print [snow, two, one, three, ball] - in random orders 25 | System.out.println(biMap.values()); // print [dwa, kula, jeden, snieg, trzy] - in random orders 26 | 27 | // Print translate by words 28 | System.out.println("one = " + biMap.get("one")); // print one = jeden 29 | System.out.println("two = " + biMap.get("two")); // print two = dwa 30 | System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = ball 31 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = snow 32 | System.out.println("empty = " + biMap.get("empty")); // print empty = null 33 | 34 | // Print count word's pair 35 | System.out.println(biMap.size()); //print 5 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/gs-eclipse/src/GsMutableBagTest.java: -------------------------------------------------------------------------------- 1 | import com.gs.collections.api.bag.MutableBag; 2 | import com.gs.collections.impl.bag.mutable.HashBag; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GsMutableBagTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | MutableBag bag = HashBag.newBag(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(bag); // print [Hi, World!, World!, Hello, Hello, All!]- in random orders 17 | // Print all unique words 18 | System.out.println(bag.toSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + bag.occurrencesOf("Hello")); // print 2 22 | System.out.println("World = " + bag.occurrencesOf("World!")); // print 2 23 | System.out.println("All = " + bag.occurrencesOf("All!")); // print 1 24 | System.out.println("Hi = " + bag.occurrencesOf("Hi")); // print 1 25 | System.out.println("Empty = " + bag.occurrencesOf("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(bag.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(bag.toSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/gs-eclipse/src/GsMutableSortedBagTest.java: -------------------------------------------------------------------------------- 1 | import com.gs.collections.api.bag.sorted.MutableSortedBag; 2 | import com.gs.collections.impl.bag.sorted.mutable.TreeBag; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GsMutableSortedBagTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | MutableSortedBag bag = TreeBag.newBag(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(bag); // print [All!, Hello, Hello, Hi, World!, World!]- in natural order 17 | // Print all unique words 18 | System.out.println(bag.toSortedSet()); // print [All!, Hello, Hi, World!]- in natural order 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + bag.occurrencesOf("Hello")); // print 2 22 | System.out.println("World = " + bag.occurrencesOf("World!")); // print 2 23 | System.out.println("All = " + bag.occurrencesOf("All!")); // print 1 24 | System.out.println("Hi = " + bag.occurrencesOf("Hi")); // print 1 25 | System.out.println("Empty = " + bag.occurrencesOf("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(bag.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(bag.toSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaArrayListMultimapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.ArrayListMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaArrayListMultimapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = ArrayListMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - keys in random orders, values in predictable iteration order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in random orders 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaBiMapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.BiMap; 2 | import com.google.common.collect.HashBiMap; 3 | 4 | 5 | // 6 | public class GuavaBiMapTest { 7 | 8 | // Task: create collection to translate Polish-English words in two ways 9 | public static void main(String[] args) { 10 | String[] englishWords = {"one", "two", "three","ball","snow"}; 11 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"}; 12 | 13 | // Create Multiset 14 | BiMap biMap = HashBiMap.create(englishWords.length); 15 | // Create English-Polish dictionary 16 | int i = 0; 17 | for(String englishWord: englishWords) { 18 | biMap.put(englishWord, russianWords[i]); 19 | i++; 20 | } 21 | 22 | // Print count words 23 | System.out.println(biMap); // print {two=dwa, three=trzy, snow=snieg, ball=kula, one=jeden} - in random orders 24 | // Print all unique words 25 | System.out.println(biMap.keySet()); // print [two, three, snow, ball, one] - in random orders 26 | System.out.println(biMap.values()); // print [dwa, trzy, snieg, kula, jeden]- in random orders 27 | 28 | // Print translate by words 29 | System.out.println("one = " + biMap.get("one")); // print one = jeden 30 | System.out.println("two = " + biMap.get("two")); // print two = dwa 31 | System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = ball 32 | System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = snow 33 | System.out.println("empty = " + biMap.get("empty")); // print empty = null 34 | 35 | // Print count word's pair 36 | System.out.println(biMap.size()); //print 5 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaConcurrentHashMultisetTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.ConcurrentHashMultiset; 2 | import com.google.common.collect.Multiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaConcurrentHashMultisetTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = ConcurrentHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [Hi, Hello x 2, World! x 2, All!] - in random orders 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaEnumHashBiMapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.BiMap; 2 | import com.google.common.collect.EnumHashBiMap; 3 | 4 | // 5 | public class GuavaEnumHashBiMapTest { 6 | enum ENGLISH_WORD { 7 | ONE, TWO, THREE, BALL, SNOW 8 | } 9 | 10 | // Task: create collection to translate Polish-English words in two ways 11 | public static void main(String[] args) { 12 | ENGLISH_WORD[] englishWords = ENGLISH_WORD.values(); 13 | String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"}; 14 | 15 | // Create Multiset 16 | BiMap biMap = EnumHashBiMap.create(ENGLISH_WORD.class); 17 | // Create English-Polish dictionary 18 | int i = 0; 19 | for(ENGLISH_WORD englishWord: englishWords) { 20 | biMap.put(englishWord, russianWords[i]); 21 | i++; 22 | } 23 | 24 | // Print count words 25 | System.out.println(biMap); // print {ONE=jeden, TWO=dwa, THREE=trzy, BALL=kula, SNOW=snieg} 26 | // Print all unique words 27 | System.out.println(biMap.keySet()); // print [ONE, TWO, THREE, BALL, SNOW] 28 | System.out.println(biMap.values()); // print [jeden, dwa, trzy, kula, snieg] 29 | 30 | // Print translate by words 31 | System.out.println("one = " + biMap.get(ENGLISH_WORD.ONE)); // print one = jeden 32 | System.out.println("two = " + biMap.get(ENGLISH_WORD.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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaHashMultiMapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.HashMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaHashMultiMapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = HashMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hi=[4], Hello=[0, 2], World!=[1, 5], All!=[3]} - keys and values in random orders 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hi, Hello, World!, All!] - in random orders 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaHashMultisetTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.HashMultiset; 2 | import com.google.common.collect.Multiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaHashMultisetTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = HashMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [Hi, Hello x 2, World! x 2, All!] - in random orders 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [Hi, Hello, World!, All!] - in random orders 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaLinkedHashMultimapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.LinkedHashMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaLinkedHashMultimapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = LinkedHashMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in predictable iteration order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in predictable iteration order 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaLinkedHashMultisetTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.LinkedHashMultiset; 2 | import com.google.common.collect.Multiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaLinkedHashMultisetTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [Hello x 2, World! x 2, All!, Hi]- in predictable iteration order 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [Hello, World!, All!, Hi] - in predictable iteration order 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaLinkedListMultimapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.LinkedListMultimap; 2 | import com.google.common.collect.Multimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaLinkedListMultimapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = LinkedListMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in predictable iteration order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in predictable iteration order 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaTreeMultimapTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.Multimap; 2 | import com.google.common.collect.TreeMultimap; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // 8 | public class GuavaTreeMultimapTest { 9 | 10 | // Task: parser string with text and show all indexes of all words 11 | public static void main(String[] args) { 12 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 13 | // Parse text to words and index 14 | List words = Arrays.asList(INPUT_TEXT.split(" ")); 15 | // Create Multimap 16 | Multimap multiMap = TreeMultimap.create(); 17 | 18 | // Fill Multimap 19 | int i = 0; 20 | for(String word: words) { 21 | multiMap.put(word, i); 22 | i++; 23 | } 24 | 25 | // Print all words 26 | System.out.println(multiMap); // print {Hello=[0, 2], World!=[1, 5], All!=[3], Hi=[4]}-in natural order 27 | // Print all unique words 28 | System.out.println(multiMap.keySet()); // print [Hello, World!, All!, Hi]- in natural order 29 | 30 | // Print all indexes 31 | System.out.println("Hello = " + multiMap.get("Hello")); // print [0, 2] 32 | System.out.println("World = " + multiMap.get("World!")); // print [1, 5] 33 | System.out.println("All = " + multiMap.get("All!")); // print [3] 34 | System.out.println("Hi = " + multiMap.get("Hi")); // print [4] 35 | System.out.println("Empty = " + multiMap.get("Empty")); // print [] 36 | 37 | // Print count all words 38 | System.out.println(multiMap.size()); //print 6 39 | 40 | // Print count unique words 41 | System.out.println(multiMap.keySet().size()); //print 4 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/guava/src/GuavaTreeMultisetTest.java: -------------------------------------------------------------------------------- 1 | import com.google.common.collect.Multiset; 2 | import com.google.common.collect.TreeMultiset; 3 | 4 | import java.util.Arrays; 5 | 6 | // 7 | public class GuavaTreeMultisetTest { 8 | 9 | public static void main(String[] args) { 10 | // Parse text to separate words 11 | String INPUT_TEXT = "Hello World! Hello All! Hi World!"; 12 | // Create Multiset 13 | Multiset multiset = TreeMultiset.create(Arrays.asList(INPUT_TEXT.split(" "))); 14 | 15 | // Print count words 16 | System.out.println(multiset); // print [All!, Hello x 2, Hi, World! x 2]- in natural (alphabet) order 17 | // Print all unique words 18 | System.out.println(multiset.elementSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order 19 | 20 | // Print count occurrences of words 21 | System.out.println("Hello = " + multiset.count("Hello")); // print 2 22 | System.out.println("World = " + multiset.count("World!")); // print 2 23 | System.out.println("All = " + multiset.count("All!")); // print 1 24 | System.out.println("Hi = " + multiset.count("Hi")); // print 1 25 | System.out.println("Empty = " + multiset.count("Empty")); // print 0 26 | 27 | // Print count all words 28 | System.out.println(multiset.size()); //print 6 29 | 30 | // Print count unique words 31 | System.out.println(multiset.elementSet().size()); //print 4 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/collections/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | collections 9 | 0.01 10 | 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 | apache-commons 28 | gs-eclipse 29 | guava 30 | 31 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-dagger/src/dagger/SimpleDaggerDI.java: -------------------------------------------------------------------------------- 1 | package dagger; 2 | 3 | import javax.inject.Inject; 4 | 5 | /** 6 | * Simple Dagger DI Hello World 7 | * 8 | * 9 | * Created by vvedenin on 11/14/2015. 10 | */ 11 | public class SimpleDaggerDI { 12 | public static class Notifier { 13 | private final NotificationService service; 14 | 15 | @Inject 16 | public Notifier(NotificationService service) { 17 | this.service = service; 18 | } 19 | 20 | public void send(String message) { 21 | service.send("email: " + message); 22 | } 23 | } 24 | 25 | public static class EMailService implements NotificationService { 26 | public void send(String message) { 27 | System.out.println("I send " + message); 28 | } 29 | } 30 | 31 | public interface NotificationService { 32 | void send(String message); 33 | } 34 | 35 | @Module 36 | public static class TestModule { 37 | @Provides 38 | NotificationService provideNotificationService() { 39 | return new EMailService(); 40 | } 41 | 42 | @Provides Notifier provideNotifier(NotificationService service) { 43 | return new Notifier(service); 44 | } 45 | } 46 | 47 | @Component(modules = TestModule.class) 48 | interface TestComponent { 49 | Notifier getNotifier(); 50 | } 51 | 52 | public static void main(String[] args) throws Exception { 53 | TestComponent testComponent = DaggerSimpleDaggerDI_TestComponent.create(); 54 | Notifier notifier = testComponent.getNotifier(); 55 | notifier.send("Hello world!"); // Напечатает "I send email: Hello world!" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-guice/src/GuiceConstructor.java: -------------------------------------------------------------------------------- 1 | import com.google.inject.AbstractModule; 2 | import com.google.inject.Guice; 3 | import com.google.inject.Injector; 4 | 5 | import javax.inject.Inject; 6 | 7 | /** 8 | * Guice Constructor DI Hello World 9 | * 10 | * 11 | * Created by vvedenin on 11/14/2015. 12 | */ 13 | public class GuiceConstructor { 14 | public static class Notifier { 15 | private final NotificationService service; 16 | 17 | @Inject 18 | public Notifier(NotificationService service) { 19 | this.service = service; 20 | } 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 | 38 | public static class TestModule extends AbstractModule { 39 | @Override 40 | protected void configure() { 41 | bind(NotificationService.class).to(EMailService.class); 42 | } 43 | } 44 | 45 | public static void main(String[] args) throws Exception { 46 | Injector injector = Guice.createInjector(new TestModule()); 47 | Notifier notifier = injector.getInstance(Notifier.class); 48 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-guice/src/GuiceFieldInject.java: -------------------------------------------------------------------------------- 1 | import com.google.inject.AbstractModule; 2 | import com.google.inject.Guice; 3 | import com.google.inject.Injector; 4 | 5 | import javax.inject.Inject; 6 | 7 | /** 8 | * Guice Field Inject DI Hello World 9 | * 10 | * 11 | * Created by vvedenin on 11/14/2015. 12 | */ 13 | public class GuiceFieldInject { 14 | public static class Notifier { 15 | @Inject 16 | private NotificationService service; 17 | 18 | public void send(String message) { 19 | service.send("email: " + message); 20 | } 21 | } 22 | 23 | public static class EMailService implements NotificationService { 24 | public void send(String message) { 25 | System.out.println("I send " + message); 26 | } 27 | } 28 | 29 | public interface NotificationService { 30 | void send(String message); 31 | } 32 | 33 | 34 | public static class TestModule extends AbstractModule { 35 | @Override 36 | protected void configure() { 37 | bind(NotificationService.class).to(EMailService.class); 38 | } 39 | } 40 | 41 | public static void main(String[] args) throws Exception { 42 | Injector injector = Guice.createInjector(new TestModule()); 43 | Notifier notifier = injector.getInstance(Notifier.class); 44 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-guice/src/GuiceSetterInject.java: -------------------------------------------------------------------------------- 1 | import com.google.inject.AbstractModule; 2 | import com.google.inject.Guice; 3 | import com.google.inject.Injector; 4 | 5 | import javax.inject.Inject; 6 | 7 | /** 8 | * Guice Setter Inject DI Hello World 9 | * 10 | * 11 | * Created by vvedenin on 11/14/2015. 12 | */ 13 | public class GuiceSetterInject { 14 | public static class Notifier { 15 | private NotificationService service; 16 | 17 | @Inject 18 | public void setService(NotificationService service) { 19 | this.service = service; 20 | } 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 | 38 | public static class TestModule extends AbstractModule { 39 | @Override 40 | protected void configure() { 41 | bind(NotificationService.class).to(EMailService.class); 42 | } 43 | } 44 | 45 | public static void main(String[] args) throws Exception { 46 | Injector injector = Guice.createInjector(new TestModule()); 47 | Notifier notifier = injector.getInstance(Notifier.class); 48 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | dependency-injection-spring 9 | 0.01 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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/resources/constructorAutowired.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/resources/constructorInject.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/resources/fieldAutowired.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/resources/setterAutowired.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/src/SpringFieldAutowired.java: -------------------------------------------------------------------------------- 1 | import org.springframework.beans.factory.annotation.Autowired; 2 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * Field DI injection Hello World using Java annotation 8 | * 9 | * Created by vvedenin on 11/14/2015. 10 | */ 11 | public class SpringFieldAutowired { 12 | public static class Notifier { 13 | @Autowired 14 | private NotificationService service; 15 | 16 | public void send(String message) { 17 | service.send("email: " + message); 18 | } 19 | } 20 | 21 | public static class EMailService implements NotificationService { 22 | public void send(String message) { 23 | System.out.println("I send " + message); 24 | } 25 | } 26 | 27 | public interface NotificationService { 28 | void send(String message); 29 | } 30 | 31 | @Configuration 32 | public static class DIConfiguration { 33 | @Bean 34 | public Notifier getNotifier(NotificationService service){ 35 | return new Notifier(); 36 | } 37 | 38 | @Bean 39 | public NotificationService getNotificationService(){ 40 | return new EMailService(); 41 | } 42 | } 43 | 44 | public static void main(String[] args) throws Exception { 45 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DIConfiguration.class); 46 | Notifier notifier = context.getBean(Notifier.class); 47 | notifier.send("Hello World!"); // Print "I send email: Hello World!" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/src/xml/XmlConstructorAutowired.java: -------------------------------------------------------------------------------- 1 | package xml; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | /** 8 | * Constructor DI injection Hello World using XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlConstructorAutowired { 13 | public static class Notifier { 14 | private final NotificationService service; 15 | 16 | @Autowired 17 | public Notifier(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "constructorAutowired.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/src/xml/XmlFieldAutowired.java: -------------------------------------------------------------------------------- 1 | package xml; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | /** 8 | * Field DI injection Hello World using XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlFieldAutowired { 13 | public static class Notifier { 14 | @Autowired 15 | private NotificationService service; 16 | 17 | public void setService(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "fieldAutowired.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/src/xml/XmlSetterAutowired.java: -------------------------------------------------------------------------------- 1 | package xml; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | /** 8 | * Setter DI injection Hello World using XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlSetterAutowired { 13 | public static class Notifier { 14 | private NotificationService service; 15 | 16 | @Autowired 17 | public void setService(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "fieldAutowired.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/dependency-injection-spring/src/xml/jsr330/XmlConstructorInject.java: -------------------------------------------------------------------------------- 1 | package xml.jsr330; 2 | 3 | import org.springframework.context.support.ClassPathXmlApplicationContext; 4 | 5 | import javax.inject.Inject; 6 | 7 | /** 8 | * Hello World using jsr330 annotation and XML config 9 | * 10 | * Created by vvedenin on 11/14/2015. 11 | */ 12 | public class XmlConstructorInject { 13 | public static class Notifier { 14 | private final NotificationService service; 15 | 16 | @Inject 17 | public Notifier(NotificationService service) { 18 | this.service = service; 19 | } 20 | 21 | public void send(String message) { 22 | service.send("email: " + message); 23 | } 24 | } 25 | 26 | public static class EMailService implements NotificationService { 27 | public void send(String message) { 28 | System.out.println("I send " + message); 29 | } 30 | } 31 | 32 | public interface NotificationService { 33 | void send(String message); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 38 | "constructorInject.xml"); 39 | Notifier notifier = context.getBean(Notifier.class); 40 | notifier.send("Hello world!"); // Print "I send email: Hello world!" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/dependency_injection/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | dependency_injection 9 | 0.01 10 | 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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/cyclops_react/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | cyclops_react 9 | 0.01 10 | Functional programming :: Cyclops react 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.aol.simplereact 29 | cyclops-react 30 | 1.0.0-RC2.3 31 | 32 | 33 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/cyclops_react/src/main/java/cyclopsreact/CyclopsReactHelloWorld.java: -------------------------------------------------------------------------------- 1 | package cyclopsreact; 2 | 3 | import com.aol.cyclops.data.collections.extensions.standard.ListX; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * Hello World for CyclopsReact 12 | * 13 | * Created by vedenin on 16.04.16. 14 | */ 15 | public class CyclopsReactHelloWorld { 16 | public static class Person { 17 | private final int age; 18 | private final String name; 19 | 20 | public Person(String name, int age) { 21 | this.age = age; 22 | this.name = name; 23 | } 24 | 25 | public int getAge() { 26 | return age; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Hello world! My name is " + name +", and I am " + age + " years old!"; 36 | } 37 | } 38 | 39 | private void streamExample() { 40 | Map> map = Arrays.asList(new Person("Alisa", 10)) 41 | .stream() 42 | .collect(Collectors.groupingBy(Person::getAge)); 43 | System.out.println(map.get(10).get(0)); 44 | } 45 | 46 | private void cyclopsExample() { 47 | Map> map = ListX.of(new Person("Bella", 12)).groupBy(Person::getAge); 48 | System.out.println(map.get(12).get(0)); 49 | } 50 | 51 | public static void main(String[] args) { 52 | CyclopsReactHelloWorld cls = new CyclopsReactHelloWorld(); 53 | cls.streamExample(); 54 | cls.cyclopsExample(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/javaslang/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | javaslang 9 | 0.01 10 | Functional programming :: Javaslang 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 | io.javaslang 29 | javaslang 30 | 2.0.1 31 | 32 | 33 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/jdk_stream_api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vedenin 8 | jdk_stream_api 9 | 0.01 10 | Functional programming :: JDK 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.aol.simplereact 29 | cyclops-react 30 | 1.0.0-RC2.3 31 | 32 | 33 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/jdk_stream_api/src/main/java/streamapi/DistinctTests.java: -------------------------------------------------------------------------------- 1 | package streamapi; 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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/jdk_stream_api/src/main/java/streamapi/LimitAndSkipTests.java: -------------------------------------------------------------------------------- 1 | package streamapi; 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 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/functional_programming/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | functional_programming 9 | 0.01 10 | Functional programming 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 | cyclops_react 28 | jdk_stream_api 29 | javaslang 30 | 31 | -------------------------------------------------------------------------------- /helloworlds/1.6-usefull-libraries/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | 1.6-usefull-libraries 9 | 0.01 10 | Usefull libraries 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 | collections 28 | dependency_injection 29 | bean_mapping 30 | functional_programming 31 | 32 | -------------------------------------------------------------------------------- /helloworlds/2.8-machine-learning/deeplearning4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | deeplearning4j 9 | 0.01 10 | Machine Learning :: Deeplearning4j 11 | 12 | 13 | 0.4-rc3.8 14 | 0.4-rc3.8 15 | 0.0.0.14 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 3.1 24 | 25 | 1.8 26 | 1.8 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.deeplearning4j 35 | deeplearning4j-core 36 | ${dl4j.version} 37 | 38 | 39 | 40 | org.nd4j 41 | nd4j-x86 42 | ${nd4j.version} 43 | 44 | 45 | 46 | canova-api 47 | org.nd4j 48 | ${canova.version} 49 | 50 | 51 | -------------------------------------------------------------------------------- /helloworlds/2.8-machine-learning/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | 2.8-machine-learning 9 | 0.01 10 | 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 | smile 28 | deeplearning4j 29 | 30 | -------------------------------------------------------------------------------- /helloworlds/2.8-machine-learning/smile/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | smile 9 | 0.01 10 | Machine Learning :: Smile 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.github.haifengl 29 | smile-core 30 | 1.1.0 31 | 32 | 33 | -------------------------------------------------------------------------------- /helloworlds/2.8-machine-learning/smile/resources/weather.nominal.arff: -------------------------------------------------------------------------------- 1 | @relation weather.symbolic 2 | 3 | @attribute outlook {sunny, overcast, rainy} 4 | @attribute temperature {hot, mild, cool} 5 | @attribute humidity {high, normal} 6 | @attribute windy {TRUE, FALSE} 7 | @attribute play {yes, no} 8 | 9 | @data 10 | sunny,hot,high,FALSE,no 11 | sunny,hot,high,TRUE,no 12 | overcast,hot,high,FALSE,yes 13 | rainy,mild,high,FALSE,yes 14 | rainy,cool,normal,FALSE,yes 15 | rainy,cool,normal,TRUE,no 16 | overcast,cool,normal,TRUE,yes 17 | sunny,mild,high,FALSE,no 18 | sunny,cool,normal,FALSE,yes 19 | rainy,mild,normal,FALSE,yes 20 | sunny,mild,normal,TRUE,yes 21 | overcast,mild,high,TRUE,yes 22 | overcast,hot,normal,FALSE,yes 23 | rainy,mild,high,TRUE,no 24 | -------------------------------------------------------------------------------- /helloworlds/2.8-machine-learning/smile/src/SmileHelloWorld.java: -------------------------------------------------------------------------------- 1 | import smile.data.AttributeDataset; 2 | import smile.data.Datum; 3 | import smile.data.parser.ArffParser; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * Created by vedenin on 09.04.16. 9 | */ 10 | public class SmileHelloWorld { 11 | 12 | public static void main(String[] args) throws Exception { 13 | SmileHelloWorld cls = new SmileHelloWorld(); 14 | cls.LoadArff(); 15 | } 16 | 17 | private void LoadArff() throws Exception { 18 | ArffParser arffParser = new ArffParser(); 19 | arffParser.setResponseIndex(4); 20 | AttributeDataset weather = arffParser.parse(this.getClass().getResourceAsStream("weather.nominal.arff")); 21 | println("name" + weather.getName()); 22 | println("responce " + weather.response()); 23 | println("attributes = " + Arrays.toString(weather.attributes())); 24 | println("Data: "); 25 | println(" x : y : weight"); 26 | weather.forEach((x) -> println(Arrays.toString(x.x) + " : " + x.y + " : " + x.weight)); 27 | } 28 | 29 | private static void println(String text) { 30 | System.out.println(text); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /helloworlds/2.8-natural-language-processing/opennlp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.github.vedenin 5 | 0.01 6 | 4.0.0 7 | 8 | open-nlp 9 | Natural language processing :: OpenNLP 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.apache.opennlp 28 | opennlp-tools 29 | 1.8.2 30 | 31 | 32 | org.apache.opennlp 33 | opennlp-uima 34 | 1.6.0 35 | 36 | 37 | -------------------------------------------------------------------------------- /helloworlds/2.8-natural-language-processing/opennlp/src/main/resources/en-sent.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/helloworlds/2.8-natural-language-processing/opennlp/src/main/resources/en-sent.bin -------------------------------------------------------------------------------- /helloworlds/2.8-natural-language-processing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | pom 6 | com.github.vedenin 7 | 2.8-natural-language-processing 8 | Natural language processing 9 | 10 | 0.01 11 | 12 | opennlp 13 | stanford-core-nlp 14 | 15 | 4.0.0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /helloworlds/2.8-natural-language-processing/stanford-core-nlp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 2.8-natural-language-processing 7 | com.github.vedenin 8 | 0.01 9 | 10 | 4.0.0 11 | stanford-core-nlp 12 | Natural language processing :: StanfordNLP 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 | 4.4.0 38 | models 39 | 40 | 41 | -------------------------------------------------------------------------------- /helloworlds/3.7-web-crawling-and-html-parser/Jsoup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | jsoup 9 | 0.01 10 | Web Crawling And HTML parser :: Jsoup 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.jsoup 29 | jsoup 30 | 1.15.3 31 | 32 | 33 | -------------------------------------------------------------------------------- /helloworlds/3.7-web-crawling-and-html-parser/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | pom 6 | 7 | com.github.vedenin 8 | 0.01 9 | 4.0.0 10 | 11 | 3.7-web-crawling-and-html-parser 12 | Web Crawling And HTML parser 13 | 14 | 15 | Jsoup 16 | 17 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/fastjson/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | fastjson 7 | Json :: fastjson 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.alibaba 14 | fastjson 15 | 1.2.83 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/fastjson/src/main/java/fastjson/FastJsonHelloWorld.java: -------------------------------------------------------------------------------- 1 | package fastjson; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | /** 6 | * FastJson Hello Place 7 | * 8 | */ 9 | public class FastJsonHelloWorld { 10 | 11 | public static void main(String[] args) { 12 | // init class 13 | Place place = new Place(); 14 | place.setName("World"); 15 | 16 | Human human = new Human(); 17 | human.setMessage("Hi"); 18 | human.setPlace(place); 19 | 20 | // convert to json 21 | String jsonString = JSON.toJSONString(human); 22 | System.out.println("json " + jsonString); // print "json {"message":"Hi","place":{"name":"World"}}" 23 | 24 | // convert from json 25 | Human newHuman = JSON.parseObject(jsonString, Human.class); 26 | newHuman.say(); // print "Hi , World!" 27 | } 28 | 29 | private static class Human { 30 | private String message; 31 | private Place place; 32 | 33 | public String getMessage() { 34 | return message; 35 | } 36 | 37 | public void setMessage(String message) { 38 | this.message = message; 39 | } 40 | 41 | public Place getPlace() { 42 | return place; 43 | } 44 | 45 | public void setPlace(Place place) { 46 | this.place = place; 47 | } 48 | 49 | public void say() { 50 | System.out.println(); 51 | System.out.println(getMessage() + " , " + getPlace().getName() + "!"); 52 | } 53 | } 54 | 55 | private static class Place { 56 | private String name; 57 | 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/genson/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | genson 7 | Json :: genson 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.owlike 14 | genson 15 | 1.4 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/gson/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | gson 7 | Json :: gson 8 | com.github.vedenin 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 | com.google.code.gson 28 | gson 29 | 2.8.9 30 | 31 | 32 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/gson/src/main/java/gson/GsonHelloWorld.java: -------------------------------------------------------------------------------- 1 | package gson; 2 | 3 | import com.google.gson.Gson; 4 | 5 | /** 6 | * Gson Hello World 7 | * 8 | */ 9 | public class GsonHelloWorld { 10 | 11 | public static void main(String[] args) { 12 | // init class 13 | Place place = new Place(); 14 | place.setName("World"); 15 | 16 | Human human = new Human(); 17 | human.setMessage("Hi"); 18 | human.setPlace(place); 19 | 20 | // convert to json 21 | Gson gson = new Gson(); 22 | String jsonString = gson.toJson(human); 23 | System.out.println("json " + jsonString); // print "json {"message":"Hi","place":{"name":"World"}}" 24 | 25 | // convert from json 26 | Human newHuman = gson.fromJson(jsonString, Human.class); 27 | newHuman.say(); // print "Hi , World!" 28 | } 29 | 30 | private static class Human { 31 | private String message; 32 | private Place place; 33 | 34 | public String getMessage() { 35 | return message; 36 | } 37 | 38 | public void setMessage(String message) { 39 | this.message = message; 40 | } 41 | 42 | public Place getPlace() { 43 | return place; 44 | } 45 | 46 | public void setPlace(Place place) { 47 | this.place = place; 48 | } 49 | 50 | public void say() { 51 | System.out.println(); 52 | System.out.println(getMessage() + " , " + getPlace().getName() + "!"); 53 | } 54 | } 55 | 56 | private static class Place { 57 | private String name; 58 | 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | public void setName(String name) { 64 | this.name = name; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/ig_json_parser/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | ig_json_parser 7 | Json :: IQ Json Parser 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.instagram 14 | ig-json-parser-processor 15 | 0.0.6 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/ig_json_parser/src/main/java/ig_json_parser/Human.java: -------------------------------------------------------------------------------- 1 | package ig_json_parser; 2 | 3 | import com.instagram.common.json.annotation.JsonField; 4 | import com.instagram.common.json.annotation.JsonType; 5 | 6 | /** 7 | * Created by vedenin on 22.04.16. 8 | */ 9 | @JsonType 10 | public class Human { 11 | @JsonField(fieldName="message") 12 | public String message; 13 | @JsonField(fieldName="place") 14 | public Place place; 15 | 16 | 17 | 18 | public void say() { 19 | System.out.println(); 20 | System.out.println(message + " , " + place.name + "!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/ig_json_parser/src/main/java/ig_json_parser/IgJsonParserHelloWorld.java: -------------------------------------------------------------------------------- 1 | package ig_json_parser; 2 | 3 | import com.instagram.common.json.annotation.JsonField; 4 | import com.instagram.common.json.annotation.JsonType; 5 | 6 | /** 7 | * Ig Json Parser Hello World 8 | * 9 | */ 10 | public class IgJsonParserHelloWorld { 11 | 12 | public static void main(String[] args) throws Exception { 13 | // init class 14 | Place place = new Place(); 15 | place.name = "World"; 16 | 17 | Human human = new Human(); 18 | human.message = "Hi"; 19 | human.place = place; 20 | 21 | // convert to json 22 | String jsonString = Human__JsonHelper.serializeToJson(human); 23 | System.out.println("json " + jsonString); //print "json {"place":{"name":"World"},"message":"Hi"}" 24 | 25 | // convert from json 26 | Human newHuman = Human__JsonHelper.parseFromJson(jsonString); 27 | newHuman.say(); // print "Hi , World!" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/ig_json_parser/src/main/java/ig_json_parser/Place.java: -------------------------------------------------------------------------------- 1 | package ig_json_parser; 2 | 3 | import com.instagram.common.json.annotation.JsonField; 4 | import com.instagram.common.json.annotation.JsonType; 5 | 6 | /** 7 | * Created by vedenin on 22.04.16. 8 | */ 9 | @JsonType 10 | public class Place { 11 | @JsonField(fieldName="name") 12 | public String name; 13 | } 14 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/jackson/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | jackson 7 | Json :: jackson 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.fasterxml.jackson.core 14 | jackson-core 15 | [2.10.0.pr1,) 16 | 17 | 18 | com.fasterxml.jackson.core 19 | jackson-databind 20 | [2.10.0.pr1,) 21 | 22 | 23 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | json_java 7 | Json :: json_java 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | org.json 14 | json 15 | 20160212 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_java/src/main/java/json_java/JsonJavaHelloWorld.java: -------------------------------------------------------------------------------- 1 | package json_java; 2 | 3 | import org.json.JSONObject; 4 | 5 | /** 6 | * Json-Java Hello World 7 | * 8 | */ 9 | public class JsonJavaHelloWorld { 10 | 11 | public static void main(String[] args) { 12 | // convert Java to json 13 | JSONObject root = new JSONObject(); 14 | root.put("message", "Hi"); 15 | JSONObject place = new JSONObject(); 16 | place.put("name", "World!"); 17 | root.put("place", place); 18 | String json = root.toString(); 19 | System.out.println(json); 20 | 21 | System.out.println(); 22 | // convert json to Java 23 | JSONObject jsonObject = new JSONObject(json); 24 | String message = jsonObject.getString("message"); 25 | String name = jsonObject.getJSONObject("place").getString("name"); 26 | System.out.println(message + " " + name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_path/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | json_path 7 | Json :: json_path 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.jayway.jsonpath 14 | json-path 15 | 2.2.0 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_schema_validator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | json_schema_validator 7 | Json :: Schema Validator 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.fasterxml.jackson.core 14 | jackson-core 15 | [2.11.1,) 16 | 17 | 18 | com.fasterxml.jackson.core 19 | jackson-databind 20 | [2.11.1,) 21 | 22 | 23 | com.github.fge 24 | json-schema-validator 25 | 2.2.6 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_schema_validator/src/main/java/json_schema_validator/JsonSchemaValidatorHelloWorld.java: -------------------------------------------------------------------------------- 1 | package json_schema_validator; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.github.fge.jsonschema.core.exceptions.ProcessingException; 5 | import com.github.fge.jsonschema.core.report.ProcessingReport; 6 | import com.github.fge.jsonschema.examples.Utils; 7 | import com.github.fge.jsonschema.main.JsonSchema; 8 | import com.github.fge.jsonschema.main.JsonSchemaFactory; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Json Schema Validator Hello World 14 | */ 15 | public class JsonSchemaValidatorHelloWorld { 16 | 17 | 18 | public static void main(final String... args) 19 | throws IOException, ProcessingException { 20 | final JsonNode fstabSchema = Utils.loadResource("/fstab.json"); 21 | final JsonNode good = Utils.loadResource("/fstab-good.json"); 22 | final JsonNode bad = Utils.loadResource("/fstab-bad.json"); 23 | final JsonNode bad2 = Utils.loadResource("/fstab-bad2.json"); 24 | 25 | final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); 26 | 27 | final JsonSchema schema = factory.getJsonSchema(fstabSchema); 28 | 29 | ProcessingReport report; 30 | 31 | report = schema.validate(good); 32 | System.out.println(report); 33 | 34 | report = schema.validate(bad); 35 | System.out.println(report); 36 | 37 | report = schema.validate(bad2); 38 | System.out.println(report); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_schema_validator/src/main/resources/fstab-bad.json: -------------------------------------------------------------------------------- 1 | { 2 | "/": { 3 | "fstype": "btrfs", 4 | "options": [ "ssd" ] 5 | }, 6 | "/tmp": { 7 | "device": "tmpfs", 8 | "fstype": "tmpfs", 9 | "options": [ "size=64M" ] 10 | }, 11 | "/var/lib/mysql": { 12 | "device": "/dev/data/mysql", 13 | "fstype": "btrfs" 14 | } 15 | } -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_schema_validator/src/main/resources/fstab-bad2.json: -------------------------------------------------------------------------------- 1 | { 2 | "/": { 3 | "device": "/dev/sda1", 4 | "options": [ "ssd" ] 5 | }, 6 | "swap": { 7 | "device": "/dev/sda2", 8 | "fstype": "swap" 9 | }, 10 | "/tmp": { 11 | "device": "tmpfs", 12 | "fstype": "tmpfs", 13 | "options": "size=64M" 14 | }, 15 | "/var/lib/mysql": { 16 | "device": "/dev/data/mysql", 17 | "fstype": "btrfs" 18 | } 19 | } -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_schema_validator/src/main/resources/fstab-good.json: -------------------------------------------------------------------------------- 1 | { 2 | "/": { 3 | "device": "/dev/sda1", 4 | "fstype": "btrfs", 5 | "options": [ "ssd" ] 6 | }, 7 | "swap": { 8 | "device": "/dev/sda2", 9 | "fstype": "swap" 10 | }, 11 | "/tmp": { 12 | "device": "tmpfs", 13 | "fstype": "tmpfs", 14 | "options": [ "size=64M" ] 15 | }, 16 | "/var/lib/mysql": { 17 | "device": "/dev/data/mysql", 18 | "fstype": "btrfs" 19 | } 20 | } -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_schema_validator/src/main/resources/fstab.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "title": "/etc/fstab", 4 | "description": "JSON representation of /etc/fstab", 5 | "type": "object", 6 | "properties": { 7 | "swap": { 8 | "$ref": "#/definitions/mntent" 9 | } 10 | }, 11 | "patternProperties": { 12 | "^/([^/]+(/[^/]+)*)?$": { 13 | "$ref": "#/definitions/mntent" 14 | } 15 | }, 16 | "required": [ "/", "swap" ], 17 | "additionalProperties": false, 18 | "definitions": { 19 | "mntent": { 20 | "title": "mntent", 21 | "description": "An fstab entry", 22 | "type": "object", 23 | "properties": { 24 | "device": { 25 | "type": "string" 26 | }, 27 | "fstype": { 28 | "type": "string" 29 | }, 30 | "options": { 31 | "type": "array", 32 | "minItems": 1, 33 | "items": { "type": "string" } 34 | }, 35 | "dump": { 36 | "type": "integer", 37 | "minimum": 0 38 | }, 39 | "fsck": { 40 | "type": "integer", 41 | "minimum": 0 42 | } 43 | }, 44 | "required": [ "device", "fstype" ], 45 | "additionalItems": false 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_simple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | json_simple 7 | Json :: json_simple 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.googlecode.json-simple 14 | json-simple 15 | 1.1.1 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/json_simple/src/main/java/json_simple/JsonSimpleHelloWorld.java: -------------------------------------------------------------------------------- 1 | package json_simple; 2 | 3 | 4 | import org.json.simple.JSONObject; 5 | import org.json.simple.JSONValue; 6 | 7 | /** 8 | * Json-Java Hello World 9 | */ 10 | public class JsonSimpleHelloWorld { 11 | 12 | public static void main(String[] args) { 13 | // convert Java to json 14 | JSONObject root = new JSONObject(); 15 | root.put("message", "Hi"); 16 | JSONObject place = new JSONObject(); 17 | place.put("name", "World!"); 18 | root.put("place", place); 19 | String json = root.toJSONString(); 20 | System.out.println(json); 21 | 22 | System.out.println(); 23 | // convert json to Java 24 | JSONObject obj = (JSONObject) JSONValue.parse(json); 25 | String message = (String) obj.get("message"); 26 | place = (JSONObject) obj.get("place"); 27 | String name = (String) place.get("name"); 28 | System.out.println(message + " " + name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/jsonschema2pojo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | jsonschema2pojo 7 | Json :: jsonschema2pojo 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | org.jsonschema2pojo 14 | jsonschema2pojo-core 15 | 0.4.22 16 | 17 | 18 | com.google.guava 19 | guava 20 | 29.0-jre 21 | 22 | 23 | 24 | 25 | 26 | 27 | org.jsonschema2pojo 28 | jsonschema2pojo-maven-plugin 29 | 0.4.22 30 | 31 | ${basedir}/src/main/resources 32 | com.github.vedenin 33 | 34 | 35 | 36 | 37 | generate 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/jsonschema2pojo/src/main/resources/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "type":"object", 3 | "properties": { 4 | "foo": { 5 | "type": "string" 6 | }, 7 | "bar": { 8 | "type": "integer" 9 | }, 10 | "baz": { 11 | "type": "boolean" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /helloworlds/3.8-json/logansquare/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | logansquare 7 | Json :: logansquare 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.bluelinelabs 14 | logansquare 15 | 1.3.7 16 | 17 | 18 | com.bluelinelabs 19 | logansquare-compiler 20 | 1.3.7 21 | 22 | 23 | com.squareup 24 | javapoet 25 | 1.6.1 26 | 27 | 28 | com.fasterxml.jackson.core 29 | jackson-core 30 | [2.10.0.pr1,) 31 | 32 | 33 | com.fasterxml.jackson.core 34 | jackson-databind 35 | [2.10.0.pr1,) 36 | 37 | 38 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/logansquare/src/main/java/logansquare/Human.java: -------------------------------------------------------------------------------- 1 | package logansquare; 2 | 3 | import com.bluelinelabs.logansquare.annotation.JsonField; 4 | import com.bluelinelabs.logansquare.annotation.JsonObject; 5 | 6 | /** 7 | * Created by vedenin on 22.04.16. 8 | */ 9 | @JsonObject 10 | public class Human { 11 | @JsonField(name="message") 12 | public String message; 13 | @JsonField(name="place") 14 | public Place place; 15 | 16 | 17 | 18 | public void say() { 19 | System.out.println(); 20 | System.out.println(message + " , " + place.name + "!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/logansquare/src/main/java/logansquare/LoganSquarenParserHelloWorld.java: -------------------------------------------------------------------------------- 1 | package logansquare; 2 | 3 | import com.bluelinelabs.logansquare.LoganSquare; 4 | 5 | /** 6 | * Ig Json Parser Hello World 7 | * 8 | */ 9 | public class LoganSquarenParserHelloWorld { 10 | 11 | public static void main(String[] args) throws Exception { 12 | // init class 13 | Place place = new Place(); 14 | place.name = "World"; 15 | 16 | Human human = new Human(); 17 | human.message = "Hi"; 18 | human.place = place; 19 | 20 | // convert to json 21 | String jsonString = LoganSquare.serialize(human); 22 | System.out.println("json " + jsonString); //print "json {"place":{"name":"World"},"message":"Hi"}" 23 | 24 | // convert from json 25 | Human newHuman = LoganSquare.parse(jsonString, Human.class); 26 | newHuman.say(); // print "Hi , World!" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/logansquare/src/main/java/logansquare/Place.java: -------------------------------------------------------------------------------- 1 | package logansquare; 2 | 3 | import com.bluelinelabs.logansquare.annotation.JsonField; 4 | import com.bluelinelabs.logansquare.annotation.JsonObject; 5 | 6 | /** 7 | * Created by vedenin on 22.04.16. 8 | */ 9 | @JsonObject 10 | public class Place { 11 | @JsonField(name="name") 12 | public String name; 13 | } 14 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/minimal-json/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | minimal-json 7 | Json :: minimal-json 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.eclipsesource.minimal-json 14 | minimal-json 15 | 0.9.4 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/minimal-json/src/main/java/minimal_json/JsonMinimalHelloWorld.java: -------------------------------------------------------------------------------- 1 | package minimal_json; 2 | 3 | 4 | import com.eclipsesource.json.Json; 5 | import com.eclipsesource.json.JsonObject; 6 | 7 | import java.io.IOException; 8 | import java.io.StringWriter; 9 | 10 | /** 11 | * Json-Java Hello World 12 | */ 13 | public class JsonMinimalHelloWorld { 14 | 15 | public static void main(String[] args) throws IOException { 16 | // convert Java to writer 17 | JsonObject root = Json.object().add("message", "Hi").add( 18 | "place", Json.object().add("name", "World!") 19 | ); 20 | StringWriter writer = new StringWriter(); 21 | root.writeTo(writer); 22 | String json = writer.toString(); 23 | System.out.println(json); 24 | 25 | System.out.println(); 26 | // convert writer to Java 27 | JsonObject obj = Json.parse(json).asObject(); 28 | String message = obj.get("message").asString(); 29 | String name = obj.get("place").asObject().get("name").asString(); 30 | System.out.println(message + " " + name); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/moshi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | moshi 7 | Json :: Moshi 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | com.squareup.moshi 14 | moshi 15 | 1.1.0 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworlds/3.8-json/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.vedenin 7 | 0.01 8 | pom 9 | Json 10 | 4.0.0 11 | 12 | 3.8-json 13 | 14 | 15 | gson 16 | fastjson 17 | json_java 18 | jsonschema2pojo 19 | moshi 20 | jackson 21 | json_path 22 | json_schema_validator 23 | genson 24 | logansquare 25 | json_simple 26 | minimal-json 27 | 28 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/cucumber/src/main/java/Belly.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Cucumber Hello World 3 | * 4 | * * To run using "maven test" 5 | */ 6 | public class Belly { 7 | public void eat(int cukes) { 8 | for(int i=0; i< cukes; i++ ){ 9 | System.out.println("I'm eating " + (i + 1) + " cuke"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/cucumber/src/test/java/HelloWorldTest.java: -------------------------------------------------------------------------------- 1 | import cucumber.api.CucumberOptions; 2 | import cucumber.api.junit.Cucumber; 3 | import org.junit.runner.RunWith; 4 | 5 | /** 6 | * To run using "maven test" 7 | */ 8 | @RunWith(Cucumber.class) 9 | @CucumberOptions(plugin = {"pretty"}) 10 | public class HelloWorldTest { 11 | } 12 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/cucumber/src/test/java/Stepdefs.java: -------------------------------------------------------------------------------- 1 | import cucumber.api.java.en.Given; 2 | import cucumber.api.java.en.Then; 3 | import cucumber.api.java.en.When; 4 | 5 | /** 6 | * To run using "maven test" 7 | */ 8 | public class Stepdefs { 9 | @Given("^I have (\\d+) cukes in my belly$") 10 | public void I_have_cukes_in_my_belly(int cukes) throws Throwable { 11 | Belly belly = new Belly(); 12 | belly.eat(cukes); 13 | } 14 | 15 | @When("^I wait (\\d+) seconds$") 16 | public void i_wait_hour(int arg1) throws Throwable { 17 | Thread.sleep(10000); 18 | } 19 | 20 | @Then("^my belly should growl$") 21 | public void my_belly_should_growl() throws Throwable { 22 | System.out.println("My belly growl"); 23 | } 24 | 25 | @Then("^I say Hello World!$") 26 | public void i_say_Hello_World() throws Throwable { 27 | System.out.println(); 28 | System.out.println("Hello World!"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/cucumber/src/test/resources/belly.feature: -------------------------------------------------------------------------------- 1 | Feature: Belly 2 | 3 | Scenario: a few cukes 4 | Given I have 42 cukes in my belly 5 | When I wait 10 seconds 6 | Then my belly should growl 7 | Then I say Hello World! -------------------------------------------------------------------------------- /helloworlds/4.1-testing/image-comparison/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.1-testing 7 | com.github.vedenin 8 | 0.01 9 | 10 | 4.0.0 11 | 12 | image-comparison 13 | 14 | This example to using Image-Comparison for testing code. 15 | 16 | 17 | 3.3 18 | 3.1.1 19 | 20 | 21 | 22 | 23 | com.github.romankh3 24 | image-comparison 25 | ${image.comparison.version} 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.apache.maven.plugins 33 | maven-compiler-plugin 34 | ${maven.compiler.version} 35 | 36 | UTF-8 37 | ${java.version} 38 | ${java.version} 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/image-comparison/src/main/resources/actual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/helloworlds/4.1-testing/image-comparison/src/main/resources/actual.png -------------------------------------------------------------------------------- /helloworlds/4.1-testing/image-comparison/src/main/resources/expected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/helloworlds/4.1-testing/image-comparison/src/main/resources/expected.png -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/main/java/Cashier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Calculate end cost on {@link Product}. 3 | * Performs operations with {@link Product} and {@link Client}. 4 | */ 5 | class Cashier { 6 | /** 7 | * Performs sale {@link Product}. 8 | * If {@link Client} cant buy {@link Product} report error in {@link Client}. 9 | * 10 | * @param client {@link Client} who want buy {@link Product}. 11 | * @param product {@link Product} which want buy {@link Client}. 12 | */ 13 | void toSell(Client client, Product product) { 14 | int cost = product.getCost(); 15 | if (checkBalanceClient(client, cost)) { 16 | client.withdraw(cost); 17 | client.addProduct(product); 18 | } else { 19 | client.addCodeError(CodeError.NOT_ENOUGH_FUNDS_BALANCE); 20 | System.out.println("toSell: Failed NOT_ENOUGH_FUNDS_BALANCE"); 21 | } 22 | } 23 | 24 | /** 25 | * Check paying capacity {@link Client}. 26 | * 27 | * @return false if {@link Client} cant buy {@link Product}. 28 | */ 29 | private boolean checkBalanceClient(Client client, int cost) { 30 | return client.haveAmountOnBalance(cost); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/main/java/Client.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | /** 5 | * Need for operations to buy. 6 | * Performs operations over balance. 7 | * If failed operations buy add {@link CodeError} in method {@link Client#addCodeError(CodeError)}. 8 | */ 9 | class Client { 10 | private int balance; 11 | private List codeErrors = new ArrayList<>(); 12 | private List products = new ArrayList<>(); 13 | 14 | Client(int balance) { 15 | this.balance = balance; 16 | } 17 | 18 | boolean haveAmountOnBalance(int amount) { 19 | return (balance >= amount); 20 | } 21 | 22 | int getBalance() { 23 | return balance; 24 | } 25 | 26 | void withdraw(int amount) { 27 | balance -= amount; 28 | } 29 | 30 | void addCodeError(CodeError codeError) { 31 | codeErrors.add(codeError); 32 | } 33 | 34 | List getCodeErrors() { 35 | return codeErrors; 36 | } 37 | 38 | void addProduct(Product product) { 39 | products.add(product); 40 | } 41 | 42 | List getProducts() { 43 | return products; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "Client{" + 49 | "balance=" + balance + 50 | ", codeErrors=" + codeErrors + 51 | ", products=" + products + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/main/java/CodeError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This enum for Code Error when buy. 3 | */ 4 | enum CodeError { 5 | NOT_ENOUGH_FUNDS_BALANCE 6 | } 7 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * This example to using Mockito for testing code. Example is in CashierTest. 5 | */ 6 | class Main { 7 | public static void main(String[] args) { 8 | sellMilkFailed(); 9 | } 10 | 11 | /** 12 | * This example {@link Client} to buy {@link Product} 13 | */ 14 | private static void sellMilk() { 15 | Product milk = new Product("Milk",150); 16 | Client client = new Client(300); 17 | Cashier cashier = new Cashier(); 18 | 19 | System.out.println(client.getProducts()); //[] 20 | cashier.toSell(client,milk); 21 | System.out.println(client.getProducts()); //[Product{name='Milk', cost=150}] 22 | } 23 | 24 | /** 25 | * This example {@link Client} can't to buy {@link Product} because not enough funds balance. 26 | */ 27 | private static void sellMilkFailed() { 28 | Product milk = new Product("Milk",150); 29 | Client client = new Client(100); 30 | Cashier cashier = new Cashier(); 31 | 32 | System.out.println(client.getProducts()); //[] 33 | cashier.toSell(client,milk); 34 | System.out.println(client.getProducts()); //[] 35 | System.out.println(client.getCodeErrors()); //[NOT_ENOUGH_FUNDS_BALANCE] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/main/java/Product.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This thing which sells store. 3 | */ 4 | class Product { 5 | private final String name; 6 | private final int cost; 7 | 8 | Product(String name, int cost) { 9 | this.name = name; 10 | this.cost = cost; 11 | } 12 | 13 | String getName() { 14 | return name; 15 | } 16 | 17 | int getCost() { 18 | return cost; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Product{" + 24 | "name='" + name + '\'' + 25 | ", cost=" + cost + 26 | '}'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/test/java/ClientTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import java.util.List; 4 | 5 | import static org.hamcrest.CoreMatchers.is; 6 | import static org.junit.Assert.*; 7 | 8 | public class ClientTest { 9 | 10 | private Client client = new Client(100); 11 | 12 | @Test 13 | public void testGetBalance() throws Exception { 14 | assertThat(client.getBalance(),is(100)); 15 | } 16 | 17 | @Test 18 | public void testHaveAmountOnBalance() throws Exception { 19 | assertFalse(client.haveAmountOnBalance(101)); 20 | assertTrue(client.haveAmountOnBalance(100)); 21 | assertTrue(client.haveAmountOnBalance(99)); 22 | } 23 | 24 | @Test 25 | public void testWithdraw() throws Exception { 26 | client.withdraw(30); 27 | assertThat(client.getBalance(),is(70)); 28 | } 29 | 30 | @Test 31 | public void testAddCodeError() throws Exception { 32 | final CodeError error = CodeError.NOT_ENOUGH_FUNDS_BALANCE; 33 | client.addCodeError(error); 34 | List codeErrors = client.getCodeErrors(); 35 | assertThat(codeErrors.size(),is(1)); 36 | assertThat(codeErrors.get(0),is(error)); 37 | } 38 | 39 | @Test 40 | public void testAddProduct() throws Exception { 41 | Product milk = new Product("Milk", 50); 42 | client.addProduct(milk); 43 | List products = client.getProducts(); 44 | assertThat(products.size(),is(1)); 45 | assertThat(products.get(0),is(milk)); 46 | } 47 | } -------------------------------------------------------------------------------- /helloworlds/4.1-testing/mockito/src/test/java/CreateMockWithAnnotation.java: -------------------------------------------------------------------------------- 1 | import org.junit.Before; 2 | import org.junit.Test; 3 | import org.junit.runner.RunWith; 4 | import org.mockito.Mock; 5 | import org.mockito.runners.MockitoJUnitRunner; 6 | 7 | import static org.mockito.Mockito.when; 8 | 9 | /** 10 | * This example create Mock with use Annotation. 11 | */ 12 | @RunWith(MockitoJUnitRunner.class) 13 | public class CreateMockWithAnnotation { 14 | 15 | private static int costMilk = 10; 16 | @Mock 17 | private Client client; 18 | @Mock 19 | private Product milk; 20 | 21 | @Before 22 | public void setUp() throws Exception { 23 | settingMockClient(true); 24 | settingMockMilk(); 25 | } 26 | 27 | @Test 28 | public void test() throws Exception { 29 | System.out.println(client); 30 | System.out.println(milk); 31 | } 32 | 33 | @SuppressWarnings("SameParameterValue") 34 | private void settingMockClient(boolean haveAmountOnBalance) { 35 | when(client.haveAmountOnBalance(costMilk)).thenReturn(haveAmountOnBalance); 36 | } 37 | 38 | private void settingMockMilk() { 39 | when(milk.getName()).thenReturn("Milk"); 40 | when(milk.getCost()).thenReturn(costMilk); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /helloworlds/4.1-testing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.vedenin 7 | 0.01 8 | pom 9 | Testing 10 | 4.0.0 11 | 12 | 4.1-testing 13 | 14 | 15 | cucumber 16 | mockito 17 | image-comparison 18 | 19 | -------------------------------------------------------------------------------- /helloworlds/9.9-template/library_name/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | library_name 7 | [Section_name] :: [library_name] 8 | com.github.vedenin 9 | 0.01 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /helloworlds/9.9-template/library_name/src/main/java/library_package/TemplateHelloWorld.java: -------------------------------------------------------------------------------- 1 | package library_package; 2 | 3 | /** 4 | * Template Hello World for this module 5 | * 6 | */ 7 | public class TemplateHelloWorld { 8 | 9 | public static void main(String[] args) { 10 | // HelloWorld example for this library or framework 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /helloworlds/9.9-template/library_name/src/main/java/library_package/advanced/AdvancedTemplate.java: -------------------------------------------------------------------------------- 1 | package library_package.advanced; 2 | 3 | /** 4 | * Template Hello World examples for this module (more complex then TemplateHelloWorld) 5 | * 6 | */ 7 | public class AdvancedTemplate { 8 | 9 | public static void main(String[] args) { 10 | // HelloWorld example for this library or framework 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /helloworlds/9.9-template/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.vedenin 7 | 0.01 8 | pom 9 | [Section_name] 10 | 4.0.0 11 | 12 | 9.9-template 13 | 14 | 15 | library_name 16 | 17 | -------------------------------------------------------------------------------- /helloworlds/contributing-russian.md: -------------------------------------------------------------------------------- 1 | Если хотите помочь проекту вы можете: 2 | 3 | 1. Добавлять новые ссылки на полезные библиотеки, 4 | 2. Добавлять новые примеры, шаблон примеров [тут](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/9.9-template), в качестве примера можно использовать [json](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json) раздел. Желательно, чтобы примеры можно было бы собрать только с помощью maven'a и запустить используя только Idea Community или Eclipse без дополнительных настроек. 5 | 3. Исправить ошибки в стилистике и грамматике русского и (особенно) английского языка, -------------------------------------------------------------------------------- /helloworlds/contributing.md: -------------------------------------------------------------------------------- 1 | Contribution Guidelines 2 | 3 | You can add any examples for any libraries. Template is [this](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/9.9-template). 4 | You can see [json sections](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json) for examples. 5 | Ideally, if you examples can be build using only maven, and running using only Idea Community or Eclipse. 6 | 7 | Thank you for any your suggestions! 8 | 9 | import java.lang.*; 10 | public class Calulator { 11 | double i; 12 | double x; 13 | void p(){ 14 | x = Math.sqrt(i); 15 | } 16 | } 17 | class Demonstration_81{ 18 | public static void main(String[] args){ 19 | Calulator a = new Calulator(); 20 | a.i = 20.0; 21 | a.p(); 22 | System.out.println("Square root of"+a.i+" is "+a.x); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /helloworlds/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | com.github.vedenin 8 | hellowords 9 | 0.01 10 | 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 | 1.1-common-frameworks-and-lib 29 | 1.6-usefull-libraries 30 | 2.8-machine-learning 31 | 2.8-natural-language-processing 32 | 3.7-web-crawling-and-html-parser 33 | 3.8-json 34 | 4.1-testing 35 | 5.0-other-examples 36 | 9.9-template 37 | 38 | -------------------------------------------------------------------------------- /img/business-friendly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/img/business-friendly.png -------------------------------------------------------------------------------- /img/impossible-proprietary-code-linking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/img/impossible-proprietary-code-linking.png -------------------------------------------------------------------------------- /img/proprietary-license.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/img/proprietary-license.png -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | [CC-BY-SA-4.0](https://creativecommons.org/licenses/by-sa/4.0/legalcode) 2 | -------------------------------------------------------------------------------- /link-rus/contributing.md: -------------------------------------------------------------------------------- 1 | Любые дополнения и изменения всячески приветствуются! 2 | 3 | Пожалуйста используйте несколько оформления pull request: 4 | 1. Для каждого предложения используйте отдельный pull request, 5 | 2. Ссылки оформляйте как `[Название](ссылка) Описание` как в русской, так и в английской версии, другую версия я могу обновить сам (или 6 | вы можете добавить изменения в обе версии сразу), 7 | 3. Исправления существующего разделения по категориям, добавления новых категорий всячески приветствуются, 8 | 9 | Заранее спасибо за любую помощь! 10 | -------------------------------------------------------------------------------- /link-rus/img/good-proprietary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/link-rus/img/good-proprietary.png -------------------------------------------------------------------------------- /link-rus/img/non-proprietary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/link-rus/img/non-proprietary.png -------------------------------------------------------------------------------- /link-rus/img/proprietary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vedenin/useful-java-links/7ede817ac8f8d1423c8a4905f4752551346859ea/link-rus/img/proprietary.png --------------------------------------------------------------------------------