001/** 002 * Copyright (C) 2016 Gary Gregory. All rights reserved. 003 * 004 * See the NOTICE.txt file distributed with this work for additional 005 * information regarding copyright ownership. 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package com.garygregory.jcommander.converters.nio.file.attribute; 021 022import java.nio.file.attribute.PosixFilePermission; 023import java.nio.file.attribute.PosixFilePermissions; 024import java.util.Set; 025 026import com.garygregory.jcommander.converters.AbstractBaseConverter; 027 028/** 029 * Converts a {@link String} into a {@link Set} of {@link PosixFilePermission}. 030 * <p> 031 * For a description of the format, see {@link PosixFilePermissions#fromString(String)}. 032 * </p> 033 * 034 * <p> 035 * Example: 036 * </p> 037 * 038 * <pre class="prettyprint"> 039 * <code class="language-java">@Parameter(names = { "--posixFilePermissions" }, converter = PosixFilePermissionSetConverter.class) 040 * private Set<PosixFilePermission> posixFilePermissions;</code> 041 * </pre> 042 * <p> 043 * 044 * @see PosixFilePermission 045 * @see PosixFilePermissions#fromString(String) 046 * 047 * @since 1.0.0 048 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a> 049 */ 050@SuppressWarnings("rawtypes") 051public class PosixFilePermissionSetConverter extends AbstractBaseConverter<Set> { 052 053 /** 054 * Constructs a converter. 055 * 056 * @param optionName 057 * The option name, may be null. 058 */ 059 public PosixFilePermissionSetConverter(final String optionName) { 060 super(optionName, Set.class); 061 } 062 063 @Override 064 protected Set<PosixFilePermission> convertImpl(final String value) { 065 return PosixFilePermissions.fromString(value); 066 } 067 068}