Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Sonatype Nexus (TM) Open Source Version
   * Copyright (c) 2008-2015 Sonatype, Inc.
   * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
   *
   * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
   * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
   *
   * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
  * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
  * Eclipse Foundation. All other trademarks are the property of their respective owners.
  */
 package org.sonatype.nexus.plugins.capabilities.support.condition;
 
 import  javax.inject.Inject;
 import  javax.inject.Named;
 import  javax.inject.Singleton;
 
 import  org.sonatype.sisu.goodies.eventbus.EventBus;
 
 import static com.google.common.base.Preconditions.checkNotNull;

Factory of logical Conditions.

Since:
capabilities 2.0
 
 @Named
 @Singleton
 public class LogicalConditions
 {
 
   private final EventBus eventBus;
 
   @Inject
   public LogicalConditions(final EventBus eventBus) {
     this. = checkNotNull(eventBus);
   }

  
Creates a new condition that is satisfied when both conditions are satisfied (logical AND).

Parameters:
conditions to be AND-ed
Returns:
created condition
 
   public Condition and(final Condition... conditions) {
     return new ConjunctionCondition(conditions);
   }

  
Creates a new condition that is satisfied when at least one condition is satisfied (logical OR).

Parameters:
conditions to be OR-ed
Returns:
created condition
 
   public Condition or(final Condition... conditions) {
     return new DisjunctionCondition(conditions);
   }

  
Creates a new condition that is satisfied when at another condition is not satisfied (logical NOT).

Parameters:
condition negated condition
Returns:
created condition
 
   public Condition not(final Condition condition) {
     return new InversionCondition(condition);
   }

  
A condition that applies a logical AND between conditions.

Since:
capabilities 2.0
 
   private static class ConjunctionCondition
       extends CompositeConditionSupport
       implements Condition
   {
 
     private Condition lastNotSatisfied;
 
     public ConjunctionCondition(final EventBus eventBus,
                                 final Condition... conditions)
     {
       super(eventBusconditions);
     }
 
     @Override
     protected boolean reevaluate(final Condition... conditions) {
       for (final Condition condition : conditions) {
         if (!condition.isSatisfied()) {
            = condition;
           return false;
         }
       }
        = null;
       return true;
    }
    @Override
    public String toString() {
      final StringBuilder sb = new StringBuilder();
      for (final Condition condition : getConditions()) {
        if (sb.length() > 0) {
          sb.append(" AND ");
        }
        sb.append(condition);
      }
      return sb.toString();
    }
    @Override
    public String explainSatisfied() {
      final StringBuilder sb = new StringBuilder();
      for (final Condition condition : getConditions()) {
        if (sb.length() > 0) {
          sb.append(" AND ");
        }
        sb.append(condition.explainSatisfied());
      }
      return sb.toString();
    }
    @Override
    public String explainUnsatisfied() {
      if ( != null) {
        return .explainUnsatisfied();
      }
      final StringBuilder sb = new StringBuilder();
      for (final Condition condition : getConditions()) {
        if (sb.length() > 0) {
          sb.append(" OR ");
        }
        sb.append(condition.explainUnsatisfied());
      }
      return sb.toString();
    }
  }

  
A condition that applies a logical OR between conditions.

Since:
capabilities 2.0
  private static class DisjunctionCondition
      extends CompositeConditionSupport
      implements Condition
  {
    private Condition lastSatisfied;
    public DisjunctionCondition(final EventBus eventBus,
                                final Condition... conditions)
    {
      super(eventBusconditions);
    }
    @Override
    protected boolean reevaluate(final Condition... conditions) {
      for (final Condition condition : conditions) {
        if (condition.isSatisfied()) {
           = condition;
          return true;
        }
      }
       = null;
      return false;
    }
    @Override
    public String toString() {
      final StringBuilder sb = new StringBuilder();
      for (final Condition condition : getConditions()) {
        if (sb.length() > 0) {
          sb.append(" OR ");
        }
        sb.append(condition);
      }
      return sb.toString();
    }
    @Override
    public String explainSatisfied() {
      if ( != null) {
        return .explainSatisfied();
      }
      final StringBuilder sb = new StringBuilder();
      for (final Condition condition : getConditions()) {
        if (sb.length() > 0) {
          sb.append(" OR ");
        }
        sb.append(condition.explainSatisfied());
      }
      return sb.toString();
    }
    @Override
    public String explainUnsatisfied() {
      final StringBuilder sb = new StringBuilder();
      for (final Condition condition : getConditions()) {
        if (sb.length() > 0) {
          sb.append(" AND ");
        }
        sb.append(condition.explainUnsatisfied());
      }
      return sb.toString();
    }
  }
New to GrepCode? Check out our FAQ X