Skip to content

Commit

Permalink
Merge branch 'master' into BAEL-2527
Browse files Browse the repository at this point in the history
  • Loading branch information
pcoates33 committed Feb 6, 2019
2 parents 0066ecf + 27422d0 commit 27e8c7f
Show file tree
Hide file tree
Showing 68 changed files with 539 additions and 9 deletions.
2 changes: 2 additions & 0 deletions algorithms-miscellaneous-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
- [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings)
- [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters)
- [Java Two Pointer Technique](https://www.baeldung.com/java-two-pointer-technique)
- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations)
- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine)
1 change: 1 addition & 0 deletions apache-spark/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### Relevant articles

- [Introduction to Apache Spark](http://www.baeldung.com/apache-spark)
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
1 change: 1 addition & 0 deletions core-java-11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- [Java 11 Single File Source Code](https://www.baeldung.com/java-single-file-source-code)
- [Java 11 Local Variable Syntax for Lambda Parameters](https://www.baeldung.com/java-var-lambda-params)
- [Java 11 String API Additions](https://www.baeldung.com/java-11-string-api)
- [Java 11 Nest Based Access Control](https://www.baeldung.com/java-nest-based-access-control)
1 change: 1 addition & 0 deletions core-java-9/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
- [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api)
- [Guide to java.lang.Process API](https://www.baeldung.com/java-process-api)
- [Immutable Set in Java](https://www.baeldung.com/java-immutable-set)
1 change: 1 addition & 0 deletions core-java-arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
- [Array Operations in Java](http://www.baeldung.com/java-common-array-operations)
- [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection)
- [Sorting Arrays in Java](https://www.baeldung.com/java-sorting-arrays)
- [Convert a Float to a Byte Array in Java](https://www.baeldung.com/java-convert-float-to-byte-array)
1 change: 1 addition & 0 deletions core-java-collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
- [A Guide to EnumMap](https://www.baeldung.com/java-enum-map)
- [A Guide to Iterator in Java](http://www.baeldung.com/java-iterator)
- [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences)
- [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector)
2 changes: 2 additions & 0 deletions core-java-io/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@
- [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension)
- [Getting a File’s Mime Type in Java](http://www.baeldung.com/java-file-mime-type)
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
- [How to Write to a CSV File in Java](https://www.baeldung.com/java-csv)
- [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files)
3 changes: 2 additions & 1 deletion core-java-lang-syntax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
- [Quick Guide to java.lang.System](http://www.baeldung.com/java-lang-system)
- [Java Switch Statement](https://www.baeldung.com/java-switch)
- [The Modulo Operator in Java](https://www.baeldung.com/modulo-java)
- [Ternary Operator In Java](https://www.baeldung.com/java-ternary-operator)
- [Ternary Operator In Java](https://www.baeldung.com/java-ternary-operator)
- [Java instanceof Operator](https://www.baeldung.com/java-instanceof)
8 changes: 7 additions & 1 deletion core-java-lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws)
- [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name)
- [Java Compound Operators](https://www.baeldung.com/java-compound-operators)
- [Guide to Java Packages](https://www.baeldung.com/java-packages)
- [Guide to Java Packages](https://www.baeldung.com/java-packages)
- [The Java Native Keyword and Methods](https://www.baeldung.com/java-native)
- [If-Else Statement in Java](https://www.baeldung.com/java-if-else)
- [Control Structures in Java](https://www.baeldung.com/java-control-structures)
- [Java Interfaces](https://www.baeldung.com/java-interfaces)
- [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values)
- [Variable Scope in Java](https://www.baeldung.com/java-variable-scope)
3 changes: 2 additions & 1 deletion core-java-perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- [Different Ways to Capture Java Heap Dumps](https://www.baeldung.com/java-heap-dump-capture)
- [Understanding Memory Leaks in Java](https://www.baeldung.com/java-memory-leaks)
- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded)
- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions)
- [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions)
- [Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring)
3 changes: 2 additions & 1 deletion core-java-security/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
- [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream)
- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
- [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures)
- [SHA-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
- [SHA-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
- [Enabling TLS v1.2 in Java 7](https://www.baeldung.com/java-7-tls-v12)
4 changes: 4 additions & 0 deletions core-java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@
- [Console I/O in Java](http://www.baeldung.com/java-console-input-output)
- [Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf)
- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields)
- [Introduction to Basic Syntax in Java](https://www.baeldung.com/java-syntax)
- [Using Curl in Java](https://www.baeldung.com/java-curl)
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
- [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators)
1 change: 1 addition & 0 deletions core-kotlin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@
- [Operator Overloading in Kotlin](https://www.baeldung.com/kotlin-operator-overloading)
- [Inline Classes in Kotlin](https://www.baeldung.com/kotlin-inline-classes)
- [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final)
- [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach)
2 changes: 1 addition & 1 deletion guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
<guice.version>4.1.0</guice.version>
</properties>

</project>
</project>
24 changes: 24 additions & 0 deletions guice/src/main/java/com/baeldung/examples/common/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.baeldung.examples.common;

public class Account {

private String accountNumber;
private String type;

public String getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public interface AccountService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public class AccountServiceImpl implements AccountService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public interface AudioBookService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public class AudioBookServiceImpl implements AudioBookService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public interface AuthorService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public class AuthorServiceImpl implements AuthorService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public interface BookService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.baeldung.examples.common;

public class BookServiceImpl implements BookService {

private AuthorService authorService;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public interface PersonDao {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.baeldung.examples.common;

public class PersonDaoImpl implements PersonDao {

}
4 changes: 4 additions & 0 deletions guice/src/main/java/com/baeldung/examples/guice/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.baeldung.examples.guice;

public class Foo {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.baeldung.examples.guice;

import com.google.inject.Inject;

public class FooProcessor {

@Inject
private Foo foo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.baeldung.examples.guice;

import com.baeldung.examples.common.PersonDao;
import com.google.inject.Inject;

public class GuicePersonService {

@Inject
private PersonDao personDao;

public PersonDao getPersonDao() {
return personDao;
}

public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.baeldung.examples.guice;

import com.baeldung.examples.common.AccountService;
import com.google.inject.Inject;

public class GuiceUserService {

@Inject
private AccountService accountService;

public AccountService getAccountService() {
return accountService;
}

public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}

}
24 changes: 24 additions & 0 deletions guice/src/main/java/com/baeldung/examples/guice/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.baeldung.examples.guice;

public class Person {
private String firstName;

private String lastName;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.baeldung.examples.guice.modules;

import com.baeldung.examples.common.AccountService;
import com.baeldung.examples.common.AccountServiceImpl;
import com.baeldung.examples.common.BookService;
import com.baeldung.examples.common.BookServiceImpl;
import com.baeldung.examples.common.PersonDao;
import com.baeldung.examples.common.PersonDaoImpl;
import com.baeldung.examples.guice.Foo;
import com.baeldung.examples.guice.Person;
import com.google.inject.AbstractModule;
import com.google.inject.Provider;
import com.google.inject.Provides;

public class GuiceModule extends AbstractModule {

@Override
protected void configure() {
try {
bind(AccountService.class).to(AccountServiceImpl.class);
bind(Person.class).toConstructor(Person.class.getConstructor());
// bind(Person.class).toProvider(new Provider<Person>() {
// public Person get() {
// Person p = new Person();
// return p;
// }
// });
bind(Foo.class).toProvider(new Provider<Foo>() {
public Foo get() {
return new Foo();
}
});
bind(PersonDao.class).to(PersonDaoImpl.class);

} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

@Provides
public BookService bookServiceGenerator() {
return new BookServiceImpl();
}

}
61 changes: 61 additions & 0 deletions guice/src/test/java/com/baeldung/examples/GuiceUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.baeldung.examples;

import static org.junit.Assert.assertNotNull;

import org.junit.Test;

import com.baeldung.examples.common.BookService;
import com.baeldung.examples.guice.FooProcessor;
import com.baeldung.examples.guice.GuicePersonService;
import com.baeldung.examples.guice.GuiceUserService;
import com.baeldung.examples.guice.Person;
import com.baeldung.examples.guice.modules.GuiceModule;
import com.google.inject.Guice;
import com.google.inject.Injector;

public class GuiceUnitTest {

@Test
public void givenAccountServiceInjectedInGuiceUserService_WhenGetAccountServiceInvoked_ThenReturnValueIsNotNull() {
Injector injector = Guice.createInjector(new GuiceModule());
GuiceUserService guiceUserService = injector.getInstance(GuiceUserService.class);
assertNotNull(guiceUserService.getAccountService());
}

@Test
public void givenBookServiceIsRegisteredInModule_WhenBookServiceIsInjected_ThenReturnValueIsNotNull() {
Injector injector = Guice.createInjector(new GuiceModule());
BookService bookService = injector.getInstance(BookService.class);
assertNotNull(bookService);
}

@Test
public void givenMultipleBindingsForPerson_WhenPersonIsInjected_ThenTestFailsByProvisionException() {
Injector injector = Guice.createInjector(new GuiceModule());
Person person = injector.getInstance(Person.class);
assertNotNull(person);
}

@Test
public void givenFooInjectedToFooProcessorAsOptionalDependency_WhenFooProcessorIsRetrievedFromContext_ThenCreationExceptionIsNotThrown() {
Injector injector = Guice.createInjector(new GuiceModule());
FooProcessor fooProcessor = injector.getInstance(FooProcessor.class);
assertNotNull(fooProcessor);
}

@Test
public void givenGuicePersonServiceConstructorAnnotatedByInject_WhenGuicePersonServiceIsInjected_ThenInstanceWillBeCreatedFromTheConstructor() {
Injector injector = Guice.createInjector(new GuiceModule());
GuicePersonService personService = injector.getInstance(GuicePersonService.class);
assertNotNull(personService);
}

@Test
public void givenPersonDaoInjectedToGuicePersonServiceBySetterInjection_WhenGuicePersonServiceIsInjected_ThenPersonDaoInitializedByTheSetter() {
Injector injector = Guice.createInjector(new GuiceModule());
GuicePersonService personService = injector.getInstance(GuicePersonService.class);
assertNotNull(personService);
assertNotNull(personService.getPersonDao());
}

}
1 change: 1 addition & 0 deletions jackson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Serialize Only Fields that meet a Custom Criteria with Jackson](http://www.baeldung.com/jackson-serialize-field-custom-criteria)
- [Mapping Nested Values with Jackson](http://www.baeldung.com/jackson-nested-values)
- [Convert XML to JSON Using Jackson](https://www.baeldung.com/jackson-convert-xml-json)
- [Deserialize Immutable Objects with Jackson](https://www.baeldung.com/jackson-deserialize-immutable-objects)
1 change: 1 addition & 0 deletions java-collections-maps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- [How to Check If a Key Exists in a Map](https://www.baeldung.com/java-map-key-exists)
- [Comparing Two HashMaps in Java](https://www.baeldung.com/java-compare-hashmaps)
- [Immutable Map Implementations in Java](https://www.baeldung.com/java-immutable-maps)
- [Map to String Conversion in Java](https://www.baeldung.com/java-map-to-string-conversion)
3 changes: 2 additions & 1 deletion java-dates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
- [Convert Between java.time.Instant and java.sql.Timestamp](https://www.baeldung.com/java-time-instant-to-java-sql-timestamp)
- [Convert between String and Timestamp](https://www.baeldung.com/java-string-to-timestamp)
- [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format)
- [ZoneOffset in Java](https://www.baeldung.com/java-zone-offset)
- [ZoneOffset in Java](https://www.baeldung.com/java-zone-offset)
- [Differences Between ZonedDateTime and OffsetDateTime](https://www.baeldung.com/java-zoneddatetime-offsetdatetime)
1 change: 1 addition & 0 deletions java-streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
- [Introduction to Protonpack](https://www.baeldung.com/java-protonpack)
- [Java Stream Filter with Lambda Expression](https://www.baeldung.com/java-stream-filter-lambda)
- [Counting Matches on a Stream Filter](https://www.baeldung.com/java-stream-filter-count)
- [Java 8 Streams peek() API](https://www.baeldung.com/java-streams-peek-api)
Loading

0 comments on commit 27e8c7f

Please sign in to comment.