diff options
author | Stephen J. Molaro | 2021-03-31 14:14:30 +0000 |
---|---|---|
committer | Ryan T. Baldwin | 2021-03-31 14:14:30 +0000 |
commit | b088fa0ffde7dc706276a8f4c8c4d564ed6b44d7 (patch) | |
tree | f6c1a934ac53ffe5985439da12c5552e59b7dfbb /plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee | |
parent | 41f77e6d2de8a26fcdcaf1724c8657b5647ae62c (diff) | |
download | org.eclipse.osee-b088fa0ffde7dc706276a8f4c8c4d564ed6b44d7.tar.gz org.eclipse.osee-b088fa0ffde7dc706276a8f4c8c4d564ed6b44d7.tar.xz org.eclipse.osee-b088fa0ffde7dc706276a8f4c8c4d564ed6b44d7.zip |
feature[TW18957]: Add new computed attr type characteristics
Change-Id: Idffc6f1208b14ad5133159d4b92f04369540b306
Signed-off-by: Stephen J. Molaro <stephen.j.molaro@boeing.com>
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee')
13 files changed, 267 insertions, 16 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeDouble.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeDouble.java index d6d9ec6c866..f0cdeb44c57 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeDouble.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeDouble.java @@ -27,6 +27,11 @@ public final class AttributeTypeDouble extends AttributeTypeGeneric<Double> { } @Override + public Double valueFromDouble(double value) { + return value; + } + + @Override public Double valueFromStorageString(String storedValue) { return Double.valueOf(storedValue); } diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeGeneric.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeGeneric.java index 45f884c2927..53b422973f8 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeGeneric.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeGeneric.java @@ -67,6 +67,10 @@ public abstract class AttributeTypeGeneric<T> extends NamedIdDescription impleme return fileExtension; } + public T valueFromDouble(double value) { + return null; + } + /** * @param storedValue is the raw String stored in the database * @return the attribute value in its native Java representation diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeInteger.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeInteger.java index 3702c0840e8..42d75a89929 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeInteger.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeInteger.java @@ -27,6 +27,11 @@ public final class AttributeTypeInteger extends AttributeTypeGeneric<Integer> { } @Override + public Integer valueFromDouble(double value) { + return (int) Math.round(value); + } + + @Override public Integer valueFromStorageString(String storedValue) { return Integer.valueOf(storedValue); } diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeLong.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeLong.java index c702e7a9ac4..f057d1d794c 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeLong.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/AttributeTypeLong.java @@ -27,6 +27,11 @@ public final class AttributeTypeLong extends AttributeTypeGeneric<Long> { } @Override + public Long valueFromDouble(double value) { + return Math.round(value); + } + + @Override public Long valueFromStorageString(String storedValue) { return Long.valueOf(storedValue); } diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristic.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristic.java index 2f07c683b67..bbb1245207d 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristic.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristic.java @@ -26,29 +26,29 @@ public abstract class ComputedCharacteristic<T> extends NamedIdDescription imple private final TaggerTypeToken taggerType; private final NamespaceToken namespace; - protected final List<AttributeTypeGeneric<T>> attributeTypes; + protected final List<AttributeTypeGeneric<T>> typesToCompute; protected final Set<DisplayHint> displayHints; - public ComputedCharacteristic(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> attributeTypes, Set<DisplayHint> displayHints) { + public ComputedCharacteristic(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute, Set<DisplayHint> displayHints) { super(id, name, description); this.namespace = namespace; this.taggerType = taggerType; - this.attributeTypes = attributeTypes; + this.typesToCompute = typesToCompute; this.displayHints = displayHints; } - public ComputedCharacteristic(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> attributeTypes) { - this(id, name, taggerType, namespace, description, attributeTypes, Collections.emptySet()); + public ComputedCharacteristic(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute) { + this(id, name, taggerType, namespace, description, typesToCompute, Collections.emptySet()); } - public ComputedCharacteristic(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> attributeTypes, DisplayHint... displayHints) { - this(id, name, taggerType, namespace, description, attributeTypes, + public ComputedCharacteristic(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute, DisplayHint... displayHints) { + this(id, name, taggerType, namespace, description, typesToCompute, org.eclipse.osee.framework.jdk.core.util.Collections.asHashSet(displayHints)); } @Override - public List<AttributeTypeGeneric<T>> getAttributeTypes() { - return attributeTypes; + public List<AttributeTypeGeneric<T>> getAttributeTypesToCompute() { + return typesToCompute; } @Override @@ -75,15 +75,31 @@ public abstract class ComputedCharacteristic<T> extends NamedIdDescription imple * return true in the case that the computed type only has two valid values. Should be used in isMultiplicityValid() * if only two values are desired. */ - private boolean exactlyTwoValues(ArtifactTypeToken artifactType) { - if (attributeTypes.size() > 2) { + protected boolean exactlyTwoValues(ArtifactTypeToken artifactType) { + if (typesToCompute.size() != 2) { return false; } - for (AttributeTypeGeneric<T> attributeType : attributeTypes) { + for (AttributeTypeGeneric<T> attributeType : typesToCompute) { if (artifactType.getMax(attributeType) > 1) { return false; } } return true; } + + /** + * return true in the case that the computed type can have any number of values, as long as there are at least 2. + * Should be used in isMultiplicityValid(). + */ + protected boolean atLeastTwoValues(ArtifactTypeToken artifactType) { + if (typesToCompute.isEmpty()) { + return false; + } + for (AttributeTypeGeneric<T> attributeType : typesToCompute) { + if (typesToCompute.size() == 1 && artifactType.getMax(attributeType) == 1) { + return false; + } + } + return true; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicDesign.adoc b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicDesign.adoc index 257b3101339..944765acc03 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicDesign.adoc +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicDesign.adoc @@ -10,7 +10,9 @@ For example, given the two attribute types "Start Index" and "End Index", then " Can support arbitrarily complex (i.e. custom) calculations as well and predefined ones such as: Rate Numerator is delta of <type parameter> Denominator is a duration + duration is the time delta Ratio Ratio of <type parameter> + A ratio is a quotient where the numerator and denominator have the same units. Delta Delta of <type parameter> Quotient numerator is a <type parameter> denominator is a <type parameter> (not Duration) Product multiplicand is a <type parameter> and multiplier is a <type parameter> diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicToken.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicToken.java index f68e8309e9f..c6c37c49a34 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicToken.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ComputedCharacteristicToken.java @@ -41,9 +41,9 @@ public interface ComputedCharacteristicToken<T> extends FullyNamed, HasDescripti boolean isMultiplicityValid(ArtifactTypeToken artifactType); - T calculate(List<T> attributeValues); + T calculate(List<T> computingValues); - List<AttributeTypeGeneric<T>> getAttributeTypes(); + List<AttributeTypeGeneric<T>> getAttributeTypesToCompute(); String getMediaType(); diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicAverage.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicAverage.java new file mode 100644 index 00000000000..853f537f367 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicAverage.java @@ -0,0 +1,45 @@ +/********************************************************************* + * Copyright (c) 2021 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ +package org.eclipse.osee.framework.core.data.computed; + +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactTypeToken; +import org.eclipse.osee.framework.core.data.AttributeTypeGeneric; +import org.eclipse.osee.framework.core.data.ComputedCharacteristic; +import org.eclipse.osee.framework.core.data.NamespaceToken; +import org.eclipse.osee.framework.core.data.TaggerTypeToken; + +/** + * @author Stephen J. Molaro + */ +public final class ComputedCharacteristicAverage<T extends Number> extends ComputedCharacteristic<T> { + + public ComputedCharacteristicAverage(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute) { + super(id, name, taggerType, namespace, description, typesToCompute); + } + + @Override + public boolean isMultiplicityValid(ArtifactTypeToken artifactType) { + return atLeastTwoValues(artifactType); + } + + @Override + public T calculate(List<T> computingValues) { + double average = 0; + for (T value : computingValues) { + average += value.doubleValue(); + } + average /= computingValues.size(); + return typesToCompute.get(0).valueFromDouble(average); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicDelta.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicDelta.java new file mode 100644 index 00000000000..e00391320e9 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicDelta.java @@ -0,0 +1,41 @@ +/********************************************************************* + * Copyright (c) 2021 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ +package org.eclipse.osee.framework.core.data.computed; + +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactTypeToken; +import org.eclipse.osee.framework.core.data.AttributeTypeGeneric; +import org.eclipse.osee.framework.core.data.ComputedCharacteristic; +import org.eclipse.osee.framework.core.data.NamespaceToken; +import org.eclipse.osee.framework.core.data.TaggerTypeToken; + +/** + * @author Stephen J. Molaro + */ +public final class ComputedCharacteristicDelta<T extends Number> extends ComputedCharacteristic<T> { + + public ComputedCharacteristicDelta(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute) { + super(id, name, taggerType, namespace, description, typesToCompute); + } + + @Override + public boolean isMultiplicityValid(ArtifactTypeToken artifactType) { + return exactlyTwoValues(artifactType); + } + + @Override + public T calculate(List<T> computingValues) { + double delta = computingValues.get(0).doubleValue() - computingValues.get(1).doubleValue(); + return typesToCompute.get(0).valueFromDouble(Math.abs(delta)); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicProduct.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicProduct.java new file mode 100644 index 00000000000..b0899d08b04 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicProduct.java @@ -0,0 +1,44 @@ +/********************************************************************* + * Copyright (c) 2021 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ +package org.eclipse.osee.framework.core.data.computed; + +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactTypeToken; +import org.eclipse.osee.framework.core.data.AttributeTypeGeneric; +import org.eclipse.osee.framework.core.data.ComputedCharacteristic; +import org.eclipse.osee.framework.core.data.NamespaceToken; +import org.eclipse.osee.framework.core.data.TaggerTypeToken; + +/** + * @author Stephen J. Molaro + */ +public final class ComputedCharacteristicProduct<T extends Number> extends ComputedCharacteristic<T> { + + public ComputedCharacteristicProduct(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute) { + super(id, name, taggerType, namespace, description, typesToCompute); + } + + @Override + public boolean isMultiplicityValid(ArtifactTypeToken artifactType) { + return atLeastTwoValues(artifactType); + } + + @Override + public T calculate(List<T> computingValues) { + double product = computingValues.get(0).doubleValue(); + for (T value : computingValues.subList(1, computingValues.size())) { + product *= value.doubleValue(); + } + return typesToCompute.get(0).valueFromDouble(product); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicQuotient.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicQuotient.java new file mode 100644 index 00000000000..4dc54fbea81 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicQuotient.java @@ -0,0 +1,41 @@ +/********************************************************************* + * Copyright (c) 2021 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ +package org.eclipse.osee.framework.core.data.computed; + +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactTypeToken; +import org.eclipse.osee.framework.core.data.AttributeTypeGeneric; +import org.eclipse.osee.framework.core.data.ComputedCharacteristic; +import org.eclipse.osee.framework.core.data.NamespaceToken; +import org.eclipse.osee.framework.core.data.TaggerTypeToken; + +/** + * @author Stephen J. Molaro + */ +public final class ComputedCharacteristicQuotient<T extends Number> extends ComputedCharacteristic<T> { + + public ComputedCharacteristicQuotient(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute) { + super(id, name, taggerType, namespace, description, typesToCompute); + } + + @Override + public boolean isMultiplicityValid(ArtifactTypeToken artifactType) { + return exactlyTwoValues(artifactType); + } + + @Override + public T calculate(List<T> computingValues) { + double quotient = computingValues.get(0).doubleValue() / computingValues.get(1).doubleValue(); + return typesToCompute.get(0).valueFromDouble(quotient); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSentinel.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSentinel.java index eb73442acac..a3c48adae3a 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSentinel.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSentinel.java @@ -10,7 +10,6 @@ * Contributors: * Boeing - initial API and implementation **********************************************************************/ - package org.eclipse.osee.framework.core.data.computed; import java.util.List; @@ -35,7 +34,7 @@ public final class ComputedCharacteristicSentinel extends ComputedCharacteristic } @Override - public Object calculate(List<Object> attributeValues) { + public Object calculate(List<Object> computingValues) { return 0; } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSum.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSum.java new file mode 100644 index 00000000000..cc7d1cc9e94 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/computed/ComputedCharacteristicSum.java @@ -0,0 +1,44 @@ +/********************************************************************* + * Copyright (c) 2021 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ +package org.eclipse.osee.framework.core.data.computed; + +import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactTypeToken; +import org.eclipse.osee.framework.core.data.AttributeTypeGeneric; +import org.eclipse.osee.framework.core.data.ComputedCharacteristic; +import org.eclipse.osee.framework.core.data.NamespaceToken; +import org.eclipse.osee.framework.core.data.TaggerTypeToken; + +/** + * @author Stephen J. Molaro + */ +public final class ComputedCharacteristicSum<T extends Number> extends ComputedCharacteristic<T> { + + public ComputedCharacteristicSum(Long id, String name, TaggerTypeToken taggerType, NamespaceToken namespace, String description, List<AttributeTypeGeneric<T>> typesToCompute) { + super(id, name, taggerType, namespace, description, typesToCompute); + } + + @Override + public boolean isMultiplicityValid(ArtifactTypeToken artifactType) { + return atLeastTwoValues(artifactType); + } + + @Override + public T calculate(List<T> computingValues) { + double sum = 0; + for (T value : computingValues) { + sum += value.doubleValue(); + } + return typesToCompute.get(0).valueFromDouble(sum); + } +}
\ No newline at end of file |