001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nicolas Chapurlat <nchapurlat@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.core.schema.types.constraints; 019 020import java.io.Serializable; 021import java.util.HashMap; 022import java.util.Map; 023 024/** 025 * This constraint ensure some object is not null. 026 * <p> 027 * This class is a singleton. Use {@link #get()} to get the singleton. 028 * </p> 029 * 030 * @since 7.1 031 * @author <a href="mailto:nc@nuxeo.com">Nicolas Chapurlat</a> 032 */ 033public class NotNullConstraint extends AbstractConstraint { 034 035 private static final long serialVersionUID = 1L; 036 037 private static final String NAME = "NotNullConstraint"; 038 039 // Lazy ang thread safe singleton instance. 040 private static class Holder { 041 private static final NotNullConstraint INSTANCE = new NotNullConstraint(); 042 } 043 044 private NotNullConstraint() { 045 } 046 047 public static NotNullConstraint get() { 048 return Holder.INSTANCE; 049 } 050 051 @Override 052 public boolean validate(Object object) { 053 return object != null; 054 } 055 056 /** 057 * Here, value is : <br> 058 * name = {@value #NAME}. <br> 059 * parameters is empty 060 */ 061 @Override 062 public Description getDescription() { 063 Map<String, Serializable> params = new HashMap<String, Serializable>(); 064 return new Description(NotNullConstraint.NAME, params); 065 } 066 067 @Override 068 public int hashCode() { 069 return NotNullConstraint.class.hashCode(); 070 } 071 072 @Override 073 public boolean equals(Object obj) { 074 return obj != null && obj instanceof NotNullConstraint; 075 } 076}