001package org.gwtbootstrap3.client.ui.form.validator; 002 003import java.util.Collection; 004 005import org.gwtbootstrap3.client.ui.form.validator.ValidationMessages.Keys; 006 007/* 008 * #%L 009 * GwtBootstrap3 010 * %% 011 * Copyright (C) 2015 GwtBootstrap3 012 * %% 013 * Licensed under the Apache License, Version 2.0 (the "License"); 014 * you may not use this file except in compliance with the License. 015 * You may obtain a copy of the License at 016 * 017 * http://www.apache.org/licenses/LICENSE-2.0 018 * 019 * Unless required by applicable law or agreed to in writing, software 020 * distributed under the License is distributed on an "AS IS" BASIS, 021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 022 * See the License for the specific language governing permissions and 023 * limitations under the License. 024 * #L% 025 */ 026 027/** 028 * Validator for blank field validation. 029 * 030 * @param <T> the generic type 031 * @author Steven Jardine 032 */ 033public class BlankValidator<T> extends AbstractValidator<T> { 034 035 /** 036 * Constructor. 037 */ 038 public BlankValidator() { 039 super(Keys.BLANK, new Object[0]); 040 } 041 042 /** 043 * Constructor. 044 * 045 * @param invalidMessageOverride the invalid message override 046 */ 047 public BlankValidator(String invalidMessageOverride) { 048 super(invalidMessageOverride); 049 } 050 051 /** {@inheritDoc} */ 052 @Override 053 public int getPriority() { 054 return Priority.LOWEST; 055 } 056 057 /** {@inheritDoc} */ 058 @Override 059 public boolean isValid(T value) { 060 if (value instanceof Collection<?>) { return ((Collection<?>) value).size() > 0; } 061 return value != null && !"".equals(value.toString()); 062 } 063 064}