001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2007-2011 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.util; 011 012import mondrian.olap.Util; 013 014import java.lang.reflect.Method; 015import java.math.BigDecimal; 016import java.sql.Statement; 017import java.util.Set; 018import java.util.Timer; 019 020/** 021 * Interface containing methods which are implemented differently in different 022 * versions of the JDK. 023 * 024 * <p>The methods should not be called directly, only via the corresponding 025 * static methods in {@link mondrian.olap.Util}, namely:<ul> 026 * <li>{@link mondrian.olap.Util#makeBigDecimalFromDouble(double)}</li> 027 * <li>{@link mondrian.olap.Util#quotePattern(String)}</li> 028 * </ul></p> 029 * 030 * <p>This interface could in principle be extended to allow native 031 * implementations of methods, or to serve as a factory for entire classes 032 * which have different implementations in different environments.</p> 033 * 034 * @author jhyde 035 * @since Feb 5, 2007 036 */ 037public interface UtilCompatible { 038 BigDecimal makeBigDecimalFromDouble(double d); 039 040 String quotePattern(String s); 041 042 <T> T getAnnotation( 043 Method method, String annotationClassName, T defaultValue); 044 045 String generateUuidString(); 046 047 /** 048 * Cancels and closes a SQL Statement object. If errors are encountered, 049 * they should be logged under {@link Util}. 050 * @param stmt The statement to close. 051 */ 052 void cancelStatement(Statement stmt); 053 054 /** 055 * Compiles a script to yield a Java interface. 056 * 057 * @param iface Interface script should implement 058 * @param script Script code 059 * @param engineName Name of engine (e.g. "JavaScript") 060 * @param <T> Interface 061 * @return Object that implements given interface 062 */ 063 <T> T compileScript( 064 Class<T> iface, 065 String script, 066 String engineName); 067 068 /** 069 * Removes a thread local from the current thread. 070 * 071 * <p>From JDK 1.5 onwards, calls {@link ThreadLocal#remove()}; before 072 * that, no-ops.</p> 073 * 074 * @param threadLocal Thread local 075 * @param <T> Type 076 */ 077 <T> void threadLocalRemove(ThreadLocal<T> threadLocal); 078 079 /** 080 * Creates a hash set that, like {@link java.util.IdentityHashMap}, 081 * compares keys using identity. 082 * 083 * @param <T> Element type 084 * @return Set 085 */ 086 <T> Set<T> newIdentityHashSet(); 087 088 /** 089 * As {@link java.util.Arrays#binarySearch(Object[], int, int, Object)}, but 090 * available pre-JDK 1.6. 091 */ 092 <T extends Comparable<T>> int binarySearch(T[] ts, int start, int end, T t); 093 094 /** 095 * Creates an object from which to get information about system memory 096 * use. From JDK 1.5 onwards, uses 097 * {@link java.lang.management.MemoryPoolMXBean}. 098 * 099 * @return Memory info 100 */ 101 Util.MemoryInfo getMemoryInfo(); 102 103 /** 104 * Equivalent to {@link Timer#Timer(String, boolean)}. 105 * (Introduced in JDK 1.5.) 106 * 107 * @param name the name of the associated thread 108 * @param isDaemon true if the associated thread should run as a daemon 109 * @return timer 110 */ 111 Timer newTimer(String name, boolean isDaemon); 112} 113 114// End UtilCompatible.java