001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.objecttools;
018
019import static org.apache.juneau.commons.utils.CollectionUtils.*;
020import static org.apache.juneau.commons.utils.StringUtils.*;
021
022import java.util.*;
023
024/**
025 * Arguments passed to {@link ObjectViewer}.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ObjectTools">Object Tools</a>
029 * </ul>
030 */
031public class ViewArgs {
032   /**
033    * Static creator.
034    *
035    * @param args List of view arguments.
036    * @return A new {@link ViewArgs} object.
037    */
038   public static ViewArgs create(List<String> args) {
039      if (args == null)
040         return null;
041      return new ViewArgs(args);
042   }
043
044   /**
045    * Static creator.
046    *
047    * @param args Comma-delimited list of view arguments.
048    * @return A new {@link ViewArgs} object.
049    */
050   public static ViewArgs create(String args) {
051      if (args == null)
052         return null;
053      return new ViewArgs(args);
054   }
055
056   private final List<String> view;
057
058   /**
059    * Constructor.
060    *
061    * @param viewArgs
062    *    View arguments.
063    *    <br>Values are column names.
064    */
065   public ViewArgs(Collection<String> viewArgs) {
066      this.view = u(toList(viewArgs));
067   }
068
069   /**
070    * Constructor.
071    *
072    * @param viewArgs
073    *    View arguments.
074    *    <br>Values are column names.
075    */
076   public ViewArgs(String viewArgs) {
077      this(l(splita(viewArgs)));
078   }
079
080   /**
081    * The view columns.
082    *
083    * <p>
084    * The view columns are the list of columns that should be displayed.
085    * An empty list implies all columns should be displayed.
086    *
087    * @return An unmodifiable list of columns to view.
088    */
089   public List<String> getView() { return view; }
090}