Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.support.annotation.NonNull;

import java.math.BigDecimal;

import java.util.Collections;
import java.util.List;

public class Main {
    public static final String[] EMPTY_STRING_ARRAY = new String[0];
    public static final long[] EMPTY_LONG_ARRAY = new long[0];
    public static final int[] EMPTY_INT_ARRAY = new int[0];
    public static final String EMPTY_STRING = "";
    private static final long EMPTY_LONG = 0L;
    private static final Integer EMPTY_INTEGER = 0;

    @NonNull
    public static <T> T getNonNull(T value, @NonNull T ifNullValue) {
        return value == null ? ifNullValue : value;
    }

    @NonNull
    public static <T> List<T> getNonNull(List<T> value) {
        return value == null ? Collections.emptyList() : value;
    }

    public static long getNonNull(Long value) {
        return getNonNull(value, EMPTY_LONG);
    }

    public static int getNonNull(Integer value) {
        return getNonNull(value, EMPTY_INTEGER);
    }

    @NonNull
    public static String getNonNull(String value) {
        return getNonNull(value, EMPTY_STRING);
    }

    @NonNull
    public static long[] getNonNull(long[] value) {
        return getNonNull(value, EMPTY_LONG_ARRAY);
    }

    @NonNull
    public static String[] getNonNull(String[] value) {
        return getNonNull(value, EMPTY_STRING_ARRAY);
    }

    @NonNull
    public static int[] getNonNull(int[] value) {
        return getNonNull(value, EMPTY_INT_ARRAY);
    }

    @NonNull
    public static BigDecimal getNonNull(BigDecimal value) {
        return getNonNull(value, BigDecimal.ZERO);
    }

    public static CharSequence getNonNull(CharSequence charSequence) {
        return charSequence == null ? EMPTY_STRING : charSequence;
    }
}