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

eu.stratosphere.core.testing.IteratorUtil Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * Copyright (C) 2010-2013 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.core.testing;

import java.io.IOException;
import java.util.Iterator;

/**
 * Convenience methods for working with {@link Object}s that should be used as records in Stratosphere.
 */
public class IteratorUtil {

	/**
	 * Generates a string for the {@link Object}s using the given {@link TypeStringifier}.
* This method stringifies at most 20 records.
* To exert more control over the amounts of records, use {@link #stringify(TypeStringifier, Iterator, int)}. * * @return a string representation of the records */ public static String stringify(final TypeStringifier typeStringifier, final Iterator iterator) { return stringify(typeStringifier, iterator, 20); } /** * Generates a string for the {@link Object}s using the given {@link TypeStringifier} for the first maxNum * {@link Object}s. * * @return a string representation of the records */ public static String stringify(final TypeStringifier typeStringifier, final Iterator iterator, final int maxNum) { final StringBuilder builder = new StringBuilder(); try { for (int index = 0; index < maxNum && iterator.hasNext(); index++) { typeStringifier.appendAsString(builder, iterator.next()); if (iterator.hasNext()) builder.append(", "); } } catch (final IOException e) { } if (iterator.hasNext()) builder.append("..."); return builder.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy