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.common.utils.Utils.*;
020import static org.apache.juneau.internal.CollectionUtils.*;
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   //-----------------------------------------------------------------------------------------------------------------
034   // Static
035   //-----------------------------------------------------------------------------------------------------------------
036
037   /**
038    * Static creator.
039    *
040    * @param args Comma-delimited list of view arguments.
041    * @return A new {@link ViewArgs} object.
042    */
043   public static ViewArgs create(String args) {
044      if (args == null) return null;
045      return new ViewArgs(args);
046   }
047
048   /**
049    * Static creator.
050    *
051    * @param args List of view arguments.
052    * @return A new {@link ViewArgs} object.
053    */
054   public static ViewArgs create(List<String> args) {
055      if (args == null) return null;
056      return new ViewArgs(args);
057   }
058
059   //-----------------------------------------------------------------------------------------------------------------
060   // Instance
061   //-----------------------------------------------------------------------------------------------------------------
062
063   private final List<String> view;
064
065   /**
066    * Constructor.
067    *
068    * @param viewArgs
069    *    View arguments.
070    *    <br>Values are column names.
071    */
072   public ViewArgs(String viewArgs) {
073      this(alist(splita(viewArgs)));
074   }
075
076   /**
077    * Constructor.
078    *
079    * @param viewArgs
080    *    View arguments.
081    *    <br>Values are column names.
082    */
083   public ViewArgs(Collection<String> viewArgs) {
084      this.view = u(listFrom(viewArgs));
085   }
086
087   /**
088    * The view columns.
089    *
090    * <p>
091    * The view columns are the list of columns that should be displayed.
092    * An empty list implies all columns should be displayed.
093    *
094    * @return An unmodifiable list of columns to view.
095    */
096   public List<String> getView() {
097      return view;
098   }
099}