@Override public SortFieldExpression sortBy(final String propertyName) throws IllegalArgumentException { return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .flatMap(f -> f.getFeatureId() .flatMap(id -> f.getProperty() .flatMap(property -> Optional .of((SortFieldExpression) new FeatureIdPropertyExpressionImpl(id, property)) ) ) ) .orElseGet(() -> (SortFieldExpression) common(propertyName)); }
@Override public FilterFieldExpression filterBy(final String propertyName) throws IllegalArgumentException { final Supplier<FilterFieldExpression> defaultSupplier = () -> (FilterFieldExpression) common(propertyName); return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .map(f -> f.getProperty() .map(property -> f.getFeatureId() // we have a feature id and a property path .map(id -> (FilterFieldExpression) new FeatureIdPropertyExpressionImpl(id, property)) // we have a property path .orElseGet(() -> new FeaturePropertyExpressionImpl(property)) ) // we have a feature field but no property path, this is invalid for filter operations .orElseGet(defaultSupplier) ) // we have no feature at all, continue with the other possibilities .orElseGet(defaultSupplier); }
@Override public ExistsFieldExpression existsBy(final String propertyName) throws IllegalArgumentException { return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .map(f -> f.getFeatureId() .map(id -> f.getProperty() // we have a feature id and a property path .map(property -> (ExistsFieldExpression) new FeatureIdPropertyExpressionImpl(id, property)) // we have a feature id but no property path .orElseGet(() -> new FeatureExpressionImpl(id)) ) // we have a feature field but no feature id, means it must be a property path .orElseGet(() -> (ExistsFieldExpression) f.getProperty() .map((String property) -> (ExistsFieldExpression) new FeaturePropertyExpressionImpl( property)) // at this point, we know that there must be a property, so the following throw should // never happen and is only there to make the compiler happy: .orElseThrow(() -> new IllegalStateException("Illegal state while parsing feature property path.")) ) ) // we have no feature at all, continue with the other possibilities .orElseGet(() -> (ExistsFieldExpression) common(propertyName)); }