1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18package org.apache.giraph.block_app.framework.block;
1920import java.util.Arrays;
21import java.util.Iterator;
22import java.util.List;
2324import org.apache.giraph.block_app.framework.piece.AbstractPiece;
25import org.apache.giraph.function.Consumer;
2627import com.google.common.collect.Iterables;
2829/**30 * Block that executes provided blocks sequentially.31 */32 @SuppressWarnings("rawtypes")
33publicfinalclassSequenceBlockimplementsBlock {
34privatefinalBlock[] blocks;
3536publicSequenceBlock(Block... blocks) {
37this.blocks = blocks.clone();
38 }
3940publicSequenceBlock(List<? extends Block> blocks) {
41this.blocks = blocks.toArray(newBlock[blocks.size()]);
42 }
4344 @Override
45public Iterator<AbstractPiece> iterator() {
46return Iterables.concat(Arrays.asList(blocks)).iterator();
47 }
4849 @Override
50publicvoid forAllPossiblePieces(Consumer<AbstractPiece> consumer) {
51for (Block block : blocks) {
52 block.forAllPossiblePieces(consumer);
53 }
54 }
5556 @Override
57publicPieceCount getPieceCount() {
58PieceCount ret = newPieceCount(0);
59for (Block block : blocks) {
60 ret.add(block.getPieceCount());
61 }
62return ret;
63 }
6465 @Override
66public String toString() {
67return"SequenceBlock" + Arrays.toString(blocks);
68 }
69 }