<commit_before>/*
 * Copyright (c) 2016 Open Baton (http://www.openbaton.org)
 *
 * 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 org.openbaton.cli.util;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.openbaton.cli.model.GeneralName;
import org.openbaton.cli.model.GeneralTarget;
import org.openbaton.cli.model.GeneralVimInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

/**
 * Created by tce on 25.08.15.
 *
 * Used to print out the results of a cli command to the console.
 */
public class PrintFormat {

  private static List<String[]> rows = new LinkedList<String[]>();
  public static Logger log = LoggerFactory.getLogger(PrintFormat.class);

  public static String printResult(String command, Object obj)
      throws InvocationTargetException, IllegalAccessException {

    List<Object> object = new ArrayList<Object>();
    rows.clear();
    String result = "";

    if (obj == null) {
      //TODO
      if (!command.contains("delete")
          && !command.contains("changePassword")
          && !command.contains("startVNFCInstance")
          && !command.contains("stopVNFCInstance")) {
        result = "Error: invalid command line";
      }
      return result;

    } else if (isCollection(obj)) {
      object = (List<Object>) obj;
    } else if (isString(obj)) {
      return (String) obj;
    } else {
      object.add((Object) obj);
    }

    if (object.size() == 0) {
      result = "Empty List";

    } else {

      result = printTables(command, object);
    }

    return result;
  }

  public static void addRow(String... cols) {
    rows.add(cols);
  }

  private static int[] colWidths() {
    int cols = -1;<commit_msg>Fix: Prevent addVNFCInstance from printing an error message even though the command succeeds<commit_after>/*
 * Copyright (c) 2016 Open Baton (http://www.openbaton.org)
 *
 * 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 org.openbaton.cli.util;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.openbaton.cli.model.GeneralName;
import org.openbaton.cli.model.GeneralTarget;
import org.openbaton.cli.model.GeneralVimInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

/**
 * Created by tce on 25.08.15.
 *
 * Used to print out the results of a cli command to the console.
 */
public class PrintFormat {

  private static List<String[]> rows = new LinkedList<String[]>();
  public static Logger log = LoggerFactory.getLogger(PrintFormat.class);

  public static String printResult(String command, Object obj)
      throws InvocationTargetException, IllegalAccessException {

    List<Object> object = new ArrayList<Object>();
    rows.clear();
    String result = "";

    if (obj == null) {
      //TODO
      if (!command.contains("delete")
          && !command.contains("changePassword")
          && !command.contains("startVNFCInstance")
          && !command.contains("stopVNFCInstance")
          && !command.contains("createVNFCInstance")) {
        result = "Error: invalid command line";
      }
      return result;

    } else if (isCollection(obj)) {
      object = (List<Object>) obj;
    } else if (isString(obj)) {
      return (String) obj;
    } else {
      object.add((Object) obj);
    }

    if (object.size() == 0) {
      result = "Empty List";

    } else {

      result = printTables(command, object);
    }

    return result;
  }

  public static void addRow(String... cols) {
    rows.add(cols);
  }

  private static int[] colWidths() {
    int cols = -1;
{'fraction_non_alphanumeric': 0.11422149570903146, 'fraction_numerical': 0.008173273395995096, 'mean_word_length': 3.3242049469964665, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2400589', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1396, 'n_words': 440}