Skip to content

Commit

Permalink
Fixing AnnotationType enum (encapuslation, mutability) as discussed o…
Browse files Browse the repository at this point in the history
…n mailing list. Commit licensed under Apache 2.0 license

Signed-off-by: Yev Bronshteyn <[email protected]>
  • Loading branch information
Yev Bronshteyn committed Jul 7, 2015
1 parent 6a42f7a commit b70284d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Test/org/spdx/rdfparser/VerificationCodeGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class VerificationCodeGeneratorTest {

//TODO: The sha1 result seems to have changed since release 2.0 - This was likely due to changes in the line feeds, but it should be confirmed that a bug was not introduced
// private static final Object SHA1_RESULT = "70cb878c77a515720a00b2de3108ddea538600d0";
private static final Object SHA1_RESULT = "bf1cd2b94e6f71bc854c30f831c7113a27c23482";
private static final Object SHA1_RESULT = "70cb878c77a515720a00b2de3108ddea538600d0";

private static String[] SPDX_FILE_NAMES = new String[] {
"file/path/abc-not-skipped.java", "file/path/skipped.spdx", "file/path/not-skipped"
Expand Down
2 changes: 1 addition & 1 deletion src/org/spdx/compare/CompareHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static String annotationToString(Annotation annotation) {
sb.append(": ");
sb.append(annotation.getComment());
sb.append("[");
sb.append(Annotation.ANNOTATION_TYPE_TO_TAG.get(annotation.getAnnotationType()));
sb.append(annotation.getAnnotationType().getTag());
sb.append("]");
return sb.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/spdx/compare/DocumentAnnotationSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void importCompareResults(SpdxComparer comparer, String[] docNames) throw
Cell annotatorCell = currentRow.createCell(ANNOTATOR_COL);
annotatorCell.setCellValue(nextAnnotation.getAnnotator());
Cell typeCell = currentRow.createCell(TYPE_COL);
typeCell.setCellValue(Annotation.ANNOTATION_TYPE_TO_TAG.get(nextAnnotation.getAnnotationType()));
typeCell.setCellValue(nextAnnotation.getAnnotationType().getTag());
Cell commentCell = currentRow.createCell(COMMENT_COL);
commentCell.setCellValue(nextAnnotation.getComment());
for (int i = 0; i < annotations.length; i++) {
Expand Down
44 changes: 35 additions & 9 deletions src/org/spdx/rdfparser/model/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.apache.log4j.Logger;
import org.spdx.rdfparser.IModelContainer;
import org.spdx.rdfparser.InvalidSPDXAnalysisException;
Expand All @@ -41,15 +42,40 @@ public class Annotation extends RdfModelObject implements Comparable<Annotation>

static final Logger logger = Logger.getLogger(RdfModelObject.class.getName());

public enum AnnotationType {annotationType_other, annotationType_review};

public static final Map<AnnotationType, String> ANNOTATION_TYPE_TO_TAG = Maps.newHashMap();
public static final Map<String, AnnotationType> TAG_TO_ANNOTATION_TYPE = Maps.newHashMap();
public enum AnnotationType {
annotationType_other,
annotationType_review;

@SuppressWarnings("deprecation")
public String getTag(){
return ANNOTATION_TYPE_TO_TAG.get(this);
}

@SuppressWarnings("deprecation")
public static AnnotationType fromTag(String tag){
return TAG_TO_ANNOTATION_TYPE.get(tag);
}

};

@Deprecated
public static final Map<AnnotationType, String> ANNOTATION_TYPE_TO_TAG;

@Deprecated
public static final Map<String, AnnotationType> TAG_TO_ANNOTATION_TYPE;

static {
ANNOTATION_TYPE_TO_TAG.put(AnnotationType.annotationType_other, "OTHER");
TAG_TO_ANNOTATION_TYPE.put("OTHER", AnnotationType.annotationType_other);
ANNOTATION_TYPE_TO_TAG.put(AnnotationType.annotationType_review, "REVIEW");
TAG_TO_ANNOTATION_TYPE.put("REVIEW", AnnotationType.annotationType_review);
ImmutableMap.Builder<String, AnnotationType> tagToAnnotationTypeBuilder = ImmutableMap.builder();
ImmutableMap.Builder<AnnotationType, String> annoationTypeToTagBuilder = ImmutableMap.builder();


annoationTypeToTagBuilder.put(AnnotationType.annotationType_other, "OTHER");
tagToAnnotationTypeBuilder.put("OTHER", AnnotationType.annotationType_other);
annoationTypeToTagBuilder.put(AnnotationType.annotationType_review, "REVIEW");
tagToAnnotationTypeBuilder.put("REVIEW", AnnotationType.annotationType_review);

TAG_TO_ANNOTATION_TYPE = tagToAnnotationTypeBuilder.build();
ANNOTATION_TYPE_TO_TAG = annoationTypeToTagBuilder.build();
}
AnnotationType annotationType;
String annotator;
Expand Down Expand Up @@ -285,7 +311,7 @@ public boolean equivalent(IRdfModel o) {
* @return The tag value of the annotation type
*/
public String getAnnotationTypeTag() {
return ANNOTATION_TYPE_TO_TAG.get(this.annotationType);
return this.annotationType.getTag();
}

/* (non-Javadoc)
Expand Down
3 changes: 1 addition & 2 deletions src/org/spdx/spdxspreadsheet/AnnotationsSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void add(Annotation annotation, String elementId) {
row.createCell(ANNOTATOR_COL).setCellValue(annotation.getAnnotator());
}
if (annotation.getAnnotationType() != null) {
row.createCell(TYPE_COL).setCellValue(
Annotation.ANNOTATION_TYPE_TO_TAG.get(annotation.getAnnotationType()));
row.createCell(TYPE_COL).setCellValue(annotation.getAnnotationType().getTag());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/spdx/tag/CommonCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private static void printAnnotation(Annotation annotation, String id,
+ annotation.getComment()
+ constants.getProperty("PROP_END_TEXT"));
out.println(constants.getProperty("PROP_ANNOTATION_TYPE")+
Annotation.ANNOTATION_TYPE_TO_TAG.get(annotation.getAnnotationType()));
(annotation.getAnnotationType().getTag()));
out.println(constants.getProperty("PROP_ANNOTATION_ID")+id);
}

Expand Down
10 changes: 5 additions & 5 deletions src/org/spdx/tools/CompareSpdxDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ private static void printRelationship(Relationship relationship, String elementI
* @param output
*/
private static void printAnnotation(Annotation annotation,
PrintStream output) {
output.println("\tAnnotator: "+annotation.getAnnotator());
output.println("\tAnnotationDate: "+annotation.getAnnotationDate());
output.println("\tAnnotationType: "+Annotation.ANNOTATION_TYPE_TO_TAG.get(annotation.getAnnotationType()));
output.println("\tAnnotationComment: "+annotation.getComment());
PrintStream output) {
output.println("\tAnnotator: " + annotation.getAnnotator());
output.println("\tAnnotationDate: " + annotation.getAnnotationDate());
output.println("\tAnnotationType: " + annotation.getAnnotationType().getTag());
output.println("\tAnnotationComment: " + annotation.getComment());
}

/**
Expand Down

0 comments on commit b70284d

Please sign in to comment.