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

br.com.objectos.way.base.io.Stdout Maven / Gradle / Ivy

/*
 * Copyright 2013 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.way.base.io;

import java.util.List;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

/**
 * @author [email protected] (Marcio Endo)
 */
public class Stdout {

  private Stdout() {
  }

  public static void print(HasStdout stdout) {
    List exceptions = stdout.getExceptions();
    for (Exception e : exceptions) {
      System.out.println(e.getMessage());
    }

    List msgs = stdout.stdout();
    for (String msg : msgs) {
      System.out.println(msg);
    }
  }

  public static List concatExceptions(Iterable iterable) {
    Iterable> exs = Iterables.transform(iterable, ToExceptions.INSTANCE);
    Iterable concat = Iterables.concat(exs);
    return ImmutableList.copyOf(concat);
  }

  public static List concatStdout(Iterable iterable) {
    Iterable> msgs = Iterables.transform(iterable, ToStdout.INSTANCE);
    Iterable concat = Iterables.concat(msgs);
    return ImmutableList.copyOf(concat);
  }

  private static enum ToExceptions implements Function> {
    INSTANCE;
    @Override
    public List apply(HasStdout input) {
      return input.getExceptions();
    }
  }

  private static enum ToStdout implements Function> {
    INSTANCE;
    @Override
    public List apply(HasStdout input) {
      return input.stdout();
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy