https://github.com/d-plaindoux/suitcase
Java Pattern Matching library
https://github.com/d-plaindoux/suitcase
pattern-matching
Last synced: 7 months ago
JSON representation
Java Pattern Matching library
- Host: GitHub
- URL: https://github.com/d-plaindoux/suitcase
- Owner: d-plaindoux
- License: lgpl-2.1
- Archived: true
- Created: 2013-06-11T19:38:48.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2023-11-09T02:29:56.000Z (over 2 years ago)
- Last Synced: 2025-02-13T16:23:26.025Z (over 1 year ago)
- Topics: pattern-matching
- Language: Java
- Homepage:
- Size: 722 KB
- Stars: 21
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SuitCase
Note: With Java 21+ this project is finally obsolete!
[](https://coveralls.io/r/d-plaindoux/suitcase)
[](http://search.maven.org/#artifactdetails%7Corg.smallibs%7Csuitcase%7C0.3%7Cjar)
[](http://github.com/badges/stability-badges)
SuitCase is a convenient Java library dedicated to object manipulation using `pattern matching` mechanism.
## Quick Overview
If you want to manipulate object based on types in Java the dedicated design pattern is the visitor.
Unfortunately even if such pattern is well known its implementation is always painful because it implies
code dissemination and finally brakes incremental compilation approach.
In addition such mechanism only enables selection based on types and does not provides a simple and
intuitive mechanism filtering objects using their values i.e. attributes.
For this purpose a simple pattern matching inspired by Scala
[extractor object](http://docs.scala-lang.org/tutorials/tour/extractor-objects.html) has been designed.
This pattern matching offers a simple mechanism for simple object selection based on intrinsic equality.
Indeed pattern matching cases can be done on the object kind and it's internal state. For instance the following
sample checks if an integer is O or not.
``` java
Matcher isZero = Matcher.match();
isZero.caseOf(0).then(true);
isZero.caseOf(Any()).then(false);
isZero.match(0); // == true
```
## Regexp, List Patterns and more ...
More information and descriptions are given in the [Wiki](https://github.com/d-plaindoux/suitcase/wiki) and in
particular ad-hoc case is explained with practical implementations covering matching for lists, string regular
expression, XML etc.
## Releases
This library is available at Sonatype OSS Repository Hosting service and can be simply used adding the following
dependency to your pom project.
```
org.smallibs
suitcase
0.3
```
## Presentation
A [presentation (in french)](http://www.slideshare.net/dplaindoux/java-amp-le-pattern-matching-54806648) has been given
during a [Toulouse Java User Group](http://toulousejug.org) session.
## Other Propositions & Discussions
A review of various approaches is given in the [Structural Pattern Matching in Java](http://blog.higher-order.com/blog/2009/08/21/structural-pattern-matching-in-java/).
It starts from the visitor and proposes alternatives with a functional programming approach.
Some propositions like [Towards Pattern Matching in Java](http://kerflyn.wordpress.com/2012/05/09/towards-pattern-matching-in-java/)
or [Java 8 annotation processor and framework](https://github.com/derive4j/derive4j) for deriving algebraic data types constructors,
pattern-matching, morphisms are also available.
## License
Copyright (C)2015 D. Plaindoux.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; see the file COPYING. If not, write
to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
USA.