Merge remote-tracking branch 'eugenp/master'
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mabsisa</groupId>
|
||||
<artifactId>Twitter4J</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Twitter4J</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@@ -23,27 +19,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/ApplicationTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<twitter4j-stream.version>4.0.6</twitter4j-stream.version>
|
||||
</properties>
|
||||
|
||||
+1
-46
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>activejdbc</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
@@ -79,55 +78,11 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<reportFormat>brief</reportFormat>
|
||||
<trimStackTrace>true</trimStackTrace>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
<include>**/*Spec*.java</include>
|
||||
<include>**/*Test*.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/helpers/*</exclude>
|
||||
<exclude>**/*$*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>snapshots1</id>
|
||||
<name>JavaLite Snapshots1</name>
|
||||
<url>http://repo.javalite.io/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>warn</checksumPolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>snapshots2</id>
|
||||
<name>JavaLite Snapshots2</name>
|
||||
<url>http://repo.javalite.io/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>warn</checksumPolicy>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<properties>
|
||||
<activejdbc.version>1.4.13</activejdbc.version>
|
||||
<activejdbc.version>2.0</activejdbc.version>
|
||||
<environments>development.test,development</environments>
|
||||
<mysql.connector.version>5.1.34</mysql.connector.version>
|
||||
</properties>
|
||||
|
||||
@@ -16,4 +16,8 @@ public class Employee extends Model {
|
||||
set("created_by",createdBy);
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return getString("last_name");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ public class Role extends Model {
|
||||
set("role_name",role);
|
||||
set("created_by",createdBy);
|
||||
}
|
||||
|
||||
public String getRoleName() {
|
||||
return getString("role_name");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ActiveJDBCAppTest extends DBSpec
|
||||
public class ActiveJDBCAppManualTest extends DBSpec
|
||||
{
|
||||
@Test
|
||||
public void ifEmployeeCreated_thenIsValid() {
|
||||
@@ -0,0 +1 @@
|
||||
/bin/
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.java.src;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class RoundUpToHundred {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
double input = scanner.nextDouble();
|
||||
scanner.close();
|
||||
|
||||
RoundUpToHundred.round(input);
|
||||
}
|
||||
|
||||
static long round(double input) {
|
||||
long i = (long) Math.ceil(input);
|
||||
return ((i + 99) / 100) * 100;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.java.src;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RoundUpToHundredTest {
|
||||
@Test
|
||||
public void givenInput_whenRound_thenRoundUpToTheNearestHundred() {
|
||||
assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99));
|
||||
assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2));
|
||||
assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400));
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-shiro</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
@@ -36,13 +35,11 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -53,26 +50,9 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<apache-shiro-core-version>1.4.0</apache-shiro-core-version>
|
||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||
<java.version>1.8</java.version>
|
||||
<log4j-version>1.2.17</log4j-version>
|
||||
<slf4j-version>1.7.25</slf4j-version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -42,14 +42,6 @@
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<argLine>-javaagent:"C:\asm-1.0.jar"</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>cas-secured-app</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>cas-secured-app</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<description>Demo project for CAS</description>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-1</artifactId>
|
||||
@@ -60,10 +58,4 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
+10
-40
@@ -2,11 +2,17 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd ">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>cas-server</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0</version>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-1</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-1</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apereo.cas</groupId>
|
||||
@@ -39,7 +45,6 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>${mainClassName}</mainClass>
|
||||
<addResources>true</addResources>
|
||||
@@ -74,42 +79,10 @@
|
||||
</overlays>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>cas</finalName>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-releases</id>
|
||||
<url>http://oss.sonatype.org/content/repositories/releases/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>shibboleth-releases</id>
|
||||
<url>https://build.shibboleth.net/nexus/content/repositories/releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<activation>
|
||||
@@ -214,8 +187,7 @@
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<cas.version>5.3.0-SNAPSHOT</cas.version>
|
||||
<springboot.version>1.5.13.RELEASE</springboot.version>
|
||||
<cas.version>5.3.3</cas.version>
|
||||
<!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver -->
|
||||
<app.server>-tomcat</app.server>
|
||||
|
||||
@@ -223,14 +195,12 @@
|
||||
<isExecutable>false</isExecutable>
|
||||
<manifestFileToUse>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF</manifestFileToUse>
|
||||
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<wrapper-maven-plugin.version>0.0.4</wrapper-maven-plugin.version>
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
|
||||
|
||||
<echo-maven-plugin.version>0.3.0</echo-maven-plugin.version>
|
||||
<pgpverify-maven-plugin.version>1.1.0</pgpverify-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -63,6 +63,12 @@
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-exec</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
|
||||
public class CombiningArrays {
|
||||
|
||||
public static Object[] usingNativeJava(Object[] first, Object[] second) {
|
||||
Object[] combined = new Object[first.length + second.length];
|
||||
System.arraycopy(first, 0, combined, 0, first.length);
|
||||
System.arraycopy(second, 0, combined, first.length, second.length);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Object[] usingJava8ObjectStream(Object[] first, Object[] second) {
|
||||
Object[] combined = Stream.concat(Arrays.stream(first), Arrays.stream(second)).toArray();
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Object[] usingJava8FlatMaps(Object[] first, Object[] second) {
|
||||
Object[] combined = Stream.of(first, second).flatMap(Stream::of).toArray(String[]::new);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Object[] usingApacheCommons(Object[] first, Object[] second) {
|
||||
Object[] combined = ArrayUtils.addAll(first, second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Object[] usingGuava(Object[] first, Object[] second) {
|
||||
Object [] combined = ObjectArrays.concat(first, second, Object.class);
|
||||
return combined;
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class CombiningLists {
|
||||
|
||||
public static List<Object> usingNativeJava(List<Object> first, List<Object> second) {
|
||||
List<Object> combined = new ArrayList<>();
|
||||
combined.addAll(first);
|
||||
combined.addAll(second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static List<Object> usingJava8ObjectStream(List<Object> first, List<Object> second) {
|
||||
List<Object> combined = Stream.concat(first.stream(), second.stream()).collect(Collectors.toList());
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static List<Object> usingJava8FlatMaps(List<Object> first, List<Object> second) {
|
||||
List<Object> combined = Stream.of(first, second).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static List<Object> usingApacheCommons(List<Object> first, List<Object> second) {
|
||||
List<Object> combined = ListUtils.union(first, second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static List<Object> usingGuava(List<Object> first, List<Object> second) {
|
||||
Iterable<Object> combinedIterables = Iterables.unmodifiableIterable(
|
||||
Iterables.concat(first, second));
|
||||
|
||||
List<Object> combined = Lists.newArrayList(combinedIterables);
|
||||
return combined;
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.exec.util.MapUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class CombiningMaps {
|
||||
|
||||
public static Map<String, String> usingPlainJava(Map<String, String> first, Map<String, String> second) {
|
||||
Map<String, String> combined = new HashMap<>();
|
||||
combined.putAll(first);
|
||||
combined.putAll(second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Map<String, String> usingJava8ForEach(Map<String, String> first, Map<String, String> second) {
|
||||
second.forEach((key, value) -> first.merge(key, value, String::concat));
|
||||
return first;
|
||||
}
|
||||
|
||||
public static Map<String, String> usingJava8FlatMaps(Map<String, String> first, Map<String, String> second) {
|
||||
Map<String, String> combined = Stream.of(first, second).map(Map::entrySet).flatMap(Collection::stream)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, String::concat));
|
||||
return combined;
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> usingApacheCommons(Map<String, String> first, Map<String, String> second) {
|
||||
Map<String, String> combined = MapUtils.merge(first, second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Map<String, String> usingGuava(Map<String, String> first, Map<String, String> second) {
|
||||
Map<String, String> combined = ImmutableMap.<String, String>builder()
|
||||
.putAll(first)
|
||||
.putAll(second)
|
||||
.build();
|
||||
return combined;
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.collections4.SetUtils;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class CombiningSets {
|
||||
|
||||
public static Set<Object> usingNativeJava(Set<Object> first, Set<Object> second) {
|
||||
Set<Object> combined = new HashSet<>();
|
||||
combined.addAll(first);
|
||||
combined.addAll(second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Set<Object> usingJava8ObjectStream(Set<Object> first, Set<Object> second) {
|
||||
Set<Object> combined = Stream.concat(first.stream(), second.stream()).collect(Collectors.toSet());
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Set<Object> usingJava8FlatMaps(Set<Object> first, Set<Object> second) {
|
||||
Set<Object> combined = Stream.of(first, second).flatMap(Collection::stream).collect(Collectors.toSet());
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Set<Object> usingApacheCommons(Set<Object> first, Set<Object> second) {
|
||||
Set<Object> combined = SetUtils.union(first, second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static Set<Object> usingGuava(Set<Object> first, Set<Object> second) {
|
||||
Set<Object> combined = Sets.union(first, second);
|
||||
return combined;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,4 +44,12 @@ public class Employee {
|
||||
result = 31 * result + name.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Employee{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.sort;
|
||||
|
||||
public class Employee implements Comparable<Employee> {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Employee(Long id, String name) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Employee employee = (Employee) o;
|
||||
|
||||
if (!id.equals(employee.id)) return false;
|
||||
return name.equals(employee.name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id.hashCode();
|
||||
result = 31 * result + name.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Employee{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Employee employee) {
|
||||
return (int)(this.id - employee.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.baeldung.sort;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SortHashMap {
|
||||
|
||||
private static Map<String, Employee> map = new HashMap<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
initialize();
|
||||
|
||||
treeMapSortByKey();
|
||||
|
||||
arrayListSortByValue();
|
||||
arrayListSortByKey();
|
||||
|
||||
sortStream();
|
||||
|
||||
sortGuava();
|
||||
|
||||
addDuplicates();
|
||||
|
||||
treeSetByKey();
|
||||
treeSetByValue();
|
||||
|
||||
}
|
||||
|
||||
private static void sortGuava() {
|
||||
final Ordering naturalOrdering =
|
||||
Ordering.natural().onResultOf(Functions.forMap(map, null));
|
||||
|
||||
System.out.println(ImmutableSortedMap.copyOf(map, naturalOrdering));
|
||||
}
|
||||
|
||||
private static void sortStream() {
|
||||
map.entrySet().stream()
|
||||
.sorted(Map.Entry.<String, Employee>comparingByKey().reversed())
|
||||
.forEach(System.out::println);
|
||||
|
||||
Map<String, Employee> result = map.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue())
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
|
||||
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
|
||||
|
||||
result.entrySet().forEach(System.out::println);
|
||||
}
|
||||
|
||||
private static void treeSetByValue() {
|
||||
SortedSet<Employee> values = new TreeSet<>(map.values());
|
||||
System.out.println(values);
|
||||
}
|
||||
|
||||
private static void treeSetByKey() {
|
||||
SortedSet<String> keysSet = new TreeSet<>(map.keySet());
|
||||
System.out.println(keysSet);
|
||||
}
|
||||
|
||||
private static void treeMapSortByKey() {
|
||||
TreeMap<String, Employee> sorted = new TreeMap<>(map);
|
||||
sorted.putAll(map);
|
||||
|
||||
sorted.entrySet().forEach(System.out::println);
|
||||
|
||||
}
|
||||
|
||||
private static void arrayListSortByValue() {
|
||||
List<Employee> employeeById = new ArrayList<>(map.values());
|
||||
|
||||
Collections.sort(employeeById);
|
||||
|
||||
System.out.println(employeeById);
|
||||
}
|
||||
|
||||
private static void arrayListSortByKey() {
|
||||
List<String> employeeByKey = new ArrayList<>(map.keySet());
|
||||
Collections.sort(employeeByKey);
|
||||
System.out.println(employeeByKey);
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
Employee employee1 = new Employee(1L, "Mher");
|
||||
map.put(employee1.getName(), employee1);
|
||||
Employee employee2 = new Employee(22L, "Annie");
|
||||
map.put(employee2.getName(), employee2);
|
||||
Employee employee3 = new Employee(8L, "John");
|
||||
map.put(employee3.getName(), employee3);
|
||||
Employee employee4 = new Employee(2L, "George");
|
||||
map.put(employee4.getName(), employee4);
|
||||
}
|
||||
|
||||
private static void addDuplicates() {
|
||||
Employee employee5 = new Employee(1L, "Mher");
|
||||
map.put(employee5.getName(), employee5);
|
||||
Employee employee6 = new Employee(22L, "Annie");
|
||||
map.put(employee6.getName(), employee6);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningArraysUnitTest {
|
||||
private static final String first[] = {
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
};
|
||||
|
||||
private static final String second[] = {
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
};
|
||||
|
||||
private static final String expected[] = {
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
};
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingNativeJava_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingNativeJava(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingObjectStreams_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingJava8ObjectStream(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingFlatMaps_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingJava8FlatMaps(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingApacheCommons_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingApacheCommons(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingGuava_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingGuava(first, second));
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningListsUnitTest {
|
||||
private static final List<Object> first = Arrays.asList(new Object[]{
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
});
|
||||
|
||||
private static final List<Object> second = Arrays.asList(new Object[]{
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
});
|
||||
|
||||
private static final List<Object> expected = Arrays.asList(new Object[]{
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
});
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingNativeJava_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingNativeJava(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingObjectStreams_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingJava8ObjectStream(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingFlatMaps_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingJava8FlatMaps(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingApacheCommons_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingApacheCommons(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingGuava_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingGuava(first, second), is(expected));
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningMapsUnitTest {
|
||||
private static final Map<String, String> first = new HashMap<>();
|
||||
private static final Map<String, String> second = new HashMap<>();
|
||||
private static Map<String, String> expected = new HashMap<>();
|
||||
|
||||
static {
|
||||
first.put("one", "first String");
|
||||
first.put("two", "second String");
|
||||
|
||||
second.put("three", "third String");
|
||||
second.put("four", "fourth String");
|
||||
|
||||
expected.put("one", "first String");
|
||||
expected.put("two", "second String");
|
||||
expected.put("three", "third String");
|
||||
expected.put("four", "fourth String");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingNativeJava_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingPlainJava(first, second), is(expected));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingForEach_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingJava8ForEach(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingFlatMaps_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingJava8FlatMaps(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingApacheCommons_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingApacheCommons(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingGuava_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingGuava(first, second), is(expected));
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningSetsUnitTest {
|
||||
private static final Set<Object> first = new HashSet<Object>(Arrays.asList(new Object[] { "One", "Two", "Three" }));
|
||||
|
||||
private static final Set<Object> second = new HashSet<Object>(Arrays.asList(new Object[] { "Four", "Five", "Six" }));
|
||||
|
||||
private static final Set<Object> expected = new HashSet<Object>(Arrays
|
||||
.asList(new Object[] { "One", "Two", "Three", "Four", "Five", "Six" }));
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingNativeJava_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingNativeJava(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingObjectStreams_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingJava8ObjectStream(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingFlatMaps_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingJava8FlatMaps(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingApacheCommons_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingApacheCommons(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingGuava_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingGuava(first, second), is(expected));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>core-java-io</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
@@ -166,36 +165,6 @@
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*IntTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>spring-boot</classifier>
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
@@ -229,32 +198,6 @@
|
||||
<id>integration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
<include>**/*IntTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
@@ -310,14 +253,11 @@
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<esapi.version>2.1.0.1</esapi.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
<async-http-client.version>2.4.5</async-http-client.version>
|
||||
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -24,6 +24,13 @@ public class ZipDirectory {
|
||||
return;
|
||||
}
|
||||
if (fileToZip.isDirectory()) {
|
||||
if (fileName.endsWith("/")) {
|
||||
zipOut.putNextEntry(new ZipEntry(fileName));
|
||||
zipOut.closeEntry();
|
||||
} else {
|
||||
zipOut.putNextEntry(new ZipEntry(fileName + "/"));
|
||||
zipOut.closeEntry();
|
||||
}
|
||||
final File[] children = fileToZip.listFiles();
|
||||
for (final File childFile : children) {
|
||||
zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.baeldung.file;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
@@ -120,4 +121,14 @@ public class FileOperationsManualTest {
|
||||
|
||||
return resultStringBuilder.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFileName_whenUsingIOUtils_thenFileData() throws IOException {
|
||||
String expectedData = "This is a content of the file";
|
||||
|
||||
FileInputStream fis = new FileInputStream("src/test/resources/fileToRead.txt");
|
||||
String data = IOUtils.toString(fis, "UTF-8");
|
||||
|
||||
assertEquals(expectedData, data.trim());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.nio.file.Paths;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SymLinkExampleUnitTest {
|
||||
public class SymLinkExampleManualTest {
|
||||
|
||||
@Test
|
||||
public void whenUsingFiles_thenCreateSymbolicLink() throws IOException {
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.doubles;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class SplitFloatingPointNumbers {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
double doubleNumber = 24.04;
|
||||
splitUsingFloatingTypes(doubleNumber);
|
||||
splitUsingString(doubleNumber);
|
||||
splitUsingBigDecimal(doubleNumber);
|
||||
}
|
||||
|
||||
private static void splitUsingFloatingTypes(double doubleNumber) {
|
||||
System.out.println("Using Floating Point Arithmetics:");
|
||||
int intPart = (int) doubleNumber;
|
||||
System.out.println("Double Number: "+doubleNumber);
|
||||
System.out.println("Integer Part: "+ intPart);
|
||||
System.out.println("Decimal Part: "+ (doubleNumber - intPart));
|
||||
}
|
||||
|
||||
private static void splitUsingString(double doubleNumber) {
|
||||
System.out.println("Using String Operations:");
|
||||
String doubleAsString = String.valueOf(doubleNumber);
|
||||
int indexOfDecimal = doubleAsString.indexOf(".");
|
||||
System.out.println("Double Number: "+doubleNumber);
|
||||
System.out.println("Integer Part: "+ doubleAsString.substring(0, indexOfDecimal));
|
||||
System.out.println("Decimal Part: "+ doubleAsString.substring(indexOfDecimal));
|
||||
}
|
||||
|
||||
private static void splitUsingBigDecimal(double doubleNumber) {
|
||||
System.out.println("Using BigDecimal Operations:");
|
||||
BigDecimal bigDecimal = new BigDecimal(String.valueOf(doubleNumber));
|
||||
int intValue = bigDecimal.intValue();
|
||||
System.out.println("Double Number: "+bigDecimal.toPlainString());
|
||||
System.out.println("Integer Part: "+intValue);
|
||||
System.out.println("Decimal Part: "+bigDecimal.subtract(new BigDecimal(intValue)).toPlainString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.heapdump;
|
||||
|
||||
import com.sun.management.HotSpotDiagnosticMXBean;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class HeapDump {
|
||||
|
||||
public static void dumpHeap(String filePath, boolean live) throws IOException {
|
||||
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
||||
HotSpotDiagnosticMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(
|
||||
server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
|
||||
mxBean.dumpHeap(filePath, live);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String file = Paths.get("dump.hprof").toFile().getPath();
|
||||
|
||||
dumpHeap(file, true);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user