1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.common
.core
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
19 * Utility methods to handle {@link org.eclipse.jdt.annotation.NonNull}
22 * @author Alexandre Montplaisir
24 public final class NonNullUtils
{
26 private NonNullUtils() {}
29 * Returns a non-null {@link String} for a potentially null object. This
30 * method calls {@link Object#toString()} if the object is not null, or
31 * returns an empty string otherwise.
34 * A {@link Nullable} object that we want converted to a string
35 * @return The non-null string
37 public static String
nullToEmptyString(@Nullable Object obj
) {
39 return ""; //$NON-NLS-1$
41 String str
= obj
.toString();
42 return (str
== null ?
"" : str
); //$NON-NLS-1$
46 * Convert a non-annotated object reference to a {@link NonNull} one.
48 * If the reference is actually null, a {@link NullPointerException} is
49 * thrown. This is usually more desirable than letting an unwanted null
50 * reference go through and fail much later.
53 * The object that is supposed to be non-null
54 * @return A {@link NonNull} reference to the same object
55 * @throws NullPointerException
56 * If the reference was actually null
58 public static <T
> T
checkNotNull(@Nullable T obj
) {
60 throw new NullPointerException();
This page took 0.032308 seconds and 5 git commands to generate.