Skip to content

Commit

Permalink
Work on Code Issues (Spotless)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Dec 11, 2023
1 parent bf01d04 commit 1e84ac2
Show file tree
Hide file tree
Showing 63 changed files with 406 additions and 715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@

import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;

import org.jetbrains.annotations.NotNull;
import java.util.*;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -18,29 +12,29 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import edu.kit.kastel.mcse.ardoco.core.common.collection.UnmodifiableLinkedHashMap;
import edu.kit.kastel.mcse.ardoco.core.common.collection.UnmodifiableLinkedHashSet;
import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic;

/**
* This class represents an abbreviation with a known set of meanings. An abbreviation is a string such as "ArDoCo" and has the meaning "Architecture
* Documentation Consistency". The abbreviation that is disambiguated by the meanings of this class is final, but the meanings can be changed. An instance of
* this class can be serialized and deserialized into JSON using Jackson.
*/
@Deterministic
@JsonSerialize(using = Disambiguation.DisambiguationSerializer.class)
public class Disambiguation implements Comparable<Disambiguation>, Serializable {
private final String abbreviation;
private final LinkedHashSet<String> meanings;
private final SortedSet<String> meanings;

public @NotNull String getAbbreviation() {
public String getAbbreviation() {
return abbreviation;
}

public @NotNull UnmodifiableLinkedHashSet<String> getMeanings() {
return new UnmodifiableLinkedHashSet<>(meanings);
public SortedSet<String> getMeanings() {
return new TreeSet<>(meanings);
}

@Override
public int compareTo(@NotNull Disambiguation o) {
public int compareTo(Disambiguation o) {
return abbreviation.compareTo(o.abbreviation);
}

Expand Down Expand Up @@ -84,8 +78,8 @@ public void serialize(Disambiguation abbreviation, JsonGenerator jsonGenerator,
* @param meanings an array of meanings for the abbreviation, may be empty
*/
@JsonCreator
public Disambiguation(@JsonProperty("abbreviation") @NotNull String abbreviation, @JsonProperty("meanings") @NotNull String[] meanings) {
this(abbreviation, new LinkedHashSet<>(Arrays.stream(meanings).toList()));
public Disambiguation(@JsonProperty("abbreviation") String abbreviation, @JsonProperty("meanings") String[] meanings) {
this(abbreviation, new TreeSet<>(Arrays.stream(meanings).toList()));
}

/**
Expand All @@ -94,9 +88,9 @@ public Disambiguation(@JsonProperty("abbreviation") @NotNull String abbreviation
* @param abbreviation the abbreviation that is disambiguated by this instance
* @param meanings a set of meanings for the abbreviation, may be empty
*/
public Disambiguation(@NotNull String abbreviation, @NotNull LinkedHashSet<String> meanings) {
public Disambiguation(String abbreviation, SortedSet<String> meanings) {
this.abbreviation = abbreviation;
this.meanings = meanings;
this.meanings = new TreeSet<>(meanings);
}

/**
Expand All @@ -105,7 +99,7 @@ public Disambiguation(@NotNull String abbreviation, @NotNull LinkedHashSet<Strin
* @param other the other disambiguation
* @return this
*/
public @NotNull Disambiguation addMeanings(Disambiguation other) {
public Disambiguation addMeanings(Disambiguation other) {
meanings.addAll(other.meanings);
return this;
}
Expand All @@ -117,7 +111,7 @@ public Disambiguation(@NotNull String abbreviation, @NotNull LinkedHashSet<Strin
* @param ignoreCase whether letter case should be ignored when searching for the meanings
* @return the abbreviated text
*/
public @NotNull String replaceMeaningWithAbbreviation(@NotNull String text, boolean ignoreCase) {
public String replaceMeaningWithAbbreviation(String text, boolean ignoreCase) {
var abbreviatedText = text;
for (String meaning : meanings) {
String pattern = ignoreCase ? "(?i)" : "";
Expand All @@ -127,32 +121,16 @@ public Disambiguation(@NotNull String abbreviation, @NotNull LinkedHashSet<Strin
return abbreviatedText;
}

/**
* Creates a map with entries mapping each abbreviation to its disambiguation. This is useful if a list of disambiguations has to be searched for a
* particular abbreviation regularly.
*
* @param disambiguations a list of disambiguations, may be empty
* @return an immutable map
*/
public @NotNull static UnmodifiableLinkedHashMap<String, Disambiguation> toMap(@NotNull List<Disambiguation> disambiguations) {
var map = new LinkedHashMap<String, Disambiguation>();
for (var disambiguation : disambiguations) {
map.merge(disambiguation.getAbbreviation(), disambiguation, Disambiguation::addMeanings);
}
return new UnmodifiableLinkedHashMap<>(map);
}

/**
* Merges the first map with the second map in a new map. If a key already exists, the disambiguations are merged non-destructively.
*
* @param a the first map
* @param b the second map
* @return a mutable map
*/
@NotNull
public static LinkedHashMap<String, Disambiguation> merge(@NotNull UnmodifiableLinkedHashMap<String, Disambiguation> a,
@NotNull UnmodifiableLinkedHashMap<String, Disambiguation> b) {
var mergedMap = new LinkedHashMap<>(a);

public static SortedMap<String, Disambiguation> merge(SortedMap<String, Disambiguation> a, SortedMap<String, Disambiguation> b) {
var mergedMap = new TreeMap<>(a);
for (var entry : b.entrySet()) {
mergedMap.merge(entry.getKey(), entry.getValue(), Disambiguation::merge);
}
Expand All @@ -166,9 +144,9 @@ public static LinkedHashMap<String, Disambiguation> merge(@NotNull UnmodifiableL
* @param b second ambiguation
* @return new merged disambiguation
*/
@NotNull
public static Disambiguation merge(@NotNull Disambiguation a, @NotNull Disambiguation b) {
var temp = new LinkedHashSet<>(a.meanings);

public static Disambiguation merge(Disambiguation a, Disambiguation b) {
var temp = new TreeSet<>(a.meanings);
temp.addAll(b.meanings);
return new Disambiguation(a.abbreviation, temp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.Comparator;
import java.util.Optional;

import org.jetbrains.annotations.NotNull;

import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityComparable;
import edu.kit.kastel.mcse.ardoco.core.data.MetaData;

Expand All @@ -32,7 +30,7 @@ public record BoundingBox(int minX, int minY, int maxX, int maxY) implements Com
* @param other another bounding box
* @return the optional bounding box
*/
public @NotNull Optional<BoundingBox> intersect(@NotNull BoundingBox other) {
public Optional<BoundingBox> intersect(BoundingBox other) {
if (minX() > other.maxX() || maxX() < other.minX() || minY() > other.maxY() || maxY() < other.minY())
return Optional.empty();
return Optional.of(new BoundingBox(Math.max(minX(), other.minX()), Math.max(minY(), other.minY()), Math.min(maxX(), other.maxX()), Math.min(maxY(),
Expand All @@ -45,7 +43,7 @@ public record BoundingBox(int minX, int minY, int maxX, int maxY) implements Com
* @param other another bounding box
* @return the area >= 0
*/
public double union(@NotNull BoundingBox other) {
public double union(BoundingBox other) {
var i = intersect(other).map(BoundingBox::area).orElse(0.0);
return area() + other.area() - i;
}
Expand All @@ -56,7 +54,7 @@ public double union(@NotNull BoundingBox other) {
* @param other another bounding box
* @return a new bounding box
*/
public @NotNull BoundingBox combine(@NotNull BoundingBox other) {
public BoundingBox combine(BoundingBox other) {
return new BoundingBox(Math.min(minX, other.minX), Math.max(maxX, other.maxX), Math.min(minY, other.minY), Math.max(maxY, other.maxY));
}

Expand All @@ -75,7 +73,7 @@ public double area() {
* @param other another bounding box
* @return iou in the range [0,1]
*/
public double intersectionOverUnion(@NotNull BoundingBox other) {
public double intersectionOverUnion(BoundingBox other) {
return intersect(other).map(i -> i.area() / union(other)).orElse(0.0);
}

Expand All @@ -85,7 +83,7 @@ public double intersectionOverUnion(@NotNull BoundingBox other) {
* @param other another bounding box
* @return percentage in the range [0,1]
*/
public double contains(@NotNull BoundingBox other) {
public double contains(BoundingBox other) {
return contains(other, false);
}

Expand All @@ -109,7 +107,7 @@ public double contains(BoundingBox other, boolean considerArea) {
* @param other a {@link BoundingBox}
* @return true if contained entirely, false otherwise
*/
public boolean containsEntirely(@NotNull BoundingBox other) {
public boolean containsEntirely(BoundingBox other) {
return Double.compare(contains(other, true), 1.0) == 0;
}

Expand Down Expand Up @@ -142,7 +140,7 @@ public boolean similar(MetaData metaData, BoundingBox obj) {
}

@Override
public int compareTo(@NotNull BoundingBox o) {
public int compareTo(BoundingBox o) {
if (equals(o))
return 0;
return Comparator.comparing(BoundingBox::minX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;

import org.jetbrains.annotations.NotNull;
import java.util.SortedSet;
import java.util.TreeSet;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import edu.kit.kastel.mcse.ardoco.core.common.collection.UnmodifiableLinkedHashSet;

/**
* This class represents a box that is detected by the image recognition.
*/
Expand All @@ -32,9 +29,9 @@ public class Box extends DiagramElement implements Serializable {
private List<TextBox> textBoxes = new ArrayList<>();
private Color dominatingColor = null;
@JsonIgnore
private LinkedHashSet<String> references = new LinkedHashSet<>();
private SortedSet<String> references = new TreeSet<>();

private static @NotNull String calculateUUID(@NotNull int[] coordinates) {
private static String calculateUUID(int[] coordinates) {
return String.format("Box [%s]", getBoundingBoxConcat(coordinates));
}

Expand All @@ -43,7 +40,7 @@ public class Box extends DiagramElement implements Serializable {
*
* @param coordinates bounding box coordinates
*/
public static @NotNull String getBoundingBoxConcat(@NotNull int[] coordinates) {
public static String getBoundingBoxConcat(int[] coordinates) {
return Arrays.stream(coordinates).mapToObj((Integer::toString)).reduce((l, r) -> l + "-" + r).orElseThrow();
}

Expand Down Expand Up @@ -98,7 +95,7 @@ public int area() {
*
* @return a UUID of the box
*/
public @NotNull String getUUID() {
public String getUUID() {
return getName();
}

Expand All @@ -125,7 +122,7 @@ public double getConfidence() {
*
* @return the classification
*/
public @NotNull Classification getClassification() {
public Classification getClassification() {
return Classification.byString(classification);
}

Expand All @@ -143,7 +140,7 @@ public void addTextBox(TextBox textBox) {
*
* @param textBox the textbox
*/
public void removeTextBox(@NotNull TextBox textBox) {
public void removeTextBox(TextBox textBox) {
Objects.requireNonNull(textBox);
this.textBoxes.removeIf(it -> it == textBox);
}
Expand All @@ -153,12 +150,12 @@ public void removeTextBox(@NotNull TextBox textBox) {
*
* @return all associated text boxes
*/
public @NotNull List<TextBox> getTexts() {
public List<TextBox> getTexts() {
return new ArrayList<>(textBoxes);
}

public @NotNull UnmodifiableLinkedHashSet<String> getReferences() {
return new UnmodifiableLinkedHashSet<>(references);
public SortedSet<String> getReferences() {
return new TreeSet<>(references);
}

/**
Expand All @@ -167,12 +164,12 @@ public void removeTextBox(@NotNull TextBox textBox) {
* @param reference the reference string
* @return true if the reference wasn't already contained, false otherwise
*/
public boolean addReference(@NotNull String reference) {
public boolean addReference(String reference) {
return references.add(reference);
}

public void setReferences(@NotNull List<String> references) {
this.references = new LinkedHashSet<>(references);
public void setReferences(List<String> references) {
this.references = new TreeSet<>(references);
}

/**
Expand All @@ -181,7 +178,7 @@ public void setReferences(@NotNull List<String> references) {
* @param reference the reference
* @return true if removed, false otherwise
*/
public boolean removeReference(@NotNull String reference) {
public boolean removeReference(String reference) {
return references.remove(reference);
}

Expand All @@ -190,7 +187,7 @@ public boolean removeReference(@NotNull String reference) {
*
* @return the dominating color or {@code null} if not present
*/
public @NotNull Color getDominatingColor() {
public Color getDominatingColor() {
return dominatingColor;
}

Expand All @@ -199,12 +196,12 @@ public boolean removeReference(@NotNull String reference) {
*
* @param dominatingColor the dominating color
*/
public void setDominatingColor(@NotNull Color dominatingColor) {
public void setDominatingColor(Color dominatingColor) {
this.dominatingColor = dominatingColor;
}

@Override
public @NotNull BoundingBox getBoundingBox() {
public BoundingBox getBoundingBox() {
return new BoundingBox(coordinates[0], coordinates[1], coordinates[2], coordinates[3]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.io.Serializable;
import java.util.List;

import org.jetbrains.annotations.NotNull;

import edu.kit.kastel.mcse.ardoco.core.common.util.SimilarityComparable;
import edu.kit.kastel.mcse.ardoco.core.data.MetaData;

Expand Down Expand Up @@ -64,7 +62,7 @@ default boolean similar(MetaData metaData, Diagram obj) {
}

@Override
default int compareTo(@NotNull Diagram o) {
default int compareTo(Diagram o) {
if (equals(o))
return 0;
return getResourceName().compareTo(o.getResourceName());
Expand Down
Loading

0 comments on commit 1e84ac2

Please sign in to comment.