Skip to main content
summaryrefslogtreecommitdiffstats
blob: e982b5695693f9198ee3bd0402a2c08c63368c01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2012 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 static com.google.common.base.Predicates.and;
import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.attributeStringEquals;
import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.attributeValueEquals;
import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.deletionFlagEquals;
import java.util.List;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.orcs.core.internal.util.AbstractTypeCollection;
import com.google.common.base.Predicate;

/**
 * @author Roberto E. Escobar
 */
public class AttributeCollection extends AbstractTypeCollection<IAttributeType, Attribute<?>, IAttributeType, Attribute<?>> {

   private final AttributeExceptionFactory exceptionFactory;

   public AttributeCollection(AttributeExceptionFactory exceptionFactory) {
      super();
      this.exceptionFactory = exceptionFactory;
   }

   //////////////////////////////////////////////////////////////

   @Override
   @SuppressWarnings({"unchecked", "rawtypes"})
   protected ResultSet<Attribute<?>> createResultSet(List<Attribute<?>> values) {
      return new AttributeResultSet(exceptionFactory, values);
   }

   @Override
   @SuppressWarnings({"unchecked", "rawtypes"})
   protected <T extends Attribute<?>> ResultSet<T> createResultSet(IAttributeType attributeType, List<T> values) {
      return new AttributeResultSet(exceptionFactory, attributeType, values);
   }

   @Override
   protected Attribute<?> asMatcherData(Attribute<?> data) {
      return data;
   }

   @Override
   protected IAttributeType getType(Attribute<?> data) throws OseeCoreException {
      return data.getAttributeType();
   }

   public <T> ResultSet<Attribute<T>> getResultSet(IAttributeType attributeType, DeletionFlag includeDeleted) throws OseeCoreException {
      List<Attribute<T>> result = getList(attributeType, includeDeleted);
      return createResultSet(attributeType, result);
   }

   @SuppressWarnings({"unchecked", "rawtypes"})
   public <T> ResultSet<Attribute<T>> getAttributeSetFromString(IAttributeType attributeType, DeletionFlag includeDeleted, String value) throws OseeCoreException {
      Predicate deleteStateMatch = deletionFlagEquals(includeDeleted);
      Predicate stringEqualsMatch = attributeStringEquals(value);
      Predicate filter = and(deleteStateMatch, stringEqualsMatch);
      return getSetByFilter(attributeType, filter);
   }

   @SuppressWarnings({"unchecked", "rawtypes"})
   public <T> ResultSet<Attribute<T>> getAttributeSetFromValue(IAttributeType attributeType, DeletionFlag includeDeleted, T value) throws OseeCoreException {
      Predicate deleteStateMatch = deletionFlagEquals(includeDeleted);
      Predicate attributeValueEquals = attributeValueEquals(value);
      Predicate filter = and(attributeValueEquals, deleteStateMatch);
      return getSetByFilter(attributeType, filter);
   }

   @SuppressWarnings({"unchecked", "rawtypes"})
   public <T> List<Attribute<T>> getList(IAttributeType attributeType, DeletionFlag includeDeleted) throws OseeCoreException {
      Predicate attributeDeletionFlagEquals = deletionFlagEquals(includeDeleted);
      return getListByFilter(attributeType, attributeDeletionFlagEquals);
   }

}

Back to the top