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.time; 021 022import java.time.YearMonth; 023 024import com.garygregory.jcommander.converters.AbstractBaseConverter; 025 026/** 027 * Converts a {@link String} into a {@link YearMonth}. 028 * <p> 029 * For a description of the format, see {@link YearMonth#parse(CharSequence)}. 030 * </p> 031 * 032 * <p> 033 * Example: 034 * </p> 035 * 036 * <pre class="prettyprint"> 037 * <code class="language-java">@Parameter(names = { "--yearMonth" }, converter = YearMonthConverter.class) 038 * private YearMonth yearMonth;</code> 039 * </pre> 040 * <p> 041 * 042 * @see YearMonth 043 * @see YearMonth#parse(CharSequence) 044 * 045 * @since 1.0.0 046 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a> 047 */ 048public class YearMonthConverter extends AbstractBaseConverter<YearMonth> { 049 050 /** 051 * Constructs a converter. 052 * 053 * @param optionName 054 * The option name, may be null. 055 */ 056 public YearMonthConverter(final String optionName) { 057 super(optionName, YearMonth.class); 058 } 059 060 @Override 061 protected YearMonth convertImpl(final String value) { 062 return YearMonth.parse(value); 063 } 064 065}