blob: fe05ed70f0913994d24cbbb89ae564b5c1c5ec64 [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Henry Yu4b4a7eb2016-11-09 20:07:53 -05003 *
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 */
16package org.onosproject.tetopology.management.api;
17
18import com.google.common.collect.Lists;
19
20import java.util.Collection;
21import java.util.List;
22
23/**
24 * TE utility functions.
25 */
26public final class TeUtils {
27
28 // no instantiation
29 private TeUtils() {
30 }
31
32 /**
33 * Returns true if the given collection is empty; false otherwise.
34 *
35 * @param c the given collection
36 * @return true or false
37 */
38 public static boolean nonEmpty(Collection<?> c) {
39 return c != null && !c.isEmpty();
40 }
41
42 /**
43 * Adds a given element to a given list. If element is null, the
44 * given list is returned without modification. If the list is null,
45 * the function will instantiate and return a new list.
46 *
47 * @param list the given list
48 * @param element the given list element
49 * @param <T> the element type
50 * @return the resulting list
51 */
52 public static <T> List<T> addListElement(List<T> list, T element) {
53 if (element == null) {
54 return list;
55 }
56
57 List<T> result = (list == null) ? Lists.newArrayList() : list;
58
59 result.add(element);
60
61 return result;
62 }
63}