Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
b94071b1af
@ -31,3 +31,6 @@
|
||||
- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
|
||||
- [Merge Sort in Java](https://www.baeldung.com/java-merge-sort)
|
||||
- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
|
||||
- [Quicksort Algorithm Implementation in Java](https://www.baeldung.com/java-quicksort)
|
||||
- [Insertion Sort in Java](https://www.baeldung.com/java-insertion-sort)
|
||||
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
|
||||
|
3
apache-geode/README.md
Normal file
3
apache-geode/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [A Quick Guide to Apache Geode](https://www.baeldung.com/apache-geode)
|
@ -38,3 +38,4 @@
|
||||
- [Time Complexity of Java Collections](https://www.baeldung.com/java-collections-complexity)
|
||||
- [Operating on and Removing an Item from Stream](https://www.baeldung.com/java-use-remove-item-stream)
|
||||
- [An Introduction to Synchronized Java Collections](https://www.baeldung.com/java-synchronized-collections)
|
||||
- [Guide to EnumSet](https://www.baeldung.com/java-enumset)
|
||||
|
@ -31,4 +31,5 @@
|
||||
- [Create a Symbolic Link with Java](http://www.baeldung.com/java-symlink)
|
||||
- [Quick Use of FilenameFilter](http://www.baeldung.com/java-filename-filter)
|
||||
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
|
||||
- [ Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist)
|
||||
- [Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist)
|
||||
- [Guide to Java OutputStream](https://www.baeldung.com/java-outputstream)
|
||||
|
@ -154,6 +154,12 @@
|
||||
<artifactId>async-http-client</artifactId>
|
||||
<version>${async-http-client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>${opencsv.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -247,7 +253,7 @@
|
||||
<protonpack.version>1.13</protonpack.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
|
||||
<opencsv.version>4.1</opencsv.version>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
|
@ -0,0 +1,106 @@
|
||||
package com.baeldung.csv;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.opencsv.CSVReader;
|
||||
|
||||
public class ReadCSVInArrayUnitTest {
|
||||
public static final String COMMA_DELIMITER = ",";
|
||||
public static final String CSV_FILE = "src/test/resources/book.csv";
|
||||
public static final List<List<String>> EXPECTED_ARRAY = Collections.unmodifiableList(new ArrayList<List<String>>() {
|
||||
{
|
||||
add(new ArrayList<String>() {
|
||||
{
|
||||
add("Mary Kom");
|
||||
add("Unbreakable");
|
||||
}
|
||||
});
|
||||
add(new ArrayList<String>() {
|
||||
{
|
||||
add("Kapil Isapuari");
|
||||
add("Farishta");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@Test
|
||||
public void givenCSVFile_whenBufferedReader_thenContentsAsExpected() throws IOException {
|
||||
List<List<String>> records = new ArrayList<List<String>>();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(CSV_FILE))) {
|
||||
String line = "";
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] values = line.split(COMMA_DELIMITER);
|
||||
records.add(Arrays.asList(values));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int i = 0; i < EXPECTED_ARRAY.size(); i++) {
|
||||
Assert.assertArrayEquals(EXPECTED_ARRAY.get(i)
|
||||
.toArray(),
|
||||
records.get(i)
|
||||
.toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCSVFile_whenScanner_thenContentsAsExpected() throws IOException {
|
||||
List<List<String>> records = new ArrayList<List<String>>();
|
||||
try (Scanner scanner = new Scanner(new File(CSV_FILE));) {
|
||||
while (scanner.hasNextLine()) {
|
||||
records.add(getRecordFromLine(scanner.nextLine()));
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int i = 0; i < EXPECTED_ARRAY.size(); i++) {
|
||||
Assert.assertArrayEquals(EXPECTED_ARRAY.get(i)
|
||||
.toArray(),
|
||||
records.get(i)
|
||||
.toArray());
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getRecordFromLine(String line) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
try (Scanner rowScanner = new Scanner(line)) {
|
||||
rowScanner.useDelimiter(COMMA_DELIMITER);
|
||||
while (rowScanner.hasNext()) {
|
||||
values.add(rowScanner.next());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCSVFile_whenOpencsv_thenContentsAsExpected() throws IOException {
|
||||
List<List<String>> records = new ArrayList<List<String>>();
|
||||
try (CSVReader csvReader = new CSVReader(new FileReader(CSV_FILE));) {
|
||||
String[] values = null;
|
||||
while ((values = csvReader.readNext()) != null) {
|
||||
records.add(Arrays.asList(values));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int i = 0; i < EXPECTED_ARRAY.size(); i++) {
|
||||
Assert.assertArrayEquals(EXPECTED_ARRAY.get(i)
|
||||
.toArray(),
|
||||
records.get(i)
|
||||
.toArray());
|
||||
}
|
||||
}
|
||||
}
|
2
core-java-io/src/test/resources/book.csv
Normal file
2
core-java-io/src/test/resources/book.csv
Normal file
@ -0,0 +1,2 @@
|
||||
Mary Kom,Unbreakable
|
||||
Kapil Isapuari,Farishta
|
|
@ -157,3 +157,4 @@
|
||||
- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
|
||||
- [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)
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class DoubleToString {
|
||||
|
||||
public static String truncateByCast(double d) {
|
||||
return String.valueOf((int) d);
|
||||
}
|
||||
|
||||
public static String roundWithStringFormat(double d) {
|
||||
return String.format("%.0f", d);
|
||||
}
|
||||
|
||||
public static String truncateWithNumberFormat(double d) {
|
||||
NumberFormat nf = NumberFormat.getInstance();
|
||||
nf.setMaximumFractionDigits(0);
|
||||
nf.setRoundingMode(RoundingMode.FLOOR);
|
||||
return nf.format(d);
|
||||
}
|
||||
|
||||
public static String roundWithNumberFormat(double d) {
|
||||
NumberFormat nf = NumberFormat.getInstance();
|
||||
nf.setMaximumFractionDigits(0);
|
||||
return nf.format(d);
|
||||
}
|
||||
|
||||
public static String truncateWithDecimalFormat(double d) {
|
||||
DecimalFormat df = new DecimalFormat("#,###");
|
||||
df.setRoundingMode(RoundingMode.FLOOR);
|
||||
return df.format(d);
|
||||
}
|
||||
|
||||
public static String roundWithDecimalFormat(double d) {
|
||||
DecimalFormat df = new DecimalFormat("#,###");
|
||||
return df.format(d);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoubleToStringUnitTest {
|
||||
|
||||
private static final double DOUBLE_VALUE = 3.56;
|
||||
private static final String TRUNCATED_DOUBLE = "3";
|
||||
private static final String ROUNDED_UP_DOUBLE = "4";
|
||||
|
||||
|
||||
@Test
|
||||
public void truncateByCastTest() {
|
||||
assertThat(DoubleToString.truncateByCast(DOUBLE_VALUE)).isEqualTo(TRUNCATED_DOUBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundingWithStringFormatTest() {
|
||||
assertThat(DoubleToString.roundWithStringFormat(DOUBLE_VALUE)).isEqualTo(ROUNDED_UP_DOUBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void truncateWithNumberFormatTest() {
|
||||
assertThat(DoubleToString.truncateWithNumberFormat(DOUBLE_VALUE)).isEqualTo(TRUNCATED_DOUBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundWithNumberFormatTest() {
|
||||
assertThat(DoubleToString.roundWithNumberFormat(DOUBLE_VALUE)).isEqualTo(ROUNDED_UP_DOUBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void truncateWithDecimalFormatTest() {
|
||||
assertThat(DoubleToString.truncateWithDecimalFormat(DOUBLE_VALUE)).isEqualTo(TRUNCATED_DOUBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundWithDecimalFormatTest() {
|
||||
assertThat(DoubleToString.roundWithDecimalFormat(DOUBLE_VALUE)).isEqualTo(ROUNDED_UP_DOUBLE);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -39,3 +39,4 @@
|
||||
- [Introduction to Kovenant Library for Kotlin](https://www.baeldung.com/kotlin-kovenant)
|
||||
- [Converting Kotlin Data Class from JSON using GSON](https://www.baeldung.com/kotlin-json-convert-data-class)
|
||||
- [Concatenate Strings in Kotlin](https://www.baeldung.com/kotlin-concatenate-strings)
|
||||
- [Kotlin return, break, continue Keywords](https://www.baeldung.com/kotlin-return-break-continue)
|
||||
|
@ -17,3 +17,4 @@
|
||||
- [Mapping A Hibernate Query to a Custom Class](https://www.baeldung.com/hibernate-query-to-custom-class)
|
||||
- [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column)
|
||||
- [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy)
|
||||
- [Proxy in Hibernate load() Method](https://www.baeldung.com/hibernate-proxy-load-method)
|
||||
|
@ -16,3 +16,4 @@
|
||||
- [Sort a HashMap in Java](https://www.baeldung.com/java-hashmap-sort)
|
||||
- [Finding the Highest Value in a Java Map](https://www.baeldung.com/java-find-map-max)
|
||||
- [Merging Two Maps with Java 8](https://www.baeldung.com/java-merge-maps)
|
||||
- [How to Check If a Key Exists in a Map](https://www.baeldung.com/java-map-key-exists)
|
||||
|
@ -21,4 +21,5 @@
|
||||
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)
|
||||
- [Calculate Age in Java](http://www.baeldung.com/java-get-age)
|
||||
- [Increment Date in Java](http://www.baeldung.com/java-increment-date)
|
||||
- [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date)
|
||||
- [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date)
|
||||
- [Guide to DateTimeFormatter](https://www.baeldung.com/java-datetimeformatter)
|
||||
|
@ -12,3 +12,4 @@
|
||||
- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger)
|
||||
- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum)
|
||||
- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double)
|
||||
- [Using Math.sin with Degrees](https://www.baeldung.com/java-math-sin-degrees)
|
||||
|
@ -1,3 +1,4 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Guide to ScribeJava](https://www.baeldung.com/scribejava)
|
||||
- [Guide to Passay](https://www.baeldung.com/java-passay)
|
||||
|
@ -1,3 +1,4 @@
|
||||
To run the maven-polyglot-json-app successfully, you first have to build the maven-polyglot-json-extension module using: mvn clean install.
|
||||
|
||||
Related Articles:
|
||||
### Relevant Articles:
|
||||
- [Maven Polyglot](https://www.baeldung.com/maven-polyglot)
|
||||
|
@ -10,3 +10,6 @@
|
||||
- [Build a Jar with Maven and Ignore the Test Results](http://www.baeldung.com/maven-ignore-test-results)
|
||||
- [Maven Project with Multiple Source Directories](https://www.baeldung.com/maven-project-multiple-src-directories)
|
||||
- [Integration Testing with Maven](https://www.baeldung.com/maven-integration-test)
|
||||
- [Apache Maven Standard Directory Layout](https://www.baeldung.com/maven-directory-structure)
|
||||
- [Apache Maven Tutorial](https://www.baeldung.com/maven)
|
||||
- [Use the Latest Version of a Dependency in Maven](https://www.baeldung.com/maven-dependency-latest-version)
|
||||
|
@ -11,3 +11,4 @@
|
||||
- [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial)
|
||||
- [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations)
|
||||
- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations)
|
||||
- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions )
|
||||
|
@ -8,4 +8,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Spring Boot Actuator](http://www.baeldung.com/spring-boot-actuators)
|
||||
- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive)
|
||||
- [Guide to Spring 5 WebFlux](http://www.baeldung.com/spring-webflux)
|
||||
|
||||
- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web)
|
||||
|
@ -7,4 +7,5 @@
|
||||
- [Spring Web Annotations](http://www.baeldung.com/spring-mvc-annotations)
|
||||
- [Spring Core Annotations](http://www.baeldung.com/spring-core-annotations)
|
||||
- [Display RSS Feed with Spring MVC](http://www.baeldung.com/spring-mvc-rss-feed)
|
||||
|
||||
- [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao)
|
||||
- [Cache Eviction in Spring Boot](https://www.baeldung.com/spring-boot-evict-cache)
|
||||
|
@ -35,3 +35,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Spring Component Scanning](https://www.baeldung.com/spring-component-scanning)
|
||||
- [Load Spring Boot Properties From a JSON File](https://www.baeldung.com/spring-boot-json-properties)
|
||||
- [Display Auto-Configuration Report in Spring Boot](https://www.baeldung.com/spring-boot-auto-configuration-report)
|
||||
- [Logging to Graylog with Spring Boot](https://www.baeldung.com/graylog-with-spring-boot)
|
||||
|
@ -16,5 +16,6 @@ public class CollectionInjectionDemo {
|
||||
collectionsBean.printNameSet();
|
||||
collectionsBean.printNameMap();
|
||||
collectionsBean.printBeanList();
|
||||
collectionsBean.printNameListWithDefaults();
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.baeldung.collection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/18/2018.
|
||||
*/
|
||||
@ -24,6 +25,9 @@ public class CollectionsBean {
|
||||
@Qualifier("CollectionsBean")
|
||||
private List<BaeldungBean> beanList = new ArrayList<>();
|
||||
|
||||
@Value("${names.list:}#{T(java.util.Collections).emptyList()}")
|
||||
private List<String> nameListWithDefaultValue;
|
||||
|
||||
public CollectionsBean() {
|
||||
}
|
||||
|
||||
@ -51,4 +55,8 @@ public class CollectionsBean {
|
||||
public void printBeanList() {
|
||||
System.out.println(beanList);
|
||||
}
|
||||
|
||||
public void printNameListWithDefaults() {
|
||||
System.out.println(nameListWithDefaultValue);
|
||||
}
|
||||
}
|
||||
|
@ -2,3 +2,4 @@
|
||||
|
||||
- [Introduction to TestNG](http://www.baeldung.com/testng)
|
||||
- [Custom Reporting with TestNG](http://www.baeldung.com/testng-custom-reporting)
|
||||
- [A Quick JUnit vs TestNG Comparison](https://www.baeldung.com/junit-vs-testng)
|
||||
|
@ -3,3 +3,4 @@
|
||||
- [Introduction to JiBX](http://www.baeldung.com/jibx)
|
||||
- [XML Libraries Support in Java](http://www.baeldung.com/java-xml-libraries)
|
||||
- [DOM parsing with Xerces](http://www.baeldung.com/java-xerces-dom-parsing)
|
||||
- [Write an org.w3.dom.Document to a File](https://www.baeldung.com/java-write-xml-document-file)
|
||||
|
Loading…
x
Reference in New Issue
Block a user