Skip to content

Instantly share code, notes, and snippets.

View Pyknic's full-sized avatar

Emil Forslund Pyknic

View GitHub Profile
package test2.operators;
import java.util.function.Predicate;
/**
*
* @author Emil Forslund
*/
public enum StandardBinaryOperator {
public final class CollectorUtil {
/**
* Returns a new {@link MapStream} where the elements have been grouped together using
* the specified function.
*
* @param <T> the stream element type
* @param <C> the type of the key to group by
* @param grouper the function to use for grouping
* @return a {@link MapStream} grouped by key
package com.speedment.example.Alphabetic;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* An example of a method that can generate an infinite stream of
* column names like AA, AB, AC...
*
@Pyknic
Pyknic / Films.java
Last active February 18, 2016 16:59
An example of how to use the MapStream class in Speedment to create a view of all Actors and how many movies they have starred in based on rating.
MapStream.fromKeys(
actors.stream(), // Stream<Actor>
actor -> actor.findActorFilms() // Stream<ActorFilm>
.map(ActorFilm::findFilm), // Stream<Film>
.collect(groupBy(film -> film.getRating())) // MapStream<Rating, List<Film>>
.mapValue(List::size) // MapStream<Rating, Integer>
); // MapStream<Actor, MapStream<Rating, Integer>>
@Pyknic
Pyknic / output.java
Created October 3, 2015 05:43
The output from the Java 8 Variants generation
/**
* Write some documentation here.
*/
package com.speedment.steam.action;
import java.util.stream.Stream;
import java.util.function.Function;
import com.speedment.stream.StreamAction;
import static java.util.Objects.requireNonNull;
package com.pyknic.variant;
import com.speedment.codegen.lang.models.Generic;
import com.speedment.codegen.lang.models.Type;
import static com.speedment.codegen.lang.models.constants.DefaultType.DOUBLE_PRIMITIVE;
import static com.speedment.codegen.lang.models.constants.DefaultType.INT_PRIMITIVE;
import static com.speedment.codegen.lang.models.constants.DefaultType.LONG_PRIMITIVE;
import static com.speedment.codegen.lang.models.constants.DefaultType.OBJECT;
import java.util.Optional;
import java.util.OptionalDouble;
CREATE TABLE "region" (
"id" SERIAL PRIMARY KEY NOT NULL,
"abbrevation" CHAR(2) UNIQUE NOT NULL,
"name" VARCHAR(32) UNIQUE NOT NULL
);
CREATE TABLE "country" (
"id" SERIAL PRIMARY KEY NOT NULL,
"abbrevation" CHAR(2) UNIQUE NOT NULL,
"name" VARCHAR(64) NOT NULL,
@Pyknic
Pyknic / TableEnumPlugin.java
Last active September 16, 2016 18:21
A Speedment example that list all tables in the database as an enum
public final class TableEnumPlugin {
@ExecuteBefore(INITIALIZED)
void install(CodeGenerationComponent codeGen) {
codeGen.put(Project.class, TABLES_ENUM_KEY, TableEnumTranslator::new);
}
}
@Pyknic
Pyknic / speedment.json
Created September 16, 2016 18:49
Minimal Json Configuration
{
"config" : {
"name" : "sales",
"dbmses" : [{
"name" : "db0",
"typeName" : "MySQL",
"ipAddress" : "127.0.0.1",
"username" : "root",
"schemas" : [{
@Pyknic
Pyknic / Main.java
Created February 15, 2017 01:27
An example on how to generate release notes using the GitHub API
/**
*
* @author Emil Forslund
* @since 1.0.0
*/
public final class Main {
@SuppressWarnings("unchecked")
public static void main(String... param)
throws InterruptedException, ExecutionException, IOException {