GithubHelp home page GithubHelp logo

isabella232 / de.flapdoodle.guava Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flapdoodle-oss/de.flapdoodle.guava

0.0 0.0 0.0 360 KB

minor guava extensions

License: Apache License 2.0

Shell 0.11% Java 99.89%

de.flapdoodle.guava's Introduction

Organisation Flapdoodle OSS

We are now a github organisation. You are invited to participate.

de.flapdoodle.guava

minor guava extensions

Maven

Stable (Maven Central Repository, Released: 09.08.2016 - wait 24hrs for maven central)

<dependency>
	<groupId>de.flapdoodle.guava</groupId>
	<artifactId>de.flapdoodle.guava</artifactId>
	<version>1.4.1</version>
</dependency>

Snapshots (Repository http://oss.sonatype.org/content/repositories/snapshots)

<dependency>
	<groupId>de.flapdoodle.guava</groupId>
	<artifactId>de.flapdoodle.guava</artifactId>
	<version>1.4.2-SNAPSHOT</version>
</dependency>

Usage

We did some minor extensions based on guava stuff which can be usefull in some situations. These extensions are not optimized for speed or memory usage.

Collections stuff

First element of collections
List<String> data;
...
Optional<String> result = Expectations.noneOrOne(data);
...

Convert lists into maps

Convert a list into a 1:1 map
List<Order> orders;
...
Function<Order, Integer> keytransformation = new Function<Order, Integer>() {

	@Override
	public Integer apply(Order order) {
		return order.getId();
	}
};

Map<Integer, Order> orderMap = Transformations.map(orders, keytransformation);

Order order = orderMap.get(2);
...
Convert a list into a 1:1 map with transformations for key and value
List<User> users;
...
Function<User, Integer> keytransformation = new Function<User, Integer>() {

	@Override
	public Integer apply(User user) {
		return user.id();
	}
};

Function<User, String> valuetransformation = new Function<User, String>() {

	@Override
	public String apply(User user) {
		return user.name();
	}
};

Map<Integer, String> userMap = Transformations.map(users, keytransformation, valuetransformation);

String userName = userMap.get(2);
...
Convert a list into a map of lists
...
List<String> names = Lists.newArrayList("Achim", "Albert", "Susi", "Sonja", "Bert");

Function<String, Character> keytransformation = new Function<String, Character>() {

	@Override
	public Character apply(String name) {
		return name.charAt(0);
	}
};

Map<Character, ImmutableList<? extends String>> nameMap = Transformations.map(names, keytransformation,
		Folds.asListFold(Transformations.<String> asCollection()));

ImmutableList<? extends String> namesWithA = nameMap.get('A');

...

Foldleft

foldLeft can be used for many aggregation operations like sum, count, concat.. ... List numbers = Lists.newArrayList(1,2,3,4,5,6); int result = Folds.foldLeft(numbers, new Foldleft<Integer, Integer>() { @Override public Integer apply(Integer left, Integer right) { return left+right; } }, 0);

...

de.flapdoodle.guava's People

Contributors

michaelmosmann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.