Skip to content

Commit

Permalink
Update with Sonar suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Jun 18, 2024
1 parent cb7c0b3 commit 45e1447
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
mvn -B -ntp -Dorg.slf4j.simpleLogger.log.net.sourceforge.pmd=error -Psonar verify
mvn -B -ntp -Dorg.slf4j.simpleLogger.log.net.sourceforge.pmd=error
-Psonar verify javadocs:javadocs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,10 @@ protected AbstractCanvas<T> setBehaviors(final Behavior... aBehaviorArray) {
*/
@Override
@JsonSetter(JsonKeys.BEHAVIOR)
@SuppressWarnings({ PMD.LOOSE_COUPLING })
protected AbstractCanvas<T> setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(CanvasBehavior.class, this.getClass());
if (aBehaviorList instanceof final BehaviorList behaviorList) {
behaviorList.checkType(CanvasBehavior.class, getClass());
}

return (AbstractCanvas<T>) super.setBehaviors(aBehaviorList);
Expand Down Expand Up @@ -659,13 +660,8 @@ private boolean canFrame(final ContentResource<?> aContent, final MediaFragmentS
private List<AnnotationPage<?>> getAnnotations() {
final List<AnnotationPage<?>> annotations = new ArrayList<>();

getSupplementingPages().forEach(page -> {
annotations.add(page);
});

getOtherAnnotations().forEach(page -> {
annotations.add(page);
});
getSupplementingPages().forEach(annotations::add);
getOtherAnnotations().forEach(annotations::add);

return annotations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ protected <C extends CanvasResource<C>> AbstractCanvasAnnotation(final String aI
this(aID, aCanvas, new MediaFragmentSelector(aCanvasRegion));
}

/**
* Gets the content resources associated with this annotation.
*
* @return The content resources associated with this annotation
*/
@JsonIgnore
public List<ContentResource<?>> getBody() {
if (myResources == null) {
myResources = new ArrayList<>();
}

return myResources;
}

/**
* Sets the annotation resource's behaviors. The supplied behaviors are checked for compatibility with the resource.
*
Expand All @@ -139,9 +153,10 @@ public AbstractCanvasAnnotation<A> setBehaviors(final Behavior... aBehaviorArray
*/
@Override
@JsonSetter(JsonKeys.BEHAVIOR)
@SuppressWarnings({ PMD.LOOSE_COUPLING })
public AbstractCanvasAnnotation<A> setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
if (aBehaviorList instanceof final BehaviorList behaviorList) {
behaviorList.checkType(ResourceBehavior.class, getClass());
}

return (AbstractCanvasAnnotation<A>) super.setBehaviors(aBehaviorList);
Expand All @@ -156,20 +171,6 @@ protected boolean bodyHasChoice() {
return myBodyHasChoice;
}

/**
* Gets the content resources associated with this annotation.
*
* @return The content resources associated with this annotation
*/
@JsonIgnore
protected List<ContentResource<?>> getBody() {
if (myResources == null) {
myResources = new ArrayList<>();
}

return myResources;
}

/**
* Gets the annotation's motivation.
*
Expand Down Expand Up @@ -320,9 +321,7 @@ private void deserializeContentMap(final Map<?, ?> aMap) {
*/
private void deserializeListBody(final List<?> aListBody) {
if (!aListBody.isEmpty() && aListBody.get(0) instanceof Map) {
aListBody.forEach(mapObject -> {
deserializeContentMap((Map<?, ?>) mapObject);
});
aListBody.forEach(mapObject -> deserializeContentMap((Map<?, ?>) mapObject));
}
}

Expand All @@ -340,9 +339,7 @@ private void deserializeMapBody(final Map<?, ?> aMapBody) {
setChoice(true);

if (!items.isEmpty() && items.get(0) instanceof Map) {
items.forEach(mapObject -> {
deserializeContentMap((Map<?, ?>) mapObject);
});
items.forEach(mapObject -> deserializeContentMap((Map<?, ?>) mapObject));
}
} else {
deserializeContentMap(aMapBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public String getType() {
@Override
public String toString() {
try {
return JSON.getWriter(this.getClass()).writeValueAsString(this);
return JSON.getWriter(getClass()).writeValueAsString(this);
} catch (final JsonProcessingException details) {
throw new I18nRuntimeException(details);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public AnnotationCollection setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public AnnotationCollection setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (AnnotationCollection) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public AnnotationPage<A> setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public AnnotationPage<A> setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (AnnotationPage<A>) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public CanvasContent setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public CanvasContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (CanvasContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ public interface CanvasResource<T extends CanvasResource<T>> extends Resource<T>
T paintWith(boolean aChoice, List<ContentResource<?>> aContentList);

/**
* Paints content resources onto a {@link Minter} initialized canvas using a {@link PaintingAnnotation}. If the
* minter does not exist, a {@link MinterException} is thrown.
* Paints content resources onto a {@link Minter} initialized canvas using a {@link PaintingAnnotation}.
* <p>
* Calling this method with a single {@link ContentResource} associates that resource with the canvas using an
* annotation with a single body.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Collection setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public Collection setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(CollectionBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(CollectionBehavior.class, getClass());
}

return (Collection) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public DatasetContent setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public DatasetContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (DatasetContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public ImageContent setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public ImageContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (ImageContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public Manifest setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public Manifest setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ManifestBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ManifestBehavior.class, getClass());
}

return (Manifest) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ModelContent setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public ModelContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (ModelContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Range setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public Range setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(RangeBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(RangeBehavior.class, getClass());
}

return (Range) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public SoundContent setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public SoundContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (SoundContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,6 @@ public List<Behavior> getBehaviors() {
return super.getBehaviors();
}

/**
* Gets the resources associated with this annotation.
*
* @return The resources associated with this annotation
*/
@Override
@JsonIgnore
public List<ContentResource<?>> getBody() {
return super.getBody();
}

/**
* Gets a list of resource homepages.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public TextContent setBehaviors(final Behavior... aBehaviorArray) {
@JsonSetter(JsonKeys.BEHAVIOR)
public TextContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, getClass());
}

return (TextContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public VideoContent setBehaviors(final Behavior... aBehaviorArray) {

@Override
@JsonSetter(JsonKeys.BEHAVIOR)
@SuppressWarnings({ PMD.LOOSE_COUPLING })
public VideoContent setBehaviors(final List<Behavior> aBehaviorList) {
if (aBehaviorList instanceof BehaviorList) {
((BehaviorList) aBehaviorList).checkType(ResourceBehavior.class, this.getClass());
if (aBehaviorList instanceof final BehaviorList behaviorList) {
behaviorList.checkType(ResourceBehavior.class, getClass());
}

return (VideoContent) super.setBehaviors(aBehaviorList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public int hashCode() {
@Override
public String toString() {
try {
return JSON.getWriter(this.getClass()).writeValueAsString(this);
return JSON.getWriter(getClass()).writeValueAsString(this);
} catch (final JsonProcessingException details) {
throw new JsonParsingException(details);
}
Expand Down

0 comments on commit 45e1447

Please sign in to comment.