Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.query.impl.getters;
import com.hazelcast.internal.util.CollectionUtil;
import com.hazelcast.internal.util.collection.ArrayUtils;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.util.Collection;
import static com.hazelcast.query.impl.predicates.PredicateUtils.unwrapIfOptional;
public abstract class AbstractMultiValueGetter extends Getter {
public static final String REDUCER_ANY_TOKEN = "any";
public static final int DO_NOT_REDUCE = -1;
public static final int REDUCE_EVERYTHING = -2;
private final int modifier;
private final Class resultType;
public AbstractMultiValueGetter(Getter parent, String modifierSuffix, Class> inputType, Class resultType) {
super(parent);
boolean isArray = inputType.isArray();
boolean isCollection = Collection.class.isAssignableFrom(inputType);
if (modifierSuffix == null) {
modifier = DO_NOT_REDUCE;
} else {
modifier = parseModifier(modifierSuffix, isArray, isCollection);
}
this.resultType = getResultType(inputType, resultType);
}
protected abstract Object extractFrom(Object parentObject) throws IllegalAccessException, InvocationTargetException;
@Override
Class getReturnType() {
return resultType;
}
@Override
Object getValue(Object obj) throws Exception {
Object parentObject = getParentObject(obj);
if (parentObject == null) {
return null;
}
if (parentObject instanceof MultiResult) {
return extractFromMultiResult((MultiResult) parentObject);
}
Object o = unwrapIfOptional(extractFrom(parentObject));
if (modifier == DO_NOT_REDUCE) {
return o;
}
if (modifier == REDUCE_EVERYTHING) {
MultiResult