001    /*
002    // $Id: //open/mondrian/src/main/mondrian/util/UtilCompatibleJdk14.java#5 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2007-2008 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.util;
011    
012    import java.util.Set;
013    import java.util.HashSet;
014    import java.util.Arrays;
015    import java.math.BigDecimal;
016    import java.lang.reflect.Method;
017    
018    /**
019     * Implementation of {@link UtilCompatible} which runs in
020     * JDK 1.4.
021     *
022     * <p>The code uses JDK 1.5 constructs such as generics and for-each loops,
023     * but retroweaver can convert these. It does not use
024     * <code>java.util.EnumSet</code>, which is important, because retroweaver has
025     * trouble with this.
026     *
027     * @author jhyde
028     * @version $Id: //open/mondrian/src/main/mondrian/util/UtilCompatibleJdk14.java#5 $
029     * @since Feb 5, 2007
030     */
031    public class UtilCompatibleJdk14 implements UtilCompatible {
032        public <E extends Enum<E>> Set<E> enumSetOf(E first, E... rest) {
033            HashSet<E> set = new HashSet<E>();
034            set.add(first);
035            set.addAll(Arrays.asList(rest));
036            return set;
037        }
038    
039        public <E extends Enum<E>> Set<E> enumSetNoneOf(Class<E> elementType) {
040            return new HashSet<E>();
041        }
042    
043        public <E extends Enum<E>> Set<E> enumSetAllOf(Class<E> elementType) {
044            return new HashSet<E>(Arrays.asList(elementType.getEnumConstants()));
045        }
046    
047        /**
048         * This generates a BigDecimal that can have a precision that does
049         * not reflect the precision of the input double.
050         *
051         * @param d input double
052         * @return BigDecimal
053         */
054        public BigDecimal makeBigDecimalFromDouble(double d) {
055            return new BigDecimal(d);
056        }
057    
058        public String quotePattern(String s) {
059            int slashEIndex = s.indexOf("\\E");
060            if (slashEIndex == -1)
061                return "\\Q" + s + "\\E";
062    
063            StringBuilder sb = new StringBuilder(s.length() * 2);
064            sb.append("\\Q");
065            int current = 0;
066            while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
067                sb.append(s.substring(current, slashEIndex));
068                current = slashEIndex + 2;
069                sb.append("\\E\\\\E\\Q");
070            }
071            sb.append(s.substring(current, s.length()));
072            sb.append("\\E");
073            return sb.toString();
074        }
075    
076        public <T> T getAnnotation(
077            Method method, String annotationClassName, T defaultValue)
078        {
079            return defaultValue;
080        }
081    }
082    
083    // End UtilCompatibleJdk14.java