1cddda72410c992a12db61cef26713b498e31fea4Thanh Le/* 2cddda72410c992a12db61cef26713b498e31fea4Thanh Le * Copyright (C) 2013 DroidDriver committers 3cddda72410c992a12db61cef26713b498e31fea4Thanh Le * 4cddda72410c992a12db61cef26713b498e31fea4Thanh Le * Licensed under the Apache License, Version 2.0 (the "License"); 5cddda72410c992a12db61cef26713b498e31fea4Thanh Le * you may not use this file except in compliance with the License. 6cddda72410c992a12db61cef26713b498e31fea4Thanh Le * You may obtain a copy of the License at 7cddda72410c992a12db61cef26713b498e31fea4Thanh Le * 8cddda72410c992a12db61cef26713b498e31fea4Thanh Le * http://www.apache.org/licenses/LICENSE-2.0 9cddda72410c992a12db61cef26713b498e31fea4Thanh Le * 10cddda72410c992a12db61cef26713b498e31fea4Thanh Le * Unless required by applicable law or agreed to in writing, software 11cddda72410c992a12db61cef26713b498e31fea4Thanh Le * distributed under the License is distributed on an "AS IS" BASIS, 12cddda72410c992a12db61cef26713b498e31fea4Thanh Le * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cddda72410c992a12db61cef26713b498e31fea4Thanh Le * See the License for the specific language governing permissions and 14cddda72410c992a12db61cef26713b498e31fea4Thanh Le * limitations under the License. 15cddda72410c992a12db61cef26713b498e31fea4Thanh Le */ 16cddda72410c992a12db61cef26713b498e31fea4Thanh Le 17cddda72410c992a12db61cef26713b498e31fea4Thanh Lepackage com.google.android.droiddriver.util; 18cddda72410c992a12db61cef26713b498e31fea4Thanh Le 19cddda72410c992a12db61cef26713b498e31fea4Thanh Le/** 2017342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * Simple static methods to be called at the start of your own methods to verify 2117342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * correct arguments and state. 22cddda72410c992a12db61cef26713b498e31fea4Thanh Le */ 2317342a5115d7575d44a99fed9c7032e3ab316dccKevin Jinpublic final class Preconditions { 2417342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin private Preconditions() {} 2517342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin 2617342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin /** 2717342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * Ensures that an object reference passed as a parameter to the calling 2817342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * method is not null. 2917342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * 3017342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * @param reference an object reference 3117342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * @return the non-null reference that was validated 3217342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin * @throws NullPointerException if {@code reference} is null 3317342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin */ 3417342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin public static <T> T checkNotNull(T reference) { 3517342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin if (reference == null) { 3617342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin throw new NullPointerException(); 3717342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin } 3817342a5115d7575d44a99fed9c7032e3ab316dccKevin Jin return reference; 39cddda72410c992a12db61cef26713b498e31fea4Thanh Le } 40cddda72410c992a12db61cef26713b498e31fea4Thanh Le} 41