1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.jittester; 25 26 import java.util.ArrayList; 27 import java.util.Collection; 28 import java.util.Iterator; 29 import java.util.List; 30 31 32 public class TypeUtil { 33 34 public static Collection<Type> getImplicitlyCastable(Collection<Type> types, Type type) { 35 ArrayList<Type> result = new ArrayList<>(types); 36 Iterator<Type> iterator = result.iterator(); 37 while (iterator.hasNext()) { 38 if (!iterator.next().canImplicitlyCastTo(type)) { 39 iterator.remove(); 40 } 41 } 42 return result; 43 } 44 45 public static Collection<Type> getExplicitlyCastable(Collection<Type> types, Type type) { 46 ArrayList<Type> result = new ArrayList<>(types); 47 Iterator<Type> iterator = result.iterator(); 48 while (iterator.hasNext()) { 49 if (!iterator.next().canExplicitlyCastTo(type)) { 50 iterator.remove(); 51 } 52 } 53 return result; 54 } 55 56 public static List<Type> getMoreCapatiousThan(Collection<Type> types, BuiltInType type) { 57 ArrayList<Type> result = new ArrayList<>(); 58 Iterator<Type> iterator = types.iterator(); 59 while (iterator.hasNext()) { 60 try { 61 BuiltInType builtInType = (BuiltInType) iterator.next(); 62 if (builtInType.isMoreCapaciousThan(type)) { 63 result.add(builtInType); 64 } 65 } catch (Exception e) { 66 } 67 } 68 return result; 69 } 70 71 public static List<Type> getLessCapatiousOrEqualThan(Collection<Type> types, BuiltInType type) { 72 ArrayList<Type> result = new ArrayList<>(); 73 Iterator<Type> iterator = types.iterator(); 74 while (iterator.hasNext()) { 75 try { 76 BuiltInType builtInType = (BuiltInType) iterator.next(); 77 if (!builtInType.isMoreCapaciousThan(type) || builtInType.equals(type)) { 78 result.add(builtInType); 79 } 80 } catch (Exception e) { 81 } 82 } 83 return result; 84 } 85 }