Guava
From charlesreid1
Guava is a Java library of high-performance collections and data containers. It was made and is maintained by Google.
The story behind Guava is, Google basically hired the author of the Java Collections API to go nuts and build a Collections++ library.
Google Guava on Github: https://github.com/google/guava
Contents
Installing
Jar File
Probably the easiest way to install Guava is to use the Guava jar file. You can find the link to Guava distributed as a Jar file on the Guava wiki on Github: https://github.com/google/guava/wiki/Release21
Using the Jar file depends on your environment, most IDEs have an easy way to add Jar files to a project.
If you're compiling by command line, you'll need to specify the Java class path and point Java to the location of your Jar files.
Class Path
To pass a custom class path with the location of your Guava jar files to the compiler,
$ javac -cp '.:/path/to/guava/jars/guava-21.0.jar' TSP.java
Then run Java with the same flag:
$ java -cp '.:/path/to/guava/jars/guava-21.0.jar' TSP
Makefile
Put the above in a Makefile for more convenience:
HOME=/path/to/home GUAVA=$(HOME)/guava/jars/guava-21.0.jar CP=-cp '.:$(GUAVA)' build: javac $(CP) $(TARGET) run: # If no size, use default java $(CP) $(BIN) clean: rm -rf *.class .PHONY: clean tsp: clean build run
Predicates
Predicates are conditions that must be true for an action to be taken. See Guava Predicates page.
Containers
Maps
The Maps class contains many, many static utility methods for Map classes. See Guava Maps for more.
Lists
This is the analog of Maps, but for the List type.
Stacks and Queues
These are the analogues of Maps, but for the Stack and Queue types.
Networks
Edges
Getting Endpoint Nodes from an Edge
To get the nodes at either end of a node, you can use the incidentNode() function to go from an edge to the two endpoints of the edge.
The incidentNode() method returns an object called a EndpointPair class, defined by Guava. How you use it depends on whether you have a directed or an undirected graph.
Documentation on EndpointPair: http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/graph/EndpointPair.html
If you have a directed graph, you can use an edge to get the EndpointPair object, then call the source()
and target()
methods to get the nodes at the tail and head of the edge, resp.
If you have an undirected graph, you can use an edge to get the EndpointPair object, then call the nodeU()
and nodeV()
methods, which are basically equivalent to left and right.
Documentation on Network (see incidentNode method): http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/graph/Network.html#incidentNodes-java.lang.Object-
Examples of Guava in Action
Traveling Salesperson Problem
You can see some examples of Guava in action at the following links:
- charlesreid1.github.io blog: "Solving the Traveling Salesperson Problem with Guava": http://charlesreid1.github.io/solving-the-traveling-salesperson-problem-with-java-and-guava.html
- charlesreid1.github.io blog: "Better Timing of Guava Traveling Salesperson Problem Code: Timing Scripts ": http://charlesreid1.github.io/better-timing-of-guava-traveling-salesperson-problem-code-timing-scripts.html
- charlesreid1.github.io blog: " Fixing Bottlenecks in the Guava Traveling Salesperson Problem Code ": http://charlesreid1.github.io/fixing-bottlenecks-in-the-guava-traveling-salesperson-problem-code.html
- git.charlesreid1.com traveling salesperson problem (TSP) repository: https://git.charlesreid1.com/charlesreid1/tsp/src/master/guava/README.md
Flags
Computer Science notes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Python/Exceptions · Python/Assertions · Python/Decorators Python/Os (os module) · Python/Strings Python/Splat · Python/Iterators · Python/Generators Python/Comparators · Python/Lambdas
Builtin features of Java: Java/Exceptions · Java/Assertions · Java/Memory · Java/Interfaces Java/Generics · Java/Decorators · Java/Diamond Notation Java/Iterators · Java/Iterable · Iterators vs Iterable Java/Comparators · Java/Comparable · Comparators vs Comparable Java/Numeric · Java/TypeChecking · Java/Testing · Java/Timing · Java/Profiling Documentation: Javadocs · Java/Documentation Tools and functionality: Java/URLs · Java/CSV External libraries: Guava · Fastutil · Eclipse Collections OOP: OOP Checklist · Java/Abstract Class · Java/Encapsulation · Java/Generics
|
See also: