Java Code Examples for org.eclipse.emf.ecore.util.FeatureMapUtil#isFeatureMap()

The following examples show how to use org.eclipse.emf.ecore.util.FeatureMapUtil#isFeatureMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DerivedEObjectEList.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean scanNext(EStructuralFeature nextFeature,
		ListIterator<Object> nextValuesIterator) {
	boolean isFeatureMap = FeatureMapUtil.isFeatureMap(nextFeature);

	while (nextValuesIterator.hasNext()) {
		Object nextValue = nextValuesIterator.next();

		if (isFeatureMap) {
			FeatureMap.Entry entry = (FeatureMap.Entry) nextValue;
			nextFeature = entry.getEStructuralFeature();
			nextValue = entry.getValue();
		}

		if ((isIncluded(nextFeature) ? nextValue != null
				: isIncluded(nextValue))
				&& ((index < preparedValues.size() && nextValue == preparedValues
						.get(index)) || preparedValues.add(nextValue))) {

			valuesIterator = nextValuesIterator;
			preparedFeature = nextFeature;
			return true;
		}
	}

	return false;
}
 
Example 2
Source File: DerivedEObjectEList.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean scanPrevious(EStructuralFeature previousFeature,
		ListIterator<Object> previousValuesIterator) {
	boolean isFeatureMap = FeatureMapUtil.isFeatureMap(previousFeature);

	while (previousValuesIterator.hasPrevious()) {
		Object previousValue = previousValuesIterator.previous();

		if (isFeatureMap) {
			FeatureMap.Entry entry = (FeatureMap.Entry) previousValue;
			previousFeature = entry.getEStructuralFeature();
			previousValue = entry.getValue();
		}

		if (index > 0 && previousValue == preparedValues.get(index - 1)) {
			valuesIterator = previousValuesIterator;
			preparedFeature = previousFeature;
			return true;
		}
	}

	return false;
}
 
Example 3
Source File: StatechartEqualityHelper.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean haveEqualAttribute(EObject eObject1, EObject eObject2,
		EAttribute attribute) {
	
	Object value1 = eObject1.eGet(attribute);
	Object value2 = eObject2.eGet(attribute);

	// If the first value is null, the second value must be null.
	//
	if (value1 == null) {
		return value2 == null;
	}
	
	// Since the first value isn't null, if the second one is, they aren't equal.
	//
	if (value2 == null) {
		return false;
	}

	// If this is a feature map...
	//
	if (FeatureMapUtil.isFeatureMap(attribute)) {
		// The feature maps must be equal.
		//
		FeatureMap featureMap1 = (FeatureMap)value1;
		FeatureMap featureMap2 = (FeatureMap)value2;
		return equalFeatureMaps(featureMap1, featureMap2);
	}
	else {
		if (value1 instanceof String && value2 instanceof String) {
			String wsFreeValue1 = removeWhitespaces((String)value1);
			String wsFreeValue2 = removeWhitespaces((String)value2);
			return wsFreeValue1.equals(wsFreeValue2);
		}
		
		return value1.equals(value2);
	}
}
 
Example 4
Source File: DerivedSubsetEObjectEList.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public DerivedSubsetEObjectEList(Class<?> dataClass, InternalEObject owner,
		int featureID, int[] sourceFeatureIDs) {
	super(dataClass, owner, featureID, sourceFeatureIDs);

	EStructuralFeature feature = sourceFeatureIDs.length == 1 ? getEStructuralFeature(sourceFeatureIDs[0])
			: null;

	if (feature == null || !feature.isMany()
			|| FeatureMapUtil.isFeatureMap(feature)) {

		throw new IllegalArgumentException(String.valueOf(sourceFeatureIDs));
	}
}
 
Example 5
Source File: DerivedEObjectEList.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean prepareNext() {

			if (valuesIterator == null
					|| !scanNext(preparedFeature, valuesIterator)) {

				while (featureIndex < sourceFeatureIDs.length) {
					int sourceFeatureID = sourceFeatureIDs[featureIndex++];

					if (owner.eIsSet(sourceFeatureID)) {
						EStructuralFeature sourceFeature = getEStructuralFeature(sourceFeatureID);
						Object value = owner.eGet(sourceFeatureID, resolve(),
								true);

						if (sourceFeature.isMany()
								|| FeatureMapUtil.isFeatureMap(sourceFeature)) {

							@SuppressWarnings("unchecked")
							InternalEList<Object> valuesList = (InternalEList<Object>) value;

							if (scanNext(sourceFeature,
									resolve() ? valuesList.listIterator()
											: valuesList.basicListIterator())) {

								prepared = 3;
								return true;
							}
						} else if ((isIncluded(sourceFeature) ? value != null
								: isIncluded(value))
								&& ((index < preparedValues.size() && value == preparedValues
										.get(index)) || preparedValues
										.add(value))) {

							valuesIterator = null;
							preparedFeature = sourceFeature;
							prepared = 2;
							return true;
						}
					}
				}

				prepared = 1;
				return false;
			} else {
				prepared = 3;
				return true;
			}
		}
 
Example 6
Source File: DerivedEObjectEList.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean preparePrevious() {

			if (valuesIterator == null
					|| !scanPrevious(preparedFeature, valuesIterator)) {

				while (featureIndex > 0) {
					int sourceFeatureID = sourceFeatureIDs[--featureIndex];

					if (owner.eIsSet(sourceFeatureID)) {
						EStructuralFeature sourceFeature = getEStructuralFeature(sourceFeatureID);
						Object value = owner.eGet(sourceFeatureID, resolve(),
								true);

						if (sourceFeature.isMany()
								|| FeatureMapUtil.isFeatureMap(sourceFeature)) {

							@SuppressWarnings("unchecked")
							InternalEList<Object> valuesList = (InternalEList<Object>) value;
							int valuesListSize = valuesList.size();

							if (scanPrevious(
									sourceFeature,
									resolve() ? valuesList
											.listIterator(valuesListSize)
											: valuesList
													.basicListIterator(valuesListSize))) {

								prepared = -3;
								return true;
							}
						} else if (index > 0
								&& value == preparedValues.get(index - 1)) {

							valuesIterator = null;
							preparedFeature = sourceFeature;
							prepared = -2;
							return true;
						}
					}
				}

				prepared = -1;
				return false;
			} else {
				prepared = -3;
				return true;
			}
		}
 
Example 7
Source File: DerivedEObjectEList.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean isEmpty() {

	if (sourceFeatureIDs != null) {

		for (int i = 0; i < sourceFeatureIDs.length; i++) {
			int sourceFeatureID = sourceFeatureIDs[i];

			if (owner.eIsSet(sourceFeatureID)) {
				EStructuralFeature sourceFeature = getEStructuralFeature(sourceFeatureID);
				Object value = owner.eGet(sourceFeatureID, false, true);

				if (FeatureMapUtil.isFeatureMap(sourceFeature)) {
					FeatureMap featureMap = (FeatureMap) value;

					for (int j = 0, size = featureMap.size(); j < size; j++) {

						if (isIncluded(featureMap.getEStructuralFeature(j)) ? featureMap
								.getValue(j) != null
								: isIncluded(featureMap.getValue(j))) {

							return false;
						}
					}
				} else if (isIncluded(sourceFeature)) {

					if (sourceFeature.isMany() ? ((List<?>) value).size() > 0
							: value != null) {

						return false;
					}
				} else {

					if (sourceFeature.isMany()) {
						InternalEList<?> valuesList = (InternalEList<?>) value;

						if (valuesList instanceof RandomAccess) {

							for (int j = 0, size = valuesList.size(); j < size; j++) {

								if (isIncluded(valuesList.basicGet(j))) {
									return false;
								}
							}
						} else {

							for (Iterator<?> v = valuesList.basicIterator(); v
									.hasNext();) {

								if (isIncluded(v.next())) {
									return false;
								}
							}
						}
					} else if (isIncluded(value)) {
						return false;
					}
				}
			}
		}
	}

	return true;
}
 
Example 8
Source File: DerivedEObjectEList.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean contains(Object object) {

	if (sourceFeatureIDs != null) {

		for (int i = 0; i < sourceFeatureIDs.length; i++) {
			int sourceFeatureID = sourceFeatureIDs[i];

			if (owner.eIsSet(sourceFeatureID)) {
				EStructuralFeature sourceFeature = getEStructuralFeature(sourceFeatureID);
				Object value = owner.eGet(sourceFeatureID, true, true);

				if (FeatureMapUtil.isFeatureMap(sourceFeature)) {
					FeatureMap featureMap = (FeatureMap) value;

					for (int j = 0, size = featureMap.size(); j < size; j++) {
						value = featureMap.getValue(j);

						if (isIncluded(featureMap.getEStructuralFeature(j)) ? value == object
								: isIncluded(value)
										&& derive(value) == object) {

							return true;
						}
					}
				} else if (isIncluded(sourceFeature)) {

					if (sourceFeature.isMany() ? ((List<?>) value)
							.contains(object) : value == object) {

						return true;
					}
				} else {

					if (sourceFeature.isMany()) {
						InternalEList<?> valuesList = (InternalEList<?>) value;

						if (valuesList instanceof RandomAccess) {

							for (int j = 0, size = valuesList.size(); j < size; j++) {
								value = valuesList.basicGet(j);

								if (isIncluded(value)
										&& derive(value) == object) {

									return true;
								}
							}
						} else {

							for (Iterator<?> v = valuesList.basicIterator(); v
									.hasNext();) {

								value = v.next();

								if (isIncluded(value)
										&& derive(value) == object) {

									return true;
								}
							}
						}
					} else if (isIncluded(value) && derive(value) == object) {
						return true;
					}
				}
			}
		}
	}

	return false;
}