#677 init folder for pattern trampoline
This commit is contained in:
parent
09c0891948
commit
b61b64073a
2
trampoline/.gitignore
vendored
Normal file
2
trampoline/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target/
|
||||
.idea/
|
38
trampoline/README.md
Normal file
38
trampoline/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
---
|
||||
layout: pattern
|
||||
title: Trampoline
|
||||
folder: trampoline
|
||||
permalink: /patterns/trampoline/
|
||||
categories: Behavior
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Performance
|
||||
- Recursion
|
||||
---
|
||||
|
||||
## Intent
|
||||
By representing a computation in one of 2 states
|
||||
(completed with result, or a reference to the reminder of the computation,
|
||||
something like the way a java.util.Supplier does)
|
||||
it is possible to implement algorithms recursively in Java without blowing the stack
|
||||
and to interleave the execution of functions without hard coding them together or even using threads.
|
||||
|
||||
|
||||
|
||||
## Applicability
|
||||
Use the Trampoline pattern when
|
||||
|
||||
* For implementing tail recursive function. This pattern allows to switch on a stackless operation.
|
||||
* For to interleaving the execution of two or more functions on the same thread.
|
||||
|
||||
## Known uses(real world examples)
|
||||
* Trampoline refers to using reflection to avoid using inner classes, for example in event listeners.
|
||||
The time overhead of a reflection call is traded for the space overhead of an inner class.
|
||||
Trampolines in Java usually involve the creation of a GenericListener to pass events to an outer class.
|
||||
|
||||
## Credits
|
||||
|
||||
* [Trampolining: a practical guide for awesome Java Developers](https://medium.com/@johnmcclean/trampolining-a-practical-guide-for-awesome-java-developers-4b657d9c3076)
|
||||
* [Trampoline in java ](http://mindprod.com/jgloss/trampoline.html)
|
||||
|
67
trampoline/pom.xml
Normal file
67
trampoline/pom.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<version>1.19.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>trampoline</artifactId>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19</version>
|
||||
<configuration>
|
||||
<skipTests>false</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,4 @@
|
||||
package com.iluwatar.trampoline;
|
||||
|
||||
public class App {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user