package com.google.copybara.util;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import java.nio.file.Path;
import java.nio.file.PathMatcher;

/**
 * A glob that is the union of two globs. It matches if any of the two globs matches.
 */
public class UnionGlob extends Glob {

  private final Glob lval;
  private final Glob rval;

  UnionGlob(Glob lval, Glob rval) {
    this.lval = Preconditions.checkNotNull(lval);
    this.rval = Preconditions.checkNotNull(rval);
  }

  @Override
  public PathMatcher relativeTo(Path base) {
    PathMatcher leftMatcher = lval.relativeTo(base);
    PathMatcher rightMatcher = rval.relativeTo(base);
    return path -> leftMatcher.matches(path) || rightMatcher.matches(path);
  }

  @Override
  public ImmutableSet<String> roots() {
    return computeRootsFromIncludes(getIncludes());
  }

  @Override
  protected Iterable<String> getIncludes() {
    return Iterables.concat(lval.getIncludes(), rval.getIncludes());
  }

  @Override
  public String toString() {
    return lval + " + " + rval;
  }
}

@@ -1,8 +1,604 @@
+/*%0A * Copyright (C) 2016 Google Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 

Add missing license