Created
          April 29, 2009 12:47 
        
      - 
      
- 
        Save samleb/103747 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | public interface ICondition<T> { | |
| boolean isSatisfiedBy(T object); | |
| ICondition<T> negate(); | |
| ICondition<T> and(ICondition<T> other); | |
| ICondition<T> or(ICondition<T> other); | |
| } | |
| package com.maptimize.conditions; | |
| public abstract class AbstractCondition<T> implements ICondition<T> { | |
| public ICondition<T> negate() { | |
| // final ICondition<T> self = this; | |
| return new AbstractCondition<T>() { | |
| public boolean isSatisfiedBy(T object) { | |
| // Does the same thing, surprisingly | |
| return !AbstractCondition.this.isSatisfiedBy(object); | |
| } | |
| }; | |
| } | |
| public ICondition<T> and(final ICondition<T> other) { | |
| // final ICondition<T> self = this; | |
| return new AbstractCondition<T>() { | |
| public boolean isSatisfiedBy(T object) { | |
| return AbstractCondition.this.isSatisfiedBy(object) && other.isSatisfiedBy(object); | |
| } | |
| }; | |
| } | |
| public ICondition<T> or(final ICondition<T> other) { | |
| // final ICondition<T> self = this; | |
| return new AbstractCondition<T>() { | |
| public boolean isSatisfiedBy(T object) { | |
| return AbstractCondition.this.isSatisfiedBy(object) || other.isSatisfiedBy(object); | |
| } | |
| }; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment