Java Collection Null nullSafeSize(final Collection collection)

Here you can find the source of nullSafeSize(final Collection collection)

Description

null Safe Size

License

Apache License

Declaration

public static <T> int nullSafeSize(final Collection<T> collection) 

Method Source Code


//package com.java2s;
/*//  w w  w.  j a va  2 s  . c o  m
 * Copyright 2016 NAVER Corp.
 *
 * 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.
 *
 */

import java.util.Collection;

public class Main {
    public static <T> int nullSafeSize(final Collection<T> collection) {
        return nullSafeSize(collection, 0);
    }

    public static <T> int nullSafeSize(final Collection<T> collection, final int nullValue) {
        if (collection == null) {
            return nullValue;
        }
        return collection.size();
    }
}

Related

  1. nullSafe(Collection collection)
  2. nullSafe(Collection collection)
  3. nullSafe(Collection in)
  4. nullSafeCollection(Collection source)
  5. nullSafeSize(Collection collection)
  6. padWithNulls(final Collection s1, final Collection s2)
  7. removeAllIfNotNull(final Collection collection, final Collection c)
  8. removeNull(Collection collection)
  9. removeNull(final Collection c)