fun.mike:flapjack-lab

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

GroupId

GroupId

fun.mike
ArtifactId

ArtifactId

flapjack-lab
Last Version

Last Version

0.0.15
Release Date

Release Date

Type

Type

jar
Description

Description

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

https://github.com/mike706574/flapjack-lab
Source Code Management

Source Code Management

http://github.com/mike706574/flapjack-lab/tree/master

Download flapjack-lab

How to add to project

<!-- https://jarcasting.com/artifacts/fun.mike/flapjack-lab/ -->
<dependency>
    <groupId>fun.mike</groupId>
    <artifactId>flapjack-lab</artifactId>
    <version>0.0.15</version>
</dependency>
// https://jarcasting.com/artifacts/fun.mike/flapjack-lab/
implementation 'fun.mike:flapjack-lab:0.0.15'
// https://jarcasting.com/artifacts/fun.mike/flapjack-lab/
implementation ("fun.mike:flapjack-lab:0.0.15")
'fun.mike:flapjack-lab:jar:0.0.15'
<dependency org="fun.mike" name="flapjack-lab" rev="0.0.15">
  <artifact name="flapjack-lab" type="jar" />
</dependency>
@Grapes(
@Grab(group='fun.mike', module='flapjack-lab', version='0.0.15')
)
libraryDependencies += "fun.mike" % "flapjack-lab" % "0.0.15"
[fun.mike/flapjack-lab "0.0.15"]

Dependencies

compile (5)

Group / Artifact Type Version
fun.mike : flapjack-alpha jar 0.0.56
org.slf4j : slf4j-api jar 1.8.0-beta2
fun.mike : io-support-alpha jar 0.0.13
fun.mike : record-alpha jar 0.0.38
de.vandermeer : asciitable jar 0.3.2

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.slf4j : slf4j-simple jar 1.8.0-beta2

Project Modules

There are no modules declared in this project.

flapjack-lab

Maven Central Javadocs

Experimental flapjack functionality.

Usage

Pipeline

Pipelines let you parse, transform, and serialize records flat file records using a functional, data-driven API.

The examples below use this example CSV file, animals.csv:

dog,4,medium
elephant,4,huge
fox,4,medium
ostrich,2,medium
whale,0,gigantic
snake,0,small

Flat file to flat file

Example.java

// Define an input format
Format inputFormat =
    DelimitedFormat.unframed("animals",
                             "A bunch of animals.",
                             ',',
                             Arrays.asList(Column.string("name"),
                                           Column.integer("legs"),
                                           Column.string("size")));

// Define an output format
Format outputFormat =
    FixedWidthFormat("medium-sized-animals",
                     "A bunch of medium-sized animals.",
                     Arrays.asList(Field.string("name", 10),
                                   Field.string("size", 10)));

// Build a pipeline
FlatFilePipeline pipeline = Pipeline.fromFile("animals.csv", inputFormat)
    .filter(x -> x.getString("size").equals("MEDIUM"))
    .map(x -> x.updateString("name", String::toUpperCase))
    .toFile("medium-sized-animals.txt", outputFormat)
    .build();

// Run it
FlatFileResult result = pipeline.run();

// Check for failures
result.isOk();
// => true

result.getFailureCount();
// => 0

// See how many animals went in
result.getInputCount();
// => 6

// See how many medium-sized animals came out
result.getOutputCount();
// => 3

medium-sized-animals.txt

DOG       4
FOX       4
OSTRICH   2

Flat file to list

// Define an input format
Format inputFormat =
    DelimitedFormat.unframed("animals",
                             "A bunch of animals.",
                             ',',
                             Arrays.asList(Column.string("name"),
                                           Column.integer("legs"),
                                           Column.string("size")));

ListPipeline pipeline = Pipeline.fromFile("animals.csv", inputFormat)
        .map(x -> x.updateString("size", String::toUpperCase))
        .filter(x -> x.getString("size").equals("MEDIUM"))
        .toList();

ListResult result = pipeline.run();

assertTrue(result.isOk());
assertEquals(6, result.getInputCount());
assertEquals(3, result.getOutputCount());

List<Record> animals = result.orElseThrow();
// => [{name=dog, legs=4, size=MEDIUM},
       {name=fox, legs=4, size=MEDIUM},
       {name=ostrich, legs=2, size=MEDIUM}]

Build

CircleCI

Copyright and License

The use and distribution terms for this software are covered by the Eclipse Public License 1.0 which can be found in the file epl-v10.html at the root of this distribution. By using this softwaer in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

Versions

Version
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1