Skip to content

Instantly share code, notes, and snippets.

@mismatch
mismatch / WordsFrequencies.java
Last active March 4, 2018 16:07
Calculate words frequencies in declarative way
import java.io.BufferedReader;
import java.io.Reader;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Pattern;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
public class WordsFrequencies {
public class EquationStream {
public static void main(String[] args) {
List<Month> months = new ArrayList<>(12);
months.add(new Month(1, "January"));
months.add(new Month(2, "February"));
months.add(new Month(3, "March"));
months.add(new Month(4, "April"));
months.add(new Month(5, "May"));
public boolean add(E e) {
return this.m.put(e, PRESENT) == null;
}
static int compareItems(TestItem item1, TestItem item2) {
return item2.name.compareToIgnoreCase(item1.name);
}
import java.util.*;
public class TreeSetWithDuplicates {
public static void main(String[] args) {
System.out.println(removeDuplicates(Arrays.asList(
new TestItem("Book A", "First edition"),
new TestItem("Book C", "First edition"),
new TestItem("Book ABC", "Not published"),
new TestItem("Book A", "First edition"))));
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {HibernateJpaAutoConfiguration.class,
DatabasesConfig.class, JpaRepositoriesConfig.class})
public class YourDbTest {
// test methods
}
@mismatch
mismatch / JpaRepositoriesConfig.java
Created August 10, 2014 06:45
Spring Boot. Multiple DB repositories configuration example
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan.Filter;
@mismatch
mismatch / DatabasesConfig.java
Created August 10, 2014 06:41
Spring Boot. Multiple datasources configuration example
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
appName.dbOne.datasource.driverClassName=org.postgresql.Driver
appName.dbOne.datasource.url=jdbc:postgresql://localhost/dbOne
appName.dbOne.datasource.username=test
appName.dbOne.datasource.password=test
appName.dbTwo.datasource.driverClassName=org.postgresql.Driver
appName.dbTwo.datasource.url=jdbc:postgresql://localhost/dbTwo
appName.dbTwo.datasource.username=test
appName.dbTwo.datasource.password=test
#!/bin/sh
systemctl enable testrest.service