Fixed an issue that would cause capacitors to fail when creating, editing, moving or deleting

This commit is contained in:
Bane Stojkovic
2022-11-16 22:44:36 +01:00
parent cf791ac259
commit e7fcebcf96
3 changed files with 9 additions and 79 deletions
@@ -161,8 +161,8 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public IDIYComponent<T> clone() throws CloneNotSupportedException { public IDIYComponent<T> clone() throws CloneNotSupportedException {
try { try {
// Instantiate object of the same type // Instantiate object of the same type
AbstractComponent<T> newInstance = (AbstractComponent<T>) this.getClass().getConstructors()[0].newInstance();
Class<?> clazz = this.getClass(); Class<?> clazz = this.getClass();
AbstractComponent<T> newInstance = (AbstractComponent<T>) clazz.newInstance();
while (AbstractComponent.class.isAssignableFrom(clazz)) { while (AbstractComponent.class.isAssignableFrom(clazz)) {
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
clazz = clazz.getSuperclass(); clazz = clazz.getSuperclass();
@@ -181,6 +181,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
Object newArray = Array.newInstance(value.getClass().getComponentType(), Array.getLength(value)); Object newArray = Array.newInstance(value.getClass().getComponentType(), Array.getLength(value));
for (int i = 0; i < Array.getLength(value); i++) { for (int i = 0; i < Array.getLength(value); i++) {
Point2D p = (Point2D) Array.get(value, i); Point2D p = (Point2D) Array.get(value, i);
if (p != null)
Array.set(newArray, i, new Point2D.Double(p.getX(), p.getY())); Array.set(newArray, i, new Point2D.Double(p.getX(), p.getY()));
} }
value = newArray; value = newArray;
@@ -1,75 +0,0 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.core.annotations;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public final class Defaults {
private Defaults() {}
private static final Map<Class<?>, Object> DEFAULTS;
static {
// Only add to this map via put(Map, Class<T>, T)
Map<Class<?>, Object> map = new HashMap<Class<?>, Object>();
put(map, boolean.class, false);
put(map, Boolean.class, false);
put(map, char.class, '\0');
put(map, byte.class, (byte) 0);
put(map, Byte.class, (byte) 0);
put(map, short.class, (short) 0);
put(map, Short.class, (short) 0);
put(map, int.class, 0);
put(map, Integer.class, 0);
put(map, long.class, 0L);
put(map, Long.class, 0L);
put(map, float.class, 0f);
put(map, Float.class, 0f);
put(map, double.class, 0d);
put(map, Double.class, 0d);
DEFAULTS = Collections.unmodifiableMap(map);
}
private static <T> void put(Map<Class<?>, Object> map, Class<T> type, T value) {
map.put(type, value);
}
/**
* Returns the default value of {@code type} as defined by JLS --- {@code 0} for numbers,
* {@code false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types
* and {@code void}, {@code null} is returned.
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static <T> T defaultValue(Class<T> type) throws Exception {
// Primitives.wrap(type).cast(...) would avoid the warning, but we can't use that from here
// the put method enforces this key-value relationship
T t = (T) DEFAULTS.get(type);
if (t == null) {
return (T) type.getConstructors()[0].newInstance();
}
return t;
}
}
@@ -4154,6 +4154,10 @@
<releaseDate>2022-11-11 00:00:00.000 CET</releaseDate> <releaseDate>2022-11-11 00:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Fixed an issue that would cause capacitors to fail when creating, editing, moving or deleting</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Added standard models in the drop down menu of the component toolbar</description> <description>Added standard models in the drop down menu of the component toolbar</description>