There are some issues in how enums are used in SPDX Tools.
First, there are the names: RelationshipType.relationshipType_contains. The
established convention (See “Effective Java”, Item 30 or Google’s style guide:
4.8.1 Enum
classes<http://google.github.io/styleguide/javaguide.html#s4.8.1-enum-classes>,
or just about anywhere else) is to have the values in upper case and not
duplicate the enum name. Further, any literal data that is associated with enum
constants should be contain within the enum. Today, we expose the mappings of
enum values to literals in public mutable structures, violating encapsulation
in a way that allows a subcomponent in the classpath to break how the code
works in the entire application by changing those values.
I would therefore propose rewriting the Relationship, Annotation, and File
types in the following manner, consistent with universally-accepted Java
programming practices:
public enum RelationshipType {
DESCRIBES("DESCRIBES"),
DESCRIBED_BY("DESCRIBED_BY"),
ANCESTOR_OF("ANCESTOR_OF"),
BUILD_TOOL_OF("BUILD_TOOL_OF"),
CONTAINED_BY("CONTAINED_BY"),
CONTAINS("CONTAINS"),
COPY_OF("COPY_OF"),
DATA_FILE_OF("DATA_FILE_OF"),
DESCENDANT_OF("DESCENDANT_OF"),
DISTRIBUTION_ARTIFACT("DISTRIBUTION_ARTIFACT"),
DOCUMENTATION_OF("DOCUMENTATION_OF"),
DYNAMIC_LINK("DYNAMIC_LINK"),
EXPANDED_FROM_ARCHIVE("EXPANDED_FROM_ARCHIVE"),
FILE_ADDED("FILE_ADDED"),
FILE_DELETED("FILE_DELETED"),
FILE_MODIFIED("FILE_MODIFIED"),
GENERATED_FROM("GENERATED_FROM"),
GENERATES("GENERATES"),
METAFILE_OF("METAFILE_OF"),
OPTIONAL_COMPONENT_OF("OPTIONAL_COMPONENT_OF"),
OTHER("OTHER"),
PACKAGE_OF("PACKAGE_OF"),
PATCH_APPLIED("PATCH_APPLIED"),
AMENDS("AMENDS"),
STATIC_LINK("STATIC_LINK"),
TEST_CASE_OF("TEST_CASE_OF");
private final String tag;
// Immutable map to look up values by tag
private static final Map<String, RelationshipType> typesByTag;
static {
ImmutableMap.Builder<String, RelationshipType> builder =
ImmutableMap.builder();
for (RelationshipType type : RelationshipType.values()) {
builder.put(type.getTag(), type);
}
typesByTag = builder.build();
}
private RelationshipType(String tag) {
this.tag = tag;
}
public String getTag() {
return tag;
}
public static RelationshipType fromTag(String tag) {
return typesByTag.get(tag);
}
}
Because this is a change to the API, I would love to make this change as soon
as possible, perhaps in a separate point release, so that any new users will
get the updated version.
<http://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s4.8.1-enum-classes>
[cid:7EA68D51-363B-4FAD-A939-D9CD926D70AB]
Yev Bronshteyn
Senior Software Engineer
Black Duck Software
Black Duck Software<http://www.blackducksoftware.com/> |
OpenHUB<https://www.openhub.net/> |
OSDelivers<http://osdelivers.blackducksoftware.com/> | OSS
Logistics<https://www.blackducksoftware.com/oss-logistics>
[cid:E33E6B21-2C3E-4C55-8796-46161EE14AC6] <http://twitter.com/black_duck_sw>
[cid:EDB9C095-85D8-437C-A4CF-A515712839CA]
<https://www.linkedin.com/company/black-duck-software>
[cid:8D343C4D-B65C-473A-96DE-792AF2B5D16E]
<https://www.facebook.com/BlackDuckSoftware>
[cid:3FCDCA9B-C8EA-4EB2-9184-457FF1A9AB5D]
<https://plus.google.com/+Blackducksoftware/>
[cid:D1E6BBB6-3622-496C-B3BF-7DC86A214CB8]
<http://www.slideshare.net/blackducksoftware>
[cid:B8FD9DF1-3230-44BF-80DA-AEA16CB00E29]
JP Morgan Chase & Co. Hall of Innovation Inductee
<https://www.youtube.com/user/BlackDuckSoftware>
<https://www.youtube.com/user/BlackDuckSoftware>
_______________________________________________
Spdx-tech mailing list
[email protected]
https://lists.spdx.org/mailman/listinfo/spdx-tech