View Javadoc
1   /**
2    *  Copyright (C) 2016 Gary Gregory. All rights reserved.
3    *
4    *  See the NOTICE.txt file distributed with this work for additional
5    *  information regarding copyright ownership.
6    *  
7    *  Licensed under the Apache License, Version 2.0 (the "License");
8    *  you may not use this file except in compliance with the License.
9    *  You may obtain a copy of the License at
10   *  
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *  
13   *  Unless required by applicable law or agreed to in writing, software
14   *  distributed under the License is distributed on an "AS IS" BASIS,
15   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *  See the License for the specific language governing permissions and
17   *  limitations under the License.
18   */
19  
20  package com.garygregory.jcommander.converters.nio.file.attribute;
21  
22  import java.nio.file.attribute.PosixFilePermission;
23  import java.nio.file.attribute.PosixFilePermissions;
24  import java.util.Set;
25  
26  import com.garygregory.jcommander.converters.AbstractBaseConverter;
27  
28  /**
29   * Converts a {@link String} into a {@link Set} of {@link PosixFilePermission}.
30   * <p>
31   * For a description of the format, see {@link PosixFilePermissions#fromString(String)}.
32   * </p>
33   * 
34   * <p>
35   * Example:
36   * </p>
37   * 
38   * <pre class="prettyprint">
39   * <code class="language-java">&#64;Parameter(names = { "--posixFilePermissions" }, converter = PosixFilePermissionSetConverter.class)
40   * private Set&lt;PosixFilePermission&gt; posixFilePermissions;</code>
41   * </pre>
42   * <p>
43   * 
44   * @see PosixFilePermission
45   * @see PosixFilePermissions#fromString(String)
46   * 
47   * @since 1.0.0
48   * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a>
49   */
50  @SuppressWarnings("rawtypes")
51  public class PosixFilePermissionSetConverter extends AbstractBaseConverter<Set> {
52  
53      /**
54       * Constructs a converter.
55       * 
56       * @param optionName
57       *            The option name, may be null.
58       */
59      public PosixFilePermissionSetConverter(final String optionName) {
60          super(optionName, Set.class);
61      }
62  
63      @Override
64      protected Set<PosixFilePermission> convertImpl(final String value) {
65          return PosixFilePermissions.fromString(value);
66      }
67  
68  }