📄 specification.java
字号:
*/ public String getImplementationVendor() { return implementationVendor; } /** * Get the version of the implementation. * * @return the version of the implementation. */ public String getImplementationVersion() { return implementationVersion; } /** * Return an array containing sections to which specification applies * or null if relevent to no sections. * * @return an array containing sections to which specification applies * or null if relevent to no sections. */ public String[] getSections() { if (null == sections) { return null; } final String[] newSections = new String[ sections.length ]; System.arraycopy(sections, 0, newSections, 0, sections.length); return newSections; } /** * 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 (!specificationTitle.equals(other.getSpecificationTitle())) { return INCOMPATIBLE; } // Available specification version must be >= required final DeweyDecimal otherSpecificationVersion = other.getSpecificationVersion(); if (null != specificationVersion) { if (null == otherSpecificationVersion || !isCompatible(specificationVersion, otherSpecificationVersion)) { return REQUIRE_SPECIFICATION_UPGRADE; } } // Implementation Vendor ID must match final String otherImplementationVendor = other.getImplementationVendor(); if (null != implementationVendor) { if (null == otherImplementationVendor || !implementationVendor.equals(otherImplementationVendor)) { return REQUIRE_VENDOR_SWITCH; } } // Implementation version must be >= required final String otherImplementationVersion = other.getImplementationVersion(); if (null != implementationVersion) { if (null == otherImplementationVersion || !implementationVersion.equals(otherImplementationVersion)) { return REQUIRE_IMPLEMENTATION_CHANGE; } } // This available optional package satisfies the requirements return COMPATIBLE; } /** * Return <code>true</code> if the specified <code>package</code> * is satisfied by this <code>Specification</code>. Otherwise, return * <code>false</code>. * * @param other the specification * @return true if the specification is compatible with this specification */ public boolean isCompatibleWith(final Specification other) { return (COMPATIBLE == getCompatibilityWith(other)); } /** * Return a String representation of this object. * * @return string representation of object. */ public String toString() { final String brace = ": "; final StringBuffer sb = new StringBuffer(SPECIFICATION_TITLE.toString()); sb.append(brace); sb.append(specificationTitle); sb.append(StringUtils.LINE_SEP); if (null != specificationVersion) { sb.append(SPECIFICATION_VERSION); sb.append(brace); sb.append(specificationVersion); sb.append(StringUtils.LINE_SEP); } if (null != specificationVendor) { sb.append(SPECIFICATION_VENDOR); sb.append(brace); sb.append(specificationVendor); sb.append(StringUtils.LINE_SEP); } if (null != implementationTitle) { sb.append(IMPLEMENTATION_TITLE); sb.append(brace); sb.append(implementationTitle); sb.append(StringUtils.LINE_SEP); } if (null != implementationVersion) { sb.append(IMPLEMENTATION_VERSION); sb.append(brace); sb.append(implementationVersion); sb.append(StringUtils.LINE_SEP); } if (null != implementationVendor) { sb.append(IMPLEMENTATION_VENDOR); sb.append(brace); sb.append(implementationVendor); sb.append(StringUtils.LINE_SEP); } return sb.toString(); } /** * Return <code>true</code> if the first version number is greater than * or equal to the second; otherwise return <code>false</code>. * * @param first First version number (dotted decimal) * @param second Second version number (dotted decimal) */ private boolean isCompatible(final DeweyDecimal first, final DeweyDecimal second) { return first.isGreaterThanOrEqual(second); } /** * 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.</p> * * @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 != otherSections) { sections.addAll(Arrays.asList(otherSections)); } iterator.remove(); } } final Specification merged = mergeInSections(specification, sections); results.add(merged); //Reset list of sections sections.clear(); } return results; } /** * 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()); } /** * 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; } 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); } /** * Trim the supplied string if the string is non-null * * @param value the string to trim or null * @return the trimmed string or null */ private static String getTrimmedString(final String value) { return value == null ? null : value.trim(); } /** * Extract an Package Specification from Attributes. * * @param attributes Attributes to searched * @return the new Specification object, or null */ private static Specification getSpecification(final String section, final Attributes attributes) throws ParseException { //WARNING: We trim the values of all the attributes because //Some extension declarations are badly defined (ie have spaces //after version or vendor) final String name = getTrimmedString(attributes.getValue(SPECIFICATION_TITLE)); if (null == name) { return null; } final String specVendor = getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR)); if (null == specVendor) { throw new ParseException(MISSING + SPECIFICATION_VENDOR, 0); } final String specVersion = getTrimmedString(attributes.getValue(SPECIFICATION_VERSION)); if (null == specVersion) { throw new ParseException(MISSING + SPECIFICATION_VERSION, 0); } final String impTitle = getTrimmedString(attributes.getValue(IMPLEMENTATION_TITLE)); if (null == impTitle) { throw new ParseException(MISSING + IMPLEMENTATION_TITLE, 0); } final String impVersion = getTrimmedString(attributes.getValue(IMPLEMENTATION_VERSION)); if (null == impVersion) { throw new ParseException(MISSING + IMPLEMENTATION_VERSION, 0); } final String impVendor = getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR)); if (null == impVendor) { throw new ParseException(MISSING + IMPLEMENTATION_VENDOR, 0); } return new Specification(name, specVersion, specVendor, impTitle, impVersion, impVendor, new String[]{section}); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -