Class Olap4jUtil

java.lang.Object
org.olap4j.impl.Olap4jUtil

public class Olap4jUtil extends Object
Utility methods common to multiple olap4j driver implementations.

This class, and this package as a whole, are part of the olap4j library but the methods are not part of the public olap4j API. The classes exist for the convenience of implementers of olap4j drivers, but their specification and implementation may change at any time.

Applications which use the API in this package will not be portable across multiple versions of olap4j. We encourage implementors of drivers to use classes in this package, but not writers of applications.

Since:
Dec 12, 2007
Author:
jhyde
  • Field Details

    • PreJdk15

      public static final boolean PreJdk15
      Whether we are running a version of Java before 1.5.

      If this variable is true, we will be running retroweaver. Retroweaver has some problems involving EnumSet.

    • Retrowoven

      public static final boolean Retrowoven
      Whether the code base has re-engineered using retroweaver. If this is the case, some functionality is not available.
  • Constructor Details

    • Olap4jUtil

      public Olap4jUtil()
  • Method Details

    • discard

      public static void discard(boolean b)
    • discard

      public static void discard(byte b)
    • discard

      public static void discard(char c)
    • discard

      public static void discard(double v)
    • discard

      public static void discard(float v)
    • discard

      public static void discard(int i)
    • discard

      public static void discard(long l)
    • discard

      public static void discard(Object o)
    • discard

      public static void discard(short i)
    • cast

      public static <T> Set<T> cast(Set<?> set)
      Casts a Set to a Set with a different element type.
      Parameters:
      set - Set
      Returns:
      Set of desired type
    • cast

      public static <T> List<T> cast(List<?> list)
      Casts a List to a List with a different element type.
      Parameters:
      list - List
      Returns:
      List of desired type
    • cast

      public static <T> NamedList<T> cast(NamedList<?> list)
      Casts a NamedList to a NamedList with a different element type.
      Parameters:
      list - Named list
      Returns:
      Named list of desired type
    • mapOf

      public static <K, V> Map<K,V> mapOf(K key, V value, Object... keyValues)
      Returns a hashmap with given contents.

      Use this method in initializers. Type parameters are inferred from context, and the contents are initialized declaratively. For example,

      Map<String, Integer> population =
        Olap4jUtil.mapOf(
          "UK", 65000000,
          "USA", 300000000);
      Type Parameters:
      K - Key type
      V - Value type
      Parameters:
      key - First key
      value - First value
      keyValues - Second and sequent key/value pairs
      Returns:
      Map with given contents
      See Also:
    • toMap

      public static Map<String,String> toMap(Properties properties)
      Converts a Properties object to a Map with String keys and values.
      Parameters:
      properties - Properties
      Returns:
      Map backed by the given Properties object
    • unexpected

      public static AssertionError unexpected(Enum value)
      Returns an exception indicating that we didn't expect to find this value here.
      Parameters:
      value - Value
      Returns:
      an AssertionError which can be thrown
    • equal

      public static <T> boolean equal(T t1, T t2)
      Returns true if two objects are equal, or are both null.
      Parameters:
      t1 - First value
      t2 - Second value
      Returns:
      Whether values are both equal or both null
    • replace

      public static String replace(String s, String find, String replace)
      Returns a string with every occurrence of a seek string replaced with another.
      Parameters:
      s - String to act on
      find - String to find
      replace - String to replace it with
      Returns:
      The modified string
    • replace

      public static StringBuilder replace(StringBuilder buf, int start, String find, String replace)
      Replaces all occurrences of a string in a buffer with another.
      Parameters:
      buf - String buffer to act on
      start - Ordinal within find to start searching
      find - String to find
      replace - String to replace it with
      Returns:
      The string buffer
    • wildcardToRegexp

      public static String wildcardToRegexp(List<String> wildcards)
      Converts a list of SQL-style patterns into a Java regular expression.

      For example, {"Foo_", "Bar%BAZ"} becomes "Foo.|Bar.*BAZ".

      Parameters:
      wildcards - List of SQL-style wildcard expressions
      Returns:
      Regular expression
    • quotePattern

      public static String quotePattern(String s)
      Returns a literal pattern String for the specified String.

      Specification as for Pattern.quote(String), which was introduced in JDK 1.5.

      Parameters:
      s - The string to be literalized
      Returns:
      A literal string replacement
    • camelToUpper

      public static String camelToUpper(String s)
      Converts a camel-case name to an upper-case name with underscores.

      For example, camelToUpper("FooBar") returns "FOO_BAR".

      Parameters:
      s - Camel-case string
      Returns:
      Upper-case string
    • needToImplement

      public static RuntimeException needToImplement(Object o)
      Returns an exception which indicates that a particular piece of functionality should work, but a developer has not implemented it yet.
      Parameters:
      o - Object operation was called on, perhaps indicating the subtype where a virtual method needs to be implemented
      Returns:
      an exception which can be thrown
    • parseUniqueName

      public static List<String> parseUniqueName(String uniqueName)
      Parses a unique name.

      For example, uniqueNameToStringArray("[foo].[bar]") returns ["foo", "bar"].

      Parameters:
      uniqueName - Unique name
      Returns:
      Parsed unique name
      See Also:
    • stringArrayToString

      public static String stringArrayToString(String[] array)
      Converts the contents of an array of strings to a proper String representation.
      Parameters:
      array - Array of strings
      Returns:
      string representation of the array
    • emptyNamedList

      public static <T> NamedList<T> emptyNamedList()
    • unmodifiableNamedList

      public static <T> NamedList<T> unmodifiableNamedList(NamedList<T> list)
      Returns an unmodifiable view of the specified list. This method allows modules to provide users with "read-only" access to internal lists. Query operations on the returned list "read through" to the specified list, and attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException.

      The returned list will be serializable if the specified list is serializable. Similarly, the returned list will implement RandomAccess if the specified list does.

      The equivalent of Collections.unmodifiableList(java.util.List).

      Parameters:
      list - the list for which an unmodifiable view is to be returned.
      Returns:
      an unmodifiable view of the specified list.
    • enumSetOf

      public static <E extends Enum<E>> Set<E> enumSetOf(E first, E... rest)
      Equivalent to EnumSet.of(Enum, Enum[]) on JDK 1.5 or later. Otherwise, returns an ordinary set.
      Parameters:
      first - an element that the set is to contain initially
      rest - the remaining elements the set is to contain initially
      Returns:
      an enum set initially containing the specified elements
      Throws:
      NullPointerException - if any of the specified elements are null, or if rest is null
    • enumSetNoneOf

      public static <E extends Enum<E>> Set<E> enumSetNoneOf(Class<E> elementType)
      Equivalent to EnumSet.noneOf(Class) on JDK 1.5 or later. Otherwise, returns an ordinary set.
      Parameters:
      elementType - the class object of the element type for this enum set
      Returns:
      an empty enum set
    • enumSetAllOf

      public static <E extends Enum<E>> Set<E> enumSetAllOf(Class<E> elementType)
      Equivalent to EnumSet.allOf(Class) on JDK 1.5 or later. Otherwise, returns an ordinary set.
      Parameters:
      elementType - the class object of the element type for this enum set
      Returns:
      an enum set containing all elements of the given enum class
    • parseFormattedCellValue

      public static String parseFormattedCellValue(String formattedValue, Map<String,String> map)
      Parses a formatted cell values.

      There is a customary way of including formatting infornation in cell values (started with Microsoft OLAP Services, and continued by JPivot and now Pentaho Analyzer). This method parses out the formatted value that should be displayed on the screen and also any properties present.

      Examples:

      • "$123" no formatting information
      • "|$123|style=red|" print in red style
      • "|$123|style=red|arrow=up|" print in red style with an up arrow

      Properties

      Name Value Description
      style red|green|yellow renders the Member in that color
      link a url creates a hyperlink on the member
      arrow up|down|blank paints an arrow image
      image a uri. If the uri starts with "/" the context name will be prepended paints image
      Parameters:
      formattedValue - Formatted cell value
      map - Map into which to place (property, value) pairs
      Returns:
      Formatted cell value with properties removed