-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...2-cdi/src/main/java/cz/muni/fi/pv243/lesson02/factorial/CacheAwareFactorialDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cz.muni.fi.pv243.lesson02.factorial; | ||
|
||
import java.math.BigInteger; | ||
|
||
import javax.decorator.Decorator; | ||
import javax.decorator.Delegate; | ||
import javax.enterprise.inject.Any; | ||
import javax.inject.Inject; | ||
|
||
/** | ||
* Decorator that checks the {@link FactorialCache} before initiating computation. If the result is found in cache, it is | ||
* returned. | ||
* | ||
* @author Jozef Hartinger | ||
* | ||
*/ | ||
@Decorator | ||
public class CacheAwareFactorialDecorator implements Factorial { | ||
|
||
@Inject | ||
@Delegate | ||
@Any | ||
private Factorial delegate; | ||
|
||
@Inject | ||
private FactorialCache cache; | ||
|
||
@Override | ||
public BigInteger compute(long number) { | ||
BigInteger result = cache.get(number); | ||
if (result == null) { | ||
result = delegate.compute(number); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters