Ejemplo n.º 1
0
 /**
  * @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 compareTypedDimensionValues(DimensionValue v1, DimensionValue v2)
     throws XBRLException {
   Store store = v1.getItem().getStore();
   String v1s = store.serializeToString((Element) v1.getValue());
   String v2s = store.serializeToString((Element) v2.getValue());
   return v1s.compareTo(v2s);
 }
Ejemplo n.º 2
0
  /**
   * @param v1 The first explicit dimension value.
   * @param v2 The second explicit 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
   */
  private int compareExplicitDimensionValues(DimensionValue v1, DimensionValue v2)
      throws XBRLException {

    Concept v1m = (Concept) v1.getValue();
    Concept v2m = (Concept) v2.getValue();

    URI v1ns = v1m.getTargetNamespace();
    URI v2ns = v2m.getTargetNamespace();
    int result = v1ns.compareTo(v2ns);
    if (result != 0) return result;

    String v1ln = v1m.getName();
    String v2ln = v2m.getName();
    return v1ln.compareTo(v2ln);
  }
Ejemplo n.º 3
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());
    }
  }
Ejemplo n.º 4
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.º 5
0
 /**
  * Do a comparison of the items that the dimension values are for, ranking them based on the
  * string comparison of their index values.
  *
  * @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 compareItems(DimensionValue v1, DimensionValue v2) throws XBRLException {
   return v1.getItem().compareTo(v2.getItem());
 }