Line data Source code
1 : // Copyright (C) 2020 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.acceptance.testsuite.change; 16 : 17 : import com.google.common.collect.ImmutableList; 18 : import java.util.function.Function; 19 : 20 : /** Builder to simplify specifying multiple parents for a change. */ 21 : public class MultipleParentBuilder<T> { 22 : private final Function<ImmutableList<TestCommitIdentifier>, T> parentsToBuilderAdder; 23 : private final ImmutableList.Builder<TestCommitIdentifier> parents; 24 : 25 : public MultipleParentBuilder( 26 : Function<ImmutableList<TestCommitIdentifier>, T> parentsToBuilderAdder, 27 4 : TestCommitIdentifier firstParent) { 28 4 : this.parentsToBuilderAdder = parentsToBuilderAdder; 29 4 : parents = ImmutableList.builder(); 30 4 : parents.add(firstParent); 31 4 : } 32 : 33 : /** Adds an intermediate parent. */ 34 : public ParentBuilder<MultipleParentBuilder<T>> followedBy() { 35 1 : return new ParentBuilder<>( 36 : parent -> { 37 1 : parents.add(parent); 38 1 : return this; 39 : }); 40 : } 41 : 42 : /** Adds the last parent. */ 43 : public ParentBuilder<T> and() { 44 4 : return new ParentBuilder<>( 45 4 : (parent) -> parentsToBuilderAdder.apply(parents.add(parent).build())); 46 : } 47 : }