1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.service.measurement.util; 18 19 import android.net.Uri; 20 21 import java.util.Collection; 22 23 /** 24 * Validations for the Measurement PPAPI module. 25 */ 26 public final class Validation { 27 /** 28 * @throws IllegalArgumentException if one of the parameters is null. 29 */ validateNonNull(Object... objects)30 public static void validateNonNull(Object... objects) throws IllegalArgumentException { 31 for (Object o : objects) { 32 if (o == null) { 33 throw new IllegalArgumentException("Received null values"); 34 } 35 } 36 } 37 38 /** 39 * @throws IllegalArgumentException if one of the parameters is an empty collection. 40 */ validateNotEmpty(Collection... collections)41 public static void validateNotEmpty(Collection... collections) throws IllegalArgumentException { 42 for (Collection c : collections) { 43 if (c.isEmpty()) { 44 throw new IllegalArgumentException("Received an empty collection"); 45 } 46 } 47 } 48 49 /** 50 * @throws IllegalArgumentException if one of the Uri parameters is null or has no scheme. 51 */ validateUri(Uri... uris)52 public static void validateUri(Uri... uris) throws IllegalArgumentException { 53 for (Uri uri : uris) { 54 if (uri == null || uri.getScheme() == null) { 55 throw new IllegalArgumentException("Uri with no scheme is not valid"); 56 } 57 } 58 } 59 } 60