caffeine
Replaces common java.util classes along with providing exciting new Data Structures:
- Tries
- Graphs
- Finite Automaton
- Weighted/Unweighted
- Sequences
- Lazy evaluation
- Functional style
- Monadic Pipelines
- 'Streams' implementation with extra functions
- Pattern Matching and Guards
- Along with configure factory method for matching any object.
- Tuples(0-12 arity), Try class, Lazy class
- Cons list and recursive Trees using pattern matching.
Aims
- The only imports from
java.utilwill be to implement an Interface - Where possible, use generics and implement
Collection,Set,Map,List,Iterableetc. - Always reduce complexity in algorithms
- Always refactor to minimise repeated code
Pipelines
- I have implemented and augmented the API for
java.util.streams.StreamwithPipeline- Upgraded to match
JDK 9Streams API, with addition of more functional features: - zipping, cartesian product, matching, streaming optionals, pattern matching.
- Upgraded to match
- Implemented as a linked list of Nodes that perform operations on values passed to them
Sequences
I have combined my implementation of Pipelines with additional functions for use in creating sequences
- Pick an algorithm style from
- Recursive (New terms are generated based on the previous ones)
- Non Recursive (Terms are only dependent on their index)
- Users can then:
- Set the range of terms in scope
- filter only terms that pass a predicate
- take terms while a predicate holds true
- drop terms while a predicate holds true
- add and remove these conditions on the same Sequence instance
- view individual terms
- convert to a Pipeline for more options;
Terms are memoised for higher performance over multiple iterations.
Terms are generated lazily, i.e. only when they are requested.
- This saves complexity, especially when using nested sequences
Sequences are enhanced by:
SequenceOf- Contains plenty of standard sequences, such as natural numbers, integers, primes, rangesFunctions- Contains anonymous functions for use with the total() methodPredicateFor- Contains predicates for use with filtering or to add conditions
Prerequisites
- Java 8
Usage
- Clone this repository onto your system
- Include the package
com.bishabosha.caffeinein your build path
Replace standard library with:
HashMapbuilt onHashTable, implementsjava.util.MapHashTableimplementsjava.util.Setand also providesterm()methodTreeMapbuilt onSearchTreeimplementsjava.util.MapAVL balancedTreeSetbuilt onSearchTreeimplementsjava.util.SetAVL balancedLinkedListimplementsjava.util.Queue,java.util.Dequeandjava.util.List
Other Collections:
SearchTreeimplementsjava.util.CollectionAVL balanced BST, pre/post/in/level-order traversalTrieSet, implementsjava.util.SetGet word completionsTrieMap, implementsjava.util.MapGet word completions and map valuesGraphextendsRelationGraph, usingRelationSet- f: node -> node
WeightedGraphextendsRelationGraph, usingWeightedRelationSet- g: node -> (node, weight)
Base Classes to Save Code:
AbstractBaseprovides basictoString(),hashCode()toArray()functionsAbstractCollectionimplementsjava.util.CollectionAbstractMapimplementsjava.util.MapIncompleteSetimplementsjava.util.Set
Introducing Sequences
SequenceGenerate generic sequences, with pipeline api for filtering with PredicatesPredicateForSpecial predicates for use with filteringSequenceOfCommon sequences and for Project EulerFunctionsCommon scalar functions to apply across the whole sequence
Special Included Classes
FiniteAutomatonpattern matching with generics- union, intersection, kleenestar, complement, concatenation
FiniteAutomatonFactorybuild automatons from wordsRelationSetimplementsRelationsimple adjacency listWeightedRelationSetimplementsWeightedRelationextendsRelation- f: node -> weight
- g: weight -> {node}
Helper Classes
IntLooploop in a range, with a specific step, used with sequencesRangevalue range with generics, used with sequencesScannerPlusFor programming challenge practise, eliminate boilerplate typing!


Log in or sign up for Devpost to join the conversation.