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