Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2012-09-20 23:23:12 +0000
committerRoberto E. Escobar2013-08-19 22:20:13 +0000
commit4ea981844726060d7b3c303a79105b62993da043 (patch)
treec1276816a5e9e828cfc2c8a4327e9155a29afbe9
parentcdd8e5189629b7ff6a6d209922b34f7c65aed523 (diff)
downloadorg.eclipse.osee-4ea981844726060d7b3c303a79105b62993da043.tar.gz
org.eclipse.osee-4ea981844726060d7b3c303a79105b62993da043.tar.xz
org.eclipse.osee-4ea981844726060d7b3c303a79105b62993da043.zip
refactor: Extract inner attribute helper classes
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeManagerImpl.java66
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeSetHelper.java26
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/FromStringAttributeSetHelper.java56
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/TypedValueAttributeSetHelper.java51
4 files changed, 137 insertions, 62 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeManagerImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeManagerImpl.java
index 09c2d9dbc06..9e5f4a52186 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeManagerImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeManagerImpl.java
@@ -43,8 +43,6 @@ import org.eclipse.osee.orcs.data.AttributeWriteable;
*/
public abstract class AttributeManagerImpl extends AbstractIdentity<String> implements HasOrcsData<ArtifactData>, AttributeManager, AttributeExceptionFactory {
- private final AttributeSetHelper<Object, String> ATTRIBUTE_STRING_SETTER = new FromStringAttributeSetHelper();
-
private final AttributeCollection attributes;
private boolean isLoaded;
@@ -263,7 +261,8 @@ public abstract class AttributeManagerImpl extends AbstractIdentity<String> impl
@Override
public void setAttributesFromStrings(IAttributeType attributeType, Collection<String> values) throws OseeCoreException {
- setAttributesFromValuesHelper(ATTRIBUTE_STRING_SETTER, attributeType, values);
+ AttributeSetHelper<Object, String> attributeStringSetter = new FromStringAttributeSetHelper(attributes, this);
+ setAttributesFromValuesHelper(attributeStringSetter, attributeType, values);
}
@Override
@@ -273,7 +272,7 @@ public abstract class AttributeManagerImpl extends AbstractIdentity<String> impl
@Override
public <T> void setAttributesFromValues(IAttributeType attributeType, Collection<T> values) throws OseeCoreException {
- AttributeSetHelper<T, T> setter = new TypedValueAttributeSetHelper<T>();
+ AttributeSetHelper<T, T> setter = new TypedValueAttributeSetHelper<T>(attributes, this);
setAttributesFromValuesHelper(setter, attributeType, values);
}
@@ -385,16 +384,8 @@ public abstract class AttributeManagerImpl extends AbstractIdentity<String> impl
ensureAttributesLoaded();
return attributes.getAttributeList(attributeType, includeDeleted);
}
- //////////////////////////////////////////////////////////////
-
- private interface AttributeSetHelper<A, V> {
-
- boolean matches(Attribute<A> attribute, V value) throws OseeCoreException;
- void setAttributeValue(Attribute<A> attribute, V value) throws OseeCoreException;
-
- void createAttribute(IAttributeType attributeType, V value) throws OseeCoreException;
- }
+ //////////////////////////////////////////////////////////////
private <A, T> void setAttributesFromValuesHelper(AttributeSetHelper<A, T> helper, IAttributeType attributeType, Collection<T> values) throws OseeCoreException {
ensureAttributesLoaded();
@@ -435,55 +426,6 @@ public abstract class AttributeManagerImpl extends AbstractIdentity<String> impl
}
}
- private final class TypedValueAttributeSetHelper<T> implements AttributeSetHelper<T, T> {
-
- @Override
- public boolean matches(Attribute<T> attribute, T value) throws OseeCoreException {
- return value.equals(attribute.getValue());
- }
-
- @Override
- public void setAttributeValue(Attribute<T> attribute, T value) throws OseeCoreException {
- attribute.setValue(value);
- }
-
- @Override
- public void createAttribute(IAttributeType attributeType, T value) throws OseeCoreException {
- ResultSet<Attribute<T>> result =
- attributes.getAttributeSetFromValue(attributeType, DeletionFlag.EXCLUDE_DELETED, value);
- if (result.getOneOrNull() == null) {
- createAttribute(attributeType, value);
- }
- }
- }
-
- private final class FromStringAttributeSetHelper implements AttributeSetHelper<Object, String> {
-
- private String asString(Object object) {
- return String.valueOf(object);
- }
-
- @Override
- public boolean matches(Attribute<Object> attribute, String value) throws OseeCoreException {
- Object attrValue = attribute.getValue();
- return value.equals(asString(attrValue));
- }
-
- @Override
- public void setAttributeValue(Attribute<Object> attribute, java.lang.String value) throws OseeCoreException {
- attribute.setFromString(value);
- }
-
- @Override
- public void createAttribute(IAttributeType attributeType, String value) throws OseeCoreException {
- ResultSet<Attribute<Object>> result =
- attributes.getAttributeSetFromString(attributeType, DeletionFlag.EXCLUDE_DELETED, value);
- if (result.getOneOrNull() == null) {
- createAttributeFromString(attributeType, value);
- }
- }
- }
-
//////////////////////////////////////////////////////////////
private void checkTypeValid(IAttributeType attributeType) throws OseeCoreException {
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeSetHelper.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeSetHelper.java
new file mode 100644
index 00000000000..5be117c6989
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeSetHelper.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.attribute;
+
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface AttributeSetHelper<A, V> {
+
+ boolean matches(Attribute<A> attribute, V value) throws OseeCoreException;
+
+ void setAttributeValue(Attribute<A> attribute, V value) throws OseeCoreException;
+
+ void createAttribute(IAttributeType attributeType, V value) throws OseeCoreException;
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/FromStringAttributeSetHelper.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/FromStringAttributeSetHelper.java
new file mode 100644
index 00000000000..1612985bf66
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/FromStringAttributeSetHelper.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.attribute;
+
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.ResultSet;
+import org.eclipse.osee.framework.core.enums.DeletionFlag;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.internal.artifact.AttributeManager;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class FromStringAttributeSetHelper implements AttributeSetHelper<Object, String> {
+
+ private final AttributeCollection attributes;
+ private final AttributeManager manager;
+
+ public FromStringAttributeSetHelper(AttributeCollection attributes, AttributeManager manager) {
+ super();
+ this.attributes = attributes;
+ this.manager = manager;
+ }
+
+ private String asString(Object object) {
+ return String.valueOf(object);
+ }
+
+ @Override
+ public boolean matches(Attribute<Object> attribute, String value) throws OseeCoreException {
+ Object attrValue = attribute.getValue();
+ return value.equals(asString(attrValue));
+ }
+
+ @Override
+ public void setAttributeValue(Attribute<Object> attribute, java.lang.String value) throws OseeCoreException {
+ attribute.setFromString(value);
+ }
+
+ @Override
+ public void createAttribute(IAttributeType attributeType, String value) throws OseeCoreException {
+ ResultSet<Attribute<Object>> result =
+ attributes.getAttributeSetFromString(attributeType, DeletionFlag.EXCLUDE_DELETED, value);
+ if (result.getOneOrNull() == null) {
+ manager.createAttributeFromString(attributeType, value);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/TypedValueAttributeSetHelper.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/TypedValueAttributeSetHelper.java
new file mode 100644
index 00000000000..db1f972c1e5
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/attribute/TypedValueAttributeSetHelper.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.attribute;
+
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.ResultSet;
+import org.eclipse.osee.framework.core.enums.DeletionFlag;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.internal.artifact.AttributeManager;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class TypedValueAttributeSetHelper<T> implements AttributeSetHelper<T, T> {
+
+ private final AttributeCollection attributes;
+ private final AttributeManager manager;
+
+ public TypedValueAttributeSetHelper(AttributeCollection attributes, AttributeManager manager) {
+ super();
+ this.attributes = attributes;
+ this.manager = manager;
+ }
+
+ @Override
+ public boolean matches(Attribute<T> attribute, T value) throws OseeCoreException {
+ return value.equals(attribute.getValue());
+ }
+
+ @Override
+ public void setAttributeValue(Attribute<T> attribute, T value) throws OseeCoreException {
+ attribute.setValue(value);
+ }
+
+ @Override
+ public void createAttribute(IAttributeType attributeType, T value) throws OseeCoreException {
+ ResultSet<Attribute<T>> result =
+ attributes.getAttributeSetFromValue(attributeType, DeletionFlag.EXCLUDE_DELETED, value);
+ if (result.getOneOrNull() == null) {
+ manager.createAttribute(attributeType, value);
+ }
+ }
+} \ No newline at end of file

Back to the top