/*
 * Copyright (c) 2013-2018 Cinchapi Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cinchapi.common.describe;

import java.lang.reflect.Array;
import java.util.Map;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import com.cinchapi.common.base.validate.Check;

/**
 * A customizable {@link Adjective} that describes emptiness for objects.
 *
 * @author Jeff Nelson
 */
@NotThreadSafe
public class Empty extends Adjective {

    /**
     * Create an {@link Empty} instance with the default set of definitions.
     * More definitions can be added using the {@link #define(Class, Check)}
     * method.
     * 
     * @return the {@link Empty} instance
     */
    public static Empty is() {
        Empty empty = new Empty();
        empty.define(String.class, string -> string.isEmpty());
        empty.define(Iterable.class,
                iterable -> !iterable.iterator().hasNext());
        empty.define(Map.class, map -> map.isEmpty());
        return empty;
    }

    /**
     * Create an {@link Empty} instance with the provided set of
     * {@code definitions}. More definitions can be added using the
     * {@link #define(Class, Check)} method.
     * 
     * @param definitions
     * @return the {@link Empty} instance
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static Empty is(Map<Class, Check> definitions) {
        Empty empty = new Empty();
        definitions.forEach((clazz, definition) -> {
            empty.define(clazz, definition);
        });
        return empty;
    }

    private Empty() {/* no-init */}

    @Override
    public <T> boolean describes(@Nullable T object) {
        // Add logic to declare null values and 0-length arrays as empty.
        if(object == null) {
            return true;
        }
        else if(object.getClass().isArray()) {
            return Array.getLength(object) == 0;
        }
        else {
            return super.describes(object);
        }
    }

}

@@ -821,16 +821,63 @@
 e.Check;
+%0Aimport com.google.common.collect.ImmutableMap;
 %0A%0A/**%0A *
@@ -1576,24 +1576,440 @@
 pty;%0A    %7D%0A%0A
+    /**%0A     * Create an %7B@link Empty%7D instance with the %7B@code check%7D for the specified%0A     * %7B@code clazz%7D. More definitions can be added using the%0A     * %7B@link #define(Class, Check)%7D method.%0A     * %0A     * @param clazz%0A     * @param check%0A     * @return the %7B@link Empty%7D instance%0A     */%0A    public static %3CT%3E Empty is(Class%3CT%3E clazz, Check%3CT%3E check) %7B%0A        return is(ImmutableMap.of(clazz, check));%0A    %7D%0A%0A
     /**%0A    
@@ -2602,16 +2602,16 @@
 verride%0A
+
     publ
@@ -2661,82 +2661,8 @@
 ) %7B%0A
-        // Add logic to declare null values and 0-length arrays as empty.%0A
     

add new factory for Empty