eu.stratosphere.sopremo.operator.PactBuilderUtil.java Source code

Java tutorial

Introduction

Here is the source code for eu.stratosphere.sopremo.operator.PactBuilderUtil.java

Source

/***********************************************************************************************************************
 *
 * Copyright (C) 2010 by the Stratosphere project (http://stratosphere.eu)
 *
 * 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 eu.stratosphere.sopremo.operator;

import com.google.common.base.Preconditions;

import eu.stratosphere.pact.common.contract.CoGroupContract;
import eu.stratosphere.pact.common.contract.MatchContract;
import eu.stratosphere.pact.common.contract.ReduceContract;
import eu.stratosphere.pact.common.type.Key;

/**
 * Some convenience methods for dealing with the PACT-Builder pattern.
 * 
 * @author Aljoscha Krettek
 */
public class PactBuilderUtil {
    public static void addKeys(ReduceContract.Builder builder, Class<? extends Key>[] keyClasses,
            int[] keyIndices) {
        Preconditions.checkArgument(keyClasses.length == keyIndices.length,
                "Lenght of keyClasses and keyIndices must match.");
        for (int i = 0; i < keyClasses.length; ++i) {
            builder.keyField(keyClasses[i], keyIndices[i]);
        }
    }

    public static void addKeys(CoGroupContract.Builder builder, Class<? extends Key>[] keyClasses,
            int[] keyIndices1, int[] keyIndices2) {
        Preconditions.checkArgument(
                keyClasses.length == keyIndices1.length && keyClasses.length == keyIndices2.length,
                "Lenght of keyClasses and keyIndices must match.");
        for (int i = 0; i < keyClasses.length; ++i) {
            builder.keyField(keyClasses[i], keyIndices1[i], keyIndices2[i]);
        }
    }

    public static void addKeysExceptFirst(CoGroupContract.Builder builder, Class<? extends Key>[] keyClasses,
            int[] keyIndices1, int[] keyIndices2) {
        Preconditions.checkArgument(
                keyClasses.length == keyIndices1.length && keyClasses.length == keyIndices2.length,
                "Lenght of keyClasses and keyIndices must match.");
        for (int i = 1; i < keyClasses.length; ++i) {
            builder.keyField(keyClasses[i], keyIndices1[i], keyIndices2[i]);
        }
    }

    public static void addKeys(MatchContract.Builder builder, Class<? extends Key>[] keyClasses, int[] keyIndices1,
            int[] keyIndices2) {
        Preconditions.checkArgument(
                keyClasses.length == keyIndices1.length && keyClasses.length == keyIndices2.length,
                "Lenght of keyClasses and keyIndices must match.");
        for (int i = 0; i < keyClasses.length; ++i) {
            builder.keyField(keyClasses[i], keyIndices1[i], keyIndices2[i]);
        }
    }

    public static void addKeysExceptFirst(MatchContract.Builder builder, Class<? extends Key>[] keyClasses,
            int[] keyIndices1, int[] keyIndices2) {
        Preconditions.checkArgument(
                keyClasses.length == keyIndices1.length && keyClasses.length == keyIndices2.length,
                "Lenght of keyClasses and keyIndices must match.");
        for (int i = 1; i < keyClasses.length; ++i) {
            builder.keyField(keyClasses[i], keyIndices1[i], keyIndices2[i]);
        }
    }
}