diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/AdditionalClassForDotNetSimulation.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/AdditionalClassForDotNetEmulation.java similarity index 91% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/AdditionalClassForDotNetSimulation.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/AdditionalClassForDotNetEmulation.java index c131da8..96930a4 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/AdditionalClassForDotNetSimulation.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/AdditionalClassForDotNetEmulation.java @@ -17,6 +17,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface AdditionalClassForDotNetSimulation { +public @interface AdditionalClassForDotNetEmulation { String note() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/const_.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/const_.java index 3884041..a3fa2ff 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/const_.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/const_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public @interface const_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/internal.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/internal_.java similarity index 82% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/internal.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/internal_.java index 7f46e7e..a49b180 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/internal.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/internal_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR}) -@AdditionalClassForDotNetSimulation -public @interface internal { +@AdditionalClassForDotNetEmulation +public @interface internal_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/namespace.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/namespace_.java similarity index 80% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/namespace.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/namespace_.java index f6e7c5e..5ef8d58 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/namespace.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/namespace_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -@AdditionalClassForDotNetSimulation -public @interface namespace { +@AdditionalClassForDotNetEmulation +public @interface namespace_ { String name(); } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/nullable.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/nullable_.java similarity index 80% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/nullable.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/nullable_.java index 7ff0bee..08e5e71 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/nullable.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/nullable_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) -@AdditionalClassForDotNetSimulation -public @interface nullable { +@AdditionalClassForDotNetEmulation +public @interface nullable_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/out.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/out_.java similarity index 81% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/out.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/out_.java index edcf3a0..ed489f8 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/out.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/out_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) -@AdditionalClassForDotNetSimulation -public @interface out { +@AdditionalClassForDotNetEmulation +public @interface out_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/readonly.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/readonly_.java similarity index 81% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/readonly.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/readonly_.java index a13eb49..3f5d8b4 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/readonly.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/readonly_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE_USE, ElementType.FIELD}) -@AdditionalClassForDotNetSimulation -public @interface readonly { +@AdditionalClassForDotNetEmulation +public @interface readonly_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/ref.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/ref_.java similarity index 81% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/ref.java rename to src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/ref_.java index 059ebad..466cecd 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/ref.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/ref_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) -@AdditionalClassForDotNetSimulation -public @interface ref { +@AdditionalClassForDotNetEmulation +public @interface ref_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/static_.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/static_.java index db2e0fc..82867b5 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/static_.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/static_.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public @interface static_ { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/struct.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/struct.java index f32acb1..31e135a 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/struct.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/CSharpKeyWords/struct.java @@ -4,14 +4,14 @@ */ package com.openeggbert.jdotnet.JDotNet.CSharpKeyWords; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; /** * * @author robertvokac */ -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public abstract class struct { public abstract T copy(); /** diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/AbstractPropertyImpl.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/AbstractPropertyImpl.java new file mode 100644 index 0000000..8010c54 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/AbstractPropertyImpl.java @@ -0,0 +1,32 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +/** + * An abstract base class for implementing property-like behavior. + * + * This class provides a protected field "value" that can be used by subclasses + * to manage the state of the property. The type of the property value is defined + * by the generic type parameter . + * + * Subclasses can provide specific implementations of read-only, write-only, + * or read-write properties by exposing appropriate methods for access or modification + * of the "value" field. + * + * @param the type of the property's value + */ +@AllArgsConstructor +@NoArgsConstructor +public abstract class AbstractPropertyImpl { + /** + * The value stored by the property. + * + * This field is protected to allow subclasses to directly manage + * the property's value, while providing flexibility for implementing + * specific behaviors such as read-only, write-only, or read-write access. + * + * @param the type of the property's value + */ + protected T value; +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IObservable.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IObservable.java new file mode 100644 index 0000000..1b9f43f --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IObservable.java @@ -0,0 +1,8 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +import java.util.function.Consumer; + +@FunctionalInterface +public interface IObservable { + void addObserver(Consumer listener); +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IProperty.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IProperty.java new file mode 100644 index 0000000..6692149 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IProperty.java @@ -0,0 +1,12 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +/** + * Represents a property that supports both read and write operations for a value of type T. + * + * The interface extends both IReadOnlyProperty and IWriteOnlyProperty, combining their + * functionality to provide a complete property interface. + * + * @param the type of the property's value + */ +public interface IProperty extends IReadOnlyProperty, IWriteOnlyProperty { +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IPropertyChangeListener.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IPropertyChangeListener.java new file mode 100644 index 0000000..75bac47 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IPropertyChangeListener.java @@ -0,0 +1,6 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +@FunctionalInterface +public interface IPropertyChangeListener { + void propertyChanged(T oldValue, T newValue); +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IReadOnlyProperty.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IReadOnlyProperty.java new file mode 100644 index 0000000..8673519 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IReadOnlyProperty.java @@ -0,0 +1,20 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +/** + * Represents a read-only property for a value of type T. + * + * This interface defines a single method to retrieve the property value, + * ensuring that implementing classes provide read access while prohibiting + * modification of the value it holds. + * + * @param the type of the property's value + */ +@FunctionalInterface +public interface IReadOnlyProperty { + /** + * Retrieves the value of the property. + * + * @return the current value of the property + */ + T get(); +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IWriteOnlyProperty.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IWriteOnlyProperty.java new file mode 100644 index 0000000..6e26abb --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/IWriteOnlyProperty.java @@ -0,0 +1,20 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +/** + * Represents a write-only property for a value of type T. + * + * This interface defines a single method to set the property value, + * ensuring that implementing classes provide write access while prohibiting + * retrieval of the value it holds. + * + * @param the type of the property's value + */ +@FunctionalInterface +public interface IWriteOnlyProperty { + /** + * Sets the value for the property. + * + * @param value the value to set for the property + */ + void set(T value); +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/ObservablePropertyImpl.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/ObservablePropertyImpl.java new file mode 100644 index 0000000..f0ac158 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/ObservablePropertyImpl.java @@ -0,0 +1,85 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +/** + * A concrete implementation of the IProperty interface, providing both + * read and write access to a property of type T. + *

+ * This class extends AbstractPropertyImpl, leveraging its protected "value" field + * to store the property's data, and implements the getter and setter methods + * as specified by the IProperty interface. + * + * @param the type of the property's value + */ +public class ObservablePropertyImpl extends PropertyImpl implements IObservable{ + + private List> observers = new ArrayList<>(); + private final List> changeListeners = new ArrayList<>(); + + public ObservablePropertyImpl(IReadOnlyProperty readOnlyPropertyIn, IWriteOnlyProperty writeOnlyPropertyIn) { + super(readOnlyPropertyIn, writeOnlyPropertyIn); + } + + public ObservablePropertyImpl(IReadOnlyProperty readOnlyPropertyIn, IWriteOnlyProperty writeOnlyPropertyIn, Validator validator) { + super(readOnlyPropertyIn, writeOnlyPropertyIn, validator); + } + public ObservablePropertyImpl(T initialValue) { + super(initialValue); + } + public ObservablePropertyImpl(T initialValue, Validator validator) { + super(initialValue, validator); + } + @Override + public void set(T valueIn) { + T oldValue = this.get(); + super.set(valueIn); + if(!observers.isEmpty()) { + notifyListeners(valueIn); + } + if(!changeListeners.isEmpty()) { + notifyChangeListeners(oldValue, valueIn); + } + } + + private void notifyListeners(T value) { + for (Consumer listener : observers) { + listener.accept(value); + } + } + private void notifyChangeListeners(T oldValue, T newValue) { + for (IPropertyChangeListener listener : changeListeners) { + listener.propertyChanged(oldValue, newValue); + } + } + + public void addChangeListener(IPropertyChangeListener changeListener) { + changeListeners.add(changeListener); + } + + public void removeChangeListener(IPropertyChangeListener changeListener) { + changeListeners.remove(changeListener); + } + + + public void addObserver(Consumer listener) { + observers.add(listener); + } + + public void removeObserver(Consumer listener) { + observers.remove(listener); + } + + public boolean hasListeners() { + return !observers.isEmpty() || !changeListeners.isEmpty(); + } + public boolean hasObservers() { + return !observers.isEmpty(); + } + public boolean hasChangeListeners() { + return !changeListeners.isEmpty(); + } + +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/PropertyImpl.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/PropertyImpl.java new file mode 100644 index 0000000..ca755c6 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/PropertyImpl.java @@ -0,0 +1,73 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +import java.util.Objects; + +/** + * A concrete implementation of the IProperty interface, providing both + * read and write access to a property of type T. + *

+ * This class extends AbstractPropertyImpl, leveraging its protected "value" field + * to store the property's data, and implements the getter and setter methods + * as specified by the IProperty interface. + * + * @param the type of the property's value + */ +public class PropertyImpl extends AbstractPropertyImpl implements IProperty { + + private IReadOnlyProperty readOnlyProperty; + private IWriteOnlyProperty writeOnlyProperty; + + private final Validator validator; + + public PropertyImpl(IReadOnlyProperty readOnlyPropertyIn, IWriteOnlyProperty writeOnlyPropertyIn) { + this(readOnlyPropertyIn, writeOnlyPropertyIn, null); + } + public PropertyImpl(IReadOnlyProperty readOnlyPropertyIn, IWriteOnlyProperty writeOnlyPropertyIn, Validator validator) { + this.readOnlyProperty = Objects.requireNonNull(readOnlyPropertyIn, "readOnlyPropertyIn cannot be null."); + this.writeOnlyProperty = Objects.requireNonNull(writeOnlyPropertyIn, "writeOnlyPropertyIn cannot be null."); + this.value = null; + this.validator = validator; + } + + public PropertyImpl(T initialValue) { + this(initialValue, null); + } + + public PropertyImpl(T initialValue, Validator validator) { + this.value = initialValue; + this.readOnlyProperty = null; + this.writeOnlyProperty = null; + this.validator = validator; + } + + /** + * Sets the value for the property. + * + * @param valueIn the value to set for the property + */ + @Override + public void set(T valueIn) { + if (validator != null) { + validator.validate(valueIn); + } + if (writeOnlyProperty != null) { + writeOnlyProperty.set(valueIn); + } else { + this.value = valueIn; + } + } + + /** + * Retrieves the current value of the property. + * + * @return the current value of the property + */ + @Override + public T get() { + if (readOnlyProperty != null) { + return readOnlyProperty.get(); + } else { + return value; + } + } +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/ReadOnlyPropertyImpl.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/ReadOnlyPropertyImpl.java new file mode 100644 index 0000000..1eae70f --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/ReadOnlyPropertyImpl.java @@ -0,0 +1,30 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +/** + * A concrete implementation of a read-only property for a value of type T. + * + * This class extends AbstractPropertyImpl to inherit its protected "value" field + * for storing the state of the property. As a read-only property, it implements + * the IReadOnlyProperty interface, providing only a getter method to retrieve + * the current value of the property while prohibiting any modifications. + * + * @param the type of the property's value + */ + +@AllArgsConstructor +@NoArgsConstructor +public class ReadOnlyPropertyImpl extends AbstractPropertyImpl implements IReadOnlyProperty { + + /** + * Retrieves the current value of the property. + * + * @return the current value of the property + */ + @Override + public T get() { + return value; + } +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/Validator.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/Validator.java new file mode 100644 index 0000000..69b4f90 --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/Validator.java @@ -0,0 +1,5 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; +@FunctionalInterface +public interface Validator { + void validate(T value) throws IllegalArgumentException; +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/WriteOnlyPropertyImpl.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/WriteOnlyPropertyImpl.java new file mode 100644 index 0000000..25d8a9b --- /dev/null +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/Properties/WriteOnlyPropertyImpl.java @@ -0,0 +1,30 @@ +package com.openeggbert.jdotnet.JDotNet.Properties; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +/** + * A concrete implementation of a write-only property for a value of type T. + * + * This class extends AbstractPropertyImpl, leveraging its protected "value" field + * to store the property's data. It implements the IWriteOnlyProperty interface, + * providing a setter method to modify the property's value while prohibiting + * access to retrieve it. + * + * @param the type of the property's value + */ + +@AllArgsConstructor +@NoArgsConstructor +public class WriteOnlyPropertyImpl extends AbstractPropertyImpl implements IWriteOnlyProperty { + + /** + * Sets the value for the property. + * + * @param valueIn the value to set for the property + */ + @Override + public void set(T valueIn) { + this.value = valueIn; + } +} diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/UnusedCode.java b/src/main/java/com/openeggbert/jdotnet/JDotNet/UnusedCode.java index 6fee9f5..71b25e6 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/UnusedCode.java +++ b/src/main/java/com/openeggbert/jdotnet/JDotNet/UnusedCode.java @@ -16,7 +16,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_USE) -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public @interface UnusedCode { String description() default ""; } diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Microsoft/Devices/Sensors/AccelerometerFailedException.java b/src/main/java/com/openeggbert/jdotnet/Microsoft/Sensors/AccelerometerFailedException.java similarity index 82% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/Microsoft/Devices/Sensors/AccelerometerFailedException.java rename to src/main/java/com/openeggbert/jdotnet/Microsoft/Sensors/AccelerometerFailedException.java index 741a1de..e3947f0 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/Microsoft/Devices/Sensors/AccelerometerFailedException.java +++ b/src/main/java/com/openeggbert/jdotnet/Microsoft/Sensors/AccelerometerFailedException.java @@ -2,7 +2,7 @@ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ -package com.openeggbert.jdotnet.JDotNet.Microsoft.Devices.Sensors; +package com.openeggbert.jdotnet.Microsoft.Sensors; /** * diff --git a/src/main/java/com/openeggbert/jdotnet/JDotNet/Microsoft/Devices/Sensors/SensorFailedException.java b/src/main/java/com/openeggbert/jdotnet/Microsoft/Sensors/SensorFailedException.java similarity index 83% rename from src/main/java/com/openeggbert/jdotnet/JDotNet/Microsoft/Devices/Sensors/SensorFailedException.java rename to src/main/java/com/openeggbert/jdotnet/Microsoft/Sensors/SensorFailedException.java index f977a64..2c5a758 100644 --- a/src/main/java/com/openeggbert/jdotnet/JDotNet/Microsoft/Devices/Sensors/SensorFailedException.java +++ b/src/main/java/com/openeggbert/jdotnet/Microsoft/Sensors/SensorFailedException.java @@ -2,7 +2,7 @@ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ -package com.openeggbert.jdotnet.JDotNet.Microsoft.Devices.Sensors; +package com.openeggbert.jdotnet.Microsoft.Sensors; import com.openeggbert.jdotnet.System.Exception_; diff --git a/src/main/java/com/openeggbert/jdotnet/System/Boolean.java b/src/main/java/com/openeggbert/jdotnet/System/Boolean.java index 98a6094..eb8f6bd 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/Boolean.java +++ b/src/main/java/com/openeggbert/jdotnet/System/Boolean.java @@ -7,23 +7,22 @@ package com.openeggbert.jdotnet.System; import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.struct; import lombok.AccessLevel; import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.readonly; -import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.const_; +import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.readonly_; /** * * @author robertvokac */ @AllArgsConstructor(access = AccessLevel.PRIVATE) -@readonly +@readonly_ class Boolean extends struct { protected Boolean() { this.m_value = false; //Not meant to be instantiated. } - private @readonly final boolean m_value; + private @readonly_ + final boolean m_value; public boolean get() { return m_value; } diff --git a/src/main/java/com/openeggbert/jdotnet/System/Event.java b/src/main/java/com/openeggbert/jdotnet/System/Event.java index a40811f..49fa7cf 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/Event.java +++ b/src/main/java/com/openeggbert/jdotnet/System/Event.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.System; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -18,7 +18,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public @interface Event { String description() default "Event handler"; } diff --git a/src/main/java/com/openeggbert/jdotnet/System/EventHandlerImpl.java b/src/main/java/com/openeggbert/jdotnet/System/EventHandlerImpl.java index ab61c4c..0dec181 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/EventHandlerImpl.java +++ b/src/main/java/com/openeggbert/jdotnet/System/EventHandlerImpl.java @@ -4,15 +4,21 @@ */ package com.openeggbert.jdotnet.System; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; import java.util.ArrayList; import java.util.List; /** + * An implementation of the EventHandler interface, responsible for managing + * event listeners and invoking them when an event occurs. * - * @author robertvokac + * @param The type of event arguments that will be passed to the listeners. + * + * This class simulates the behavior of C# event handling. + * It allows adding and removing event listeners, as well as invoking them + * with the provided event arguments. */ -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public class EventHandlerImpl implements EventHandler { private final List> list = new ArrayList<>(); diff --git a/src/main/java/com/openeggbert/jdotnet/System/EventListener.java b/src/main/java/com/openeggbert/jdotnet/System/EventListener.java index 35ff880..985d635 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/EventListener.java +++ b/src/main/java/com/openeggbert/jdotnet/System/EventListener.java @@ -4,13 +4,13 @@ */ package com.openeggbert.jdotnet.System; -import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetSimulation; +import com.openeggbert.jdotnet.JDotNet.AdditionalClassForDotNetEmulation; /** * * @author robertvokac */ -@AdditionalClassForDotNetSimulation +@AdditionalClassForDotNetEmulation public interface EventListener{ void onEventHappened(T eventArgs); diff --git a/src/main/java/com/openeggbert/jdotnet/System/Resources/ResourceManager.java b/src/main/java/com/openeggbert/jdotnet/System/Resources/ResourceManager.java index fb0c8fb..6bcef47 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/Resources/ResourceManager.java +++ b/src/main/java/com/openeggbert/jdotnet/System/Resources/ResourceManager.java @@ -4,7 +4,7 @@ */ package com.openeggbert.jdotnet.System.Resources; -import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.nullable; +import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.nullable_; import com.openeggbert.jdotnet.System.Globalization.CultureInfo; import com.openeggbert.jdotnet.System.Reflection.Assembly; @@ -14,7 +14,7 @@ import com.openeggbert.jdotnet.System.Reflection.Assembly; */ public class ResourceManager { - public static String GetString(String name, @nullable CultureInfo culture) { + public static String GetString(String name, @nullable_ CultureInfo culture) { return null; //todo } diff --git a/src/main/java/com/openeggbert/jdotnet/System/String_.java b/src/main/java/com/openeggbert/jdotnet/System/String_.java index 95cf7a5..b5f4ecb 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/String_.java +++ b/src/main/java/com/openeggbert/jdotnet/System/String_.java @@ -10,8 +10,13 @@ import java.util.regex.Pattern; import lombok.Getter; /** + * The String_ class provides a set of utility functions to work with strings, + * including checks for null or empty strings, formatting operations with templates, + * and character repetitions. Helper methods are included to support locale-based + * string formatting and basic type-dependent formatting specifications. * - * @author robertvokac + * This class is not instantiable directly, and its utility methods are designed + * to mirror .NET-style string handling while integrating Java principles. */ public class String_ { @@ -22,10 +27,28 @@ public class String_ { private String value; + /** + * Determines whether the specified string is either null or empty. + * + * @param string the string to check for null or emptiness. + * @return true if the specified string is null or has a length of 0; false otherwise. + */ public static boolean IsNullOrEmpty(String string) { return string == null || string.isEmpty(); } + /** + * Formats a template string by replacing placeholders in the form of `{index}` with corresponding + * arguments from the provided list. The index must be a valid zero-based integer referencing + * the `args` array. + * + * @param template the string template with placeholders in the format `{index}` to be replaced. + * Must not be null. + * @param args the array of objects to be used as replacements for the placeholders. Must not be null. + * @return the formatted string with placeholders replaced by the corresponding arguments from `args`. + * @throws IllegalArgumentException if `template` or `args` is null, if a placeholder is invalid, + * or if the placeholder index is out of range. + */ public static String Format(String template, Object... args) { if (template == null || args == null) { throw new IllegalArgumentException("Template and arguments must not be null."); @@ -64,6 +87,14 @@ public class String_ { return result.toString(); } + /** + * Constructs a new instance of the String_ class, initializing its value with a repeated + * sequence of the specified character. + * + * @param ch the character to be repeated to form the string value. + * @param times the number of times to repeat the character. Must be non-negative. + * @throws Exception_ if the value of the parameter `times` is less than 0. + */ public String_(char ch, int times) { if(times < 0) { throw new Exception_("times cannot be less than 0"); diff --git a/src/main/java/com/openeggbert/jdotnet/System/TimeSpan.java b/src/main/java/com/openeggbert/jdotnet/System/TimeSpan.java index 3bb2666..5fcaa80 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/TimeSpan.java +++ b/src/main/java/com/openeggbert/jdotnet/System/TimeSpan.java @@ -9,8 +9,8 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; /** - * - * @author robertvokac + * Represents a time interval and provides methods to manipulate and instantiate time intervals. + * The time interval is internally stored in ticks. */ @AllArgsConstructor @NoArgsConstructor @@ -23,6 +23,11 @@ public class TimeSpan extends struct { } @Override + /** + * Creates a copy of the current TimeSpan instance. + * + * @return A new TimeSpan object with the same tick value as the current instance. + */ public TimeSpan copy() { return new TimeSpan(_ticks); } diff --git a/src/main/java/com/openeggbert/jdotnet/System/object.java b/src/main/java/com/openeggbert/jdotnet/System/object.java index 6bafb98..863508f 100644 --- a/src/main/java/com/openeggbert/jdotnet/System/object.java +++ b/src/main/java/com/openeggbert/jdotnet/System/object.java @@ -4,14 +4,14 @@ */ package com.openeggbert.jdotnet.System; -import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.nullable; +import com.openeggbert.jdotnet.JDotNet.CSharpKeyWords.nullable_; /** * * @author robertvokac */ public class object { - public static boolean ReferenceEquals(@nullable Object objA, @nullable Object objB) { + public static boolean ReferenceEquals(@nullable_ Object objA, @nullable_ Object objB) { if(objA == null && objB == null) {return true;} if(objA == null || objB == null) {return false;} return objA.equals(objB);