diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/FormatExtension.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/FormatExtension.java new file mode 100644 index 000000000..8b22d8c6e --- /dev/null +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/FormatExtension.java @@ -0,0 +1,93 @@ +/* + * @(#)FormatExtension.java + * + * Copyright (c) 2025 The authors and contributors of JHotDraw. + * You may not use, copy or modify this file, except in compliance with the + * accompanying license terms. + */ +package org.jhotdraw.draw.io; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +public final class FormatExtension { + + private final String extension; + + /** + * Creates a new format extension. + * + * @param extension the file extension (without leading dot) + * @throws IllegalArgumentException if extension is null or empty + */ + public FormatExtension(String extension) { + if (extension == null || extension.trim().isEmpty()) { + throw new IllegalArgumentException("Extension cannot be null or empty"); + } + // Normalize to lowercase for consistent comparison + this.extension = extension.trim().toLowerCase(); + } + + /** + * Returns the normalized extension string. + * + * @return the extension in lowercase + */ + public String getValue() { + return extension; + } + + /** + * Checks if this extension matches the given string (case-insensitive). + * + * @param other the string to compare + * @return true if they match + */ + public boolean matches(String other) { + if (other == null) { + return false; + } + return extension.equalsIgnoreCase(other.trim()); + } + + /** + * Creates a set of FormatExtension objects from an array of strings. + * + * @param extensions array of extension strings + * @return immutable set of FormatExtension objects + */ + public static Set createSet(String... extensions) { + if (extensions == null || extensions.length == 0) { + return Collections.emptySet(); + } + Set set = new HashSet<>(); + for (String ext : extensions) { + if (ext != null && !ext.trim().isEmpty()) { + set.add(new FormatExtension(ext)); + } + } + return Collections.unmodifiableSet(set); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + FormatExtension that = (FormatExtension) obj; + return extension.equals(that.extension); + } + + @Override + public int hashCode() { + return Objects.hash(extension); + } + + @Override + public String toString() { + return extension; + } +} + diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatProvider.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatProvider.java index e159358a7..58e289c6d 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatProvider.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatProvider.java @@ -21,9 +21,6 @@ *
  • Register with {@link ImageFormatRegistry#registerProvider(ImageFormatProvider)}
  • *
  • Or add to META-INF/services/org.jhotdraw.draw.io.ImageFormatProvider for SPI
  • * - * - * @author JHotDraw - * @version $Id$ */ public interface ImageFormatProvider { diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatRegistry.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatRegistry.java index 7a5ca9f7e..782642ef2 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatRegistry.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/ImageFormatRegistry.java @@ -26,9 +26,6 @@ * List<InputFormat> formats = ImageFormatRegistry.getInputFormats(myImageFigure); * drawing.getInputFormats().addAll(formats); * - * - * @author JHotDraw - * @version $Id$ */ public final class ImageFormatRegistry { diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/JpegFormatProvider.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/JpegFormatProvider.java index 894a77a4c..275950fd8 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/JpegFormatProvider.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/JpegFormatProvider.java @@ -15,9 +15,6 @@ * *

    JPEG uses lossy compression, making it ideal for photographs * and images with smooth color gradients. Supports both .jpg and .jpeg extensions.

    - * - * @author JHotDraw - * @version $Id$ */ public class JpegFormatProvider implements ImageFormatProvider { diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/PngFormatProvider.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/PngFormatProvider.java index e5d0c23b7..828043c29 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/PngFormatProvider.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/io/PngFormatProvider.java @@ -15,9 +15,6 @@ * *

    PNG supports lossless compression and transparency (alpha channel), * making it ideal for graphics with sharp edges or text.

    - * - * @author JHotDraw - * @version $Id$ */ public class PngFormatProvider implements ImageFormatProvider { diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java index 1e2175e37..aae6219ba 100644 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java +++ b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java @@ -32,8 +32,6 @@ /** * Comprehensive unit tests for RectangleFigure using JUnit 4, AssertJ, and Mockito. * Tests focus on geometric operations, boundary conditions, and drawing behavior. - * - * @author JHotDraw Team */ public class RectangleFigureTest {