/** Converts the specification to an id */ public ComponentId toId() { Version version = (getVersionSpecification() == VersionSpecification.emptyVersionSpecification) ? Version.emptyVersion : getVersionSpecification().lowestMatchingVersion(); return new ComponentId(getName(), version, getNamespace()); }
private ComponentId(String name, Version version, ComponentId namespace, boolean anonymous) { if (anonymous) { name = createAnonymousName(name); } spec = new Spec<>(new VersionHandler(), name, version, namespace); this.anonymous = anonymous; stringValue = spec.createStringValue(); }
/** * Checks if a componentId matches a given spec */ public boolean matches(ComponentId id) { boolean versionMatch = getVersionSpecification().matches(id.getVersion()); return getName().equals(id.getName()) && versionMatch && namespaceMatch(id.getNamespace()); }
public ComponentSpecification nestInNamespace(ComponentId namespace) { ComponentId newNameSpace = (getNamespace() == null) ? namespace : getNamespace().nestInNamespace(namespace); return new ComponentSpecification(getName(), getVersionSpecification(), newNameSpace); }
/** Creates a version specification that only matches this version */ public VersionSpecification toSpecification() { if (this == emptyVersion) return VersionSpecification.emptyVersionSpecification; else { return new VersionSpecification(getMajor(), getMinor(), getMicro(), getQualifier()); } }
/** * Returns the lowest possible Version object that matches this spec **/ public Version lowestMatchingVersion() { return new Version(getMajor(), getMinor(), getMicro(), getQualifier()); }
/** * DO NOT CALL, for internal use only, */ public final String getIdString() { if (hasInitializedId()) return getId().toString(); return "(anonymous)"; }
private boolean namespaceMatch(ComponentId otherNamespace) { if (getNamespace() == otherNamespace) { return true; } else if (getNamespace() == null || otherNamespace == null){ return false; } else { return getNamespace().equals(otherNamespace); } }
String createStringValue() { if (isNonEmpty(version) || (namespace != null)) { StringBuilder builder = new StringBuilder(name); if (isNonEmpty(version)) builder.append(':').append(version); if (namespace != null) builder.append('@').append(namespace.stringValue()); return builder.toString(); } else { return name; } }
private static boolean matches(ComponentSpecification component, Set<ComponentSpecification> excludes) { ComponentId id = component.toId().withoutNamespace(); for (ComponentSpecification exclude : excludes) { if (exclude.matches(id)) { return true; } } return false; }
public BundleInstantiationSpecification(ComponentSpecification id, ComponentSpecification classId, ComponentSpecification bundle) { this.id = id.toId(); this.classId = (classId != null) ? classId : id.withoutNamespace(); this.bundle = (bundle != null) ? bundle : this.classId; }
public int compareTo(ComponentId other) { //anonymous must never be equal to non-anonymous if (isAnonymous() ^ other.isAnonymous()) { return isAnonymous() ? -1 : 1; } return spec.compareTo(other.spec); }
/** * Creates a new component with an id. * Only for testing and components that are not created via dependency injection. * * @throws NullPointerException if the given id is null */ protected AbstractComponent(ComponentId id) { initId(id); isDeconstructable = setIsDeconstructable(); }
public ComponentSpecification(String name, VersionSpecification versionSpecification, ComponentId namespace) { spec = new Spec<>(new VersionHandler(), name, versionSpecification, namespace); stringValue = spec.createStringValue(); }
public static VersionSpecification fromString(String versionString) { if (versionString == null) { return emptyVersionSpecification; } else { return new VersionSpecification(versionString); } }
private int compare(ComponentId n1, ComponentId n2) { if (n1 == null && n2 == null) return 0; if (n1 == null) return -1; if (n2 == null) return 1; return n1.compareTo(n2); }
@Override public int compare(VersionSpecification v1, VersionSpecification v2) { return v1.compareTo(v2); } }