Esempio n. 1
0
  /**
   * Combine all specifications objects that are identical except for the sections.
   *
   * <p>Note this is very inefficent and should probably be fixed in the future.
   *
   * @param list the array of results to trim
   * @return an array list with all duplicates removed
   */
  private static ArrayList removeDuplicates(final ArrayList list) {
    final ArrayList results = new ArrayList();
    final ArrayList sections = new ArrayList();
    while (list.size() > 0) {
      final Specification specification = (Specification) list.remove(0);
      final Iterator iterator = list.iterator();
      while (iterator.hasNext()) {
        final Specification other = (Specification) iterator.next();
        if (isEqual(specification, other)) {
          final String[] otherSections = other.getSections();
          if (null != sections) {
            sections.addAll(Arrays.asList(otherSections));
          }
          iterator.remove();
        }
      }

      final Specification merged = mergeInSections(specification, sections);
      results.add(merged);
      // Reset list of sections
      sections.clear();
    }

    return results;
  }
Esempio n. 2
0
  /**
   * Return a Compatibility enum indicating the relationship of this <code>Package Specification
   * </code> with the specified <code>Extension</code>.
   *
   * @param other the other specification
   * @return the enum indicating the compatibility (or lack thereof) of specifed Package
   *     Specification
   */
  public Compatibility getCompatibilityWith(final Specification other) {
    // Specification Name must match
    if (!m_specificationTitle.equals(other.getSpecificationTitle())) {
      return INCOMPATIBLE;
    }

    // Available specification version must be >= required
    final DeweyDecimal specificationVersion = other.getSpecificationVersion();
    if (null != specificationVersion) {
      if (null == m_specificationVersion
          || !isCompatible(m_specificationVersion, specificationVersion)) {
        return REQUIRE_SPECIFICATION_UPGRADE;
      }
    }

    // Implementation Vendor ID must match
    final String implementationVendor = other.getImplementationVendor();
    if (null != implementationVendor) {
      if (null == m_implementationVendor || !m_implementationVendor.equals(implementationVendor)) {
        return REQUIRE_VENDOR_SWITCH;
      }
    }

    // Implementation version must be >= required
    final String implementationVersion = other.getImplementationVersion();
    if (null != implementationVersion) {
      if (null == m_implementationVersion
          || !m_implementationVersion.equals(implementationVersion)) {
        return REQUIRE_IMPLEMENTATION_CHANGE;
      }
    }

    // This available optional package satisfies the requirements
    return COMPATIBLE;
  }
Esempio n. 3
0
  /**
   * Merge the specified sections into specified section and return result. If no sections to be
   * added then just return original specification.
   *
   * @param specification the specification
   * @param sectionsToAdd the list of sections to merge
   * @return the merged specification
   */
  private static Specification mergeInSections(
      final Specification specification, final ArrayList sectionsToAdd) {
    if (0 == sectionsToAdd.size()) {
      return specification;
    } else {
      sectionsToAdd.addAll(Arrays.asList(specification.getSections()));

      final String[] sections = (String[]) sectionsToAdd.toArray(new String[sectionsToAdd.size()]);

      return new Specification(
          specification.getSpecificationTitle(),
          specification.getSpecificationVersion().toString(),
          specification.getSpecificationVendor(),
          specification.getImplementationTitle(),
          specification.getImplementationVersion(),
          specification.getImplementationVendor(),
          sections);
    }
  }
Esempio n. 4
0
 /**
  * Test if two specifications are equal except for their sections.
  *
  * @param specification one specificaiton
  * @param other the ohter specification
  * @return true if two specifications are equal except for their sections, else false
  */
 private static boolean isEqual(final Specification specification, final Specification other) {
   return specification.getSpecificationTitle().equals(other.getSpecificationTitle())
       && specification.getSpecificationVersion().isEqual(other.getSpecificationVersion())
       && specification.getSpecificationVendor().equals(other.getSpecificationVendor())
       && specification.getImplementationTitle().equals(other.getImplementationTitle())
       && specification.getImplementationVersion().equals(other.getImplementationVersion())
       && specification.getImplementationVendor().equals(other.getImplementationVendor());
 }