Ejemplo n.º 1
0
  /**
   * Do a comparison of the dimensions themselves. This covers the dimensions but not the values of
   * those dimensions.
   *
   * @param v1 The first typed dimension value.
   * @param v2 The second typed dimension value.
   * @return a negative integer, zero, or a positive integer as the first argument is less than,
   *     equal to, or greater than the second.
   * @throws XBRLException
   */
  protected int compareDimensions(DimensionValue v1, DimensionValue v2) throws XBRLException {

    if (v1.isTypedDimensionValue() && v2.isExplicitDimensionValue()) return 1;

    if (v1.isExplicitDimensionValue() && v2.isTypedDimensionValue()) return -1;

    Dimension v1d = v1.getDimension();
    Dimension v2d = v2.getDimension();

    URI d1ns = v1d.getTargetNamespace();
    URI d2ns = v2d.getTargetNamespace();
    int result = d1ns.compareTo(d2ns);
    if (result != 0) return result;

    String d1ln = v1d.getName();
    String d2ln = v2d.getName();
    return d1ln.compareTo(d2ln);
  }
Ejemplo n.º 2
0
  /** @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */
  public int compare(DimensionValue v1, DimensionValue v2) throws ClassCastException {
    try {

      int result = compareDimensions(v1, v2);
      if (result != 0) return result;

      if (v1.isExplicitDimensionValue() && v2.isExplicitDimensionValue()) {
        result = compareExplicitDimensionValues(v1, v2);
      }
      if (result != 0) return result;

      if (v1.isTypedDimensionValue() && v2.isTypedDimensionValue()) {
        result = compareTypedDimensionValues(v1, v2);
      }
      if (result != 0) return result;

      return compareItems(v1, v2);

    } catch (XBRLException e) {
      throw new ClassCastException("Dimension value comparison is not possible." + e.getMessage());
    }
  }