All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.dev.jjs.impl.gflow.AssumptionUtil Maven / Gradle / Ivy

There is a newer version: 2.7.0.vaadin7
Show newest version
/*
 * Copyright 2009 Google Inc.
 *
 * 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 com.google.gwt.dev.jjs.impl.gflow;

import com.google.gwt.thirdparty.guava.common.base.Preconditions;

import java.util.List;

/**
 * Utilities for working with assumption values.
 */
public class AssumptionUtil {
  /**
   * Check assumptions for equality.
   */
  public static > boolean equals(A a1, A a2) {
    if (a1 == null || a2 == null) {
      return a1 == a2;
    }

    return (a1 == a2) || (a1.equals(a2));
  }

  /**
   * Join assumptions.
   */
  public static > A join(A a1, A a2) {
    if (a1 == null) {
      return a2;
    }

    if (a2 == null) {
      return a1;
    }

    return a1 != a2 ? a1.join(a2) : a1;
  }

  /**
   * Join assumptions from the list.
   */
  public static > A join(List assumptions) {
    A result = null;
    for (A assumption : assumptions) {
      result = join(result, assumption);
    }
    return result;
  }

  public static > A join(List edges,
      AssumptionMap assumptionMap) {
    A result = null;
    for (E edge : edges) {
      result = join(result, assumptionMap.getAssumption(edge));
    }
    return result;
  }

  public static > void setAssumptions(List edges,
      List assumptions, AssumptionMap assumptionMap) {
    Preconditions.checkArgument(assumptions.size() == edges.size());
    for (int i = 0; i < edges.size(); ++i) {
      assumptionMap.setAssumption(edges.get(i), assumptions.get(i));
    }
  }

  public static > void setAssumptions(List edges,
      A assumption, AssumptionMap assumptionMap) {
    for (E edge : edges) {
      assumptionMap.setAssumption(edge, assumption);
    }
  }

  public static > String toString(
      List inEdges, List outEdges,
      AssumptionMap assumptionMap) {
    StringBuilder result = new StringBuilder();
    for (E e : inEdges) {
      if (result.length() != 0) {
        result.append("; ");
      }
      result.append(e);
      result.append("=");
      result.append(assumptionMap.getAssumption(e));
    }
    for (E e : outEdges) {
      if (result.length() != 0) {
        result.append("; ");
      }
      result.append(e);
      result.append("=");
      result.append(assumptionMap.getAssumption(e));
    }
    return result.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy