Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2015 The Pennsylvania State University and the University of Wisconsin
   * Systems and Internet Infrastructure Security Laboratory
   *
   * Author: Damien Octeau
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package edu.psu.cse.siis.coal.field.transformers;
 
 import java.util.Set;
 
A field transformer, which models the influence of a statement of a single field.
 
 public class FieldTransformer implements Internable<FieldTransformer> {
   private static final Pool<FieldTransformerPOOL = new Pool<>();
 
   protected Set<Objectadd;
   protected Set<Objectremove;
   protected boolean clear;
Applies this field transformer to a edu.psu.cse.siis.coal.field.values.FieldValue.

Parameters:
fieldValue A field value.
Returns:
A field value.
 
   public FieldValue apply(FieldValue fieldValue) {
     FieldValue result;
 
     if (this. != null || (fieldValue.hasTransformerSequence() && !this.)) {
       result = new IntermediateFieldValue();
     } else {
       result = new FieldValue();
     }
 
     if (!this.) {
       result.addAll(fieldValue.getValues());
       if (fieldValue.hasTransformerSequence()) {
         ((IntermediateFieldValueresult)
             .addTransformerSequence(((IntermediateFieldValuefieldValue).getTransformerSequence());
       }
     }
 
     if (fieldValue.hasTransformerSequence() && !this.) {
       // If the field value has a non-empty transformer sequence, then we should start by
       // adding the add/remove operations to the sequence.
       FieldTransformer intermediateFieldTransformer = this.makeNonComposedFieldTransformer();
       ((IntermediateFieldValueresult).addTransformerToSequence(intermediateFieldTransformer);
     } else {
       if (this. != null) {
         result.removeAll(this.);
       }
       if (this. != null) {
         result.addAll(this.);
       }
     }
 
     if (this. != null) {
     }
 
     return result.intern();
   }

  
Composes this field transformer with another one.

Parameters:
secondFieldOperation A field transformer.
Returns:
The result of composing this field transformer with the argument transformer.
 
   public FieldTransformer compose(FieldTransformer secondFieldOperation) {
     if (secondFieldOperation.clear) {
       return secondFieldOperation;
     }
 
     FieldTransformer result = new FieldTransformer();
     result.clear = this.;
 
    // Add the values from the first operation.
    if (this. != null) {
      result.add = new HashSet<>(this.);
    }
    if (this. != null) {
      result.remove = new HashSet<>(this.);
    }
    if (this. != null) {
      result.transformerSequence = new TransformerSequence(this.);
      if (secondFieldOperation.add != null || secondFieldOperation.remove != null) {
        // The second field transformer has some add or remove
        // operation. Start by applying these.
        FieldTransformer intermediateFieldTransformer =
            secondFieldOperation.makeNonComposedFieldTransformer();
        result.transformerSequence.addTransformerToSequence(intermediateFieldTransformer);
      }
    } else {
      // Add the values from the second operation.
      if (secondFieldOperation.add != null) {
        if (result.remove != null) {
          result.remove.removeAll(secondFieldOperation.add);
        }
        if (result.add == null) {
          result.add = new HashSet<>(secondFieldOperation.add);
        } else {
          result.add.addAll(secondFieldOperation.add);
        }
      }
      if (secondFieldOperation.remove != null) {
        if (result.add != null) {
          result.add.removeAll(secondFieldOperation.remove);
        }
        if (result.remove == null) {
          result.remove = new HashSet<>(secondFieldOperation.remove);
        } else {
          result.remove.addAll(secondFieldOperation.remove);
        }
      }
    }
    if (secondFieldOperation.transformerSequence != null) {
      // If a transformer sequence is found in the second field transformer, it means that
      // the latter contains a field composition as well. We add it last.
      if (result.transformerSequence == null) {
        result.transformerSequence = new TransformerSequence();
      }
      result.transformerSequence.addElementsToSequence(secondFieldOperation.transformerSequence);
    }
    return result.intern();
  }

  
Generates a field transformer that is identical to this instance, except that it does not contain a transformer sequence.

Returns:
A field transformer without transformer sequence.
    FieldTransformer intermediateFieldTransformer = new FieldTransformer();
    intermediateFieldTransformer.add = this.;
    intermediateFieldTransformer.remove = this.;
    return intermediateFieldTransformer.intern();
  }
  public String toString() {
    return "Add " + this. + ", remove " + this. + ", clear " + this.
        + ", transformer sequence " + this.;
  }
  public int hashCode() {
    return Objects.hash(this.this.this.this.);
  }
  public boolean equals(Object other) {
    if (!(other instanceof FieldTransformer)) {
      return false;
    }
    FieldTransformer secondFieldTransformer = (FieldTransformerother;
    return Objects.equals(this.secondFieldTransformer.add)
        && Objects.equals(this.secondFieldTransformer.remove)
        && this. == secondFieldTransformer.clear
        && Objects.equals(this.secondFieldTransformer.transformerSequence);
  }
  public FieldTransformer intern() {
    return .intern(this);
  }
New to GrepCode? Check out our FAQ X