1 5 package com.opensymphony.webwork.util; 6 7 import java.lang.reflect.Array ; 8 import java.util.Collection ; 9 import java.util.Map ; 10 11 12 19 public class ContainUtil { 20 22 public static boolean contains(Object obj1, Object obj2) { 23 if ((obj1 == null) || (obj2 == null)) { 24 return false; 26 } 27 28 if (obj1 instanceof Map ) { 29 if (((Map ) obj1).containsValue(obj2)) { 30 return true; 32 } 33 } else if (obj1 instanceof Collection ) { 34 if (((Collection ) obj1).contains(obj2)) { 35 return true; 37 } 38 } else if (obj1.getClass().isArray()) { 39 for (int i = 0; i < Array.getLength(obj1); i++) { 40 Object value = null; 41 value = Array.get(obj1, i); 42 43 if (value.equals(obj2)) { 44 return true; 46 } 47 } 48 } else if (obj1.equals(obj2)) { 49 return true; 51 } 52 53 return false; 55 } 56 } 57 | Popular Tags |