protected Optional<String> optionalAttribute(String... attributeIds) { if (element.getAnyAttribute().isEmpty()) { return Optional.empty(); } final List<String> attributes = Arrays.asList(attributeIds); return element.getAnyAttribute().stream() .filter(e -> attributes.contains(e.getEStructuralFeature().getName())) .map(e -> e.getValue().toString()) .findFirst(); }
Optional<java.lang.String> getStringValue(BaseElement element) { return element.getAnyAttribute().stream() .filter(e -> this.name().equals(e.getEStructuralFeature().getName())) .map(e -> e.getValue().toString()) .findFirst(); }
/** * Returns {@code true} if the {@code feature} has no element. * * @param feature the feature * * @return {@code true} if the {@code feature} has no element */ private boolean isEmpty(EStructuralFeature feature) { final Object value = owner.eGet(feature, false); if (FeatureMapUtil.isFeatureMap(feature)) { final FeatureMap featureMap = (FeatureMap) value; return featureMap.stream().noneMatch(this::isIncludedEntry); } if (feature.isMany()) { final Collection collection = (Collection) value; return collection.isEmpty(); } return isNull(value); }
/** * Returns the number of elements of the {@code feature}. * * @param feature the feature * * @return the number of elements of the {@code feature} */ @Nonnegative private int size(EStructuralFeature feature) { final Object value = owner.eGet(feature, false); if (FeatureMapUtil.isFeatureMap(feature)) { final FeatureMap featureMap = (FeatureMap) value; return featureMap.stream() .filter(this::isIncludedEntry) .mapToInt(e -> 1) .sum(); } if (feature.isMany()) { final Collection collection = (Collection) value; return collection.size(); } return Booleans.toInt(nonNull(value)); }
@Test public void testApplyCallActivityProperties() throws Exception { final CallActivity callActivity = mock(CallActivity.class); when(callActivity.getExtensionValues()).thenReturn(new ArrayList<>()); final String propertyName = "isCase"; final String propertyValue = "true"; final String resultName = "case"; final String resultValue = "<![CDATA[" + propertyValue + "]]>"; final Map<String, String> properties = new HashMap<>(); properties.put(propertyName, propertyValue); tested.applyCallActivityProperties(callActivity, properties); assertFalse(callActivity.getExtensionValues().isEmpty()); final ExtensionAttributeValue extenstionValue = callActivity.getExtensionValues().get(0); final Optional<String> value = extenstionValue.getValue().stream() .filter(v -> resultName.equals(((MetaDataType) v.getValue()).getName())) .map(v -> ((MetaDataType) v.getValue()).getMetaValue()).findAny(); assertTrue(value.isPresent() && resultValue.equals(value.get())); }