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.isis.core.progmodel.facets.param.autocomplete; 018 019import java.lang.annotation.Annotation; 020import java.lang.reflect.Method; 021 022import org.apache.isis.applib.annotation.MinLength; 023 024public class MinLengthUtil { 025 026 /** 027 * Finds the value of the {@link MinLength} annotation on the first parameter of the 028 * supplied method. 029 */ 030 public static int determineMinLength(final Method method) { 031 final Annotation[][] parameterAnnotations = method.getParameterAnnotations(); 032 if(parameterAnnotations.length == 1) { 033 final Annotation[] searchArgAnnotations = parameterAnnotations[0]; 034 for(Annotation annotation: searchArgAnnotations) { 035 if(annotation instanceof MinLength) { 036 MinLength minLength = (MinLength) annotation; 037 return minLength.value(); 038 } 039 } 040 } 041 return MinLengthUtil.MIN_LENGTH_DEFAULT; 042 } 043 044 public static final int MIN_LENGTH_DEFAULT = 1; 045 046 047 048}