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.
package org.bndly.common.graph;
/*-
* #%L
* Graph Impl
* %%
* Copyright (C) 2013 - 2020 Cybercon GmbH
* %%
* 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.
* #L%
*/
import org.bndly.common.reflection.ReflectionUtil;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class BeanGraphIterator {
private final ReferenceDetector referenceDetector;
private final EntityCollectionDetector entityCollectionDetector;
private final BeanGraphIteratorListener listener;
private Object ctx;
public BeanGraphIterator(ReferenceDetector referenceDetector, EntityCollectionDetector collectionDetector, BeanGraphIteratorListener listener) {
this(referenceDetector, collectionDetector, listener, null);
}
public BeanGraphIterator(ReferenceDetector referenceDetector, EntityCollectionDetector collectionDetector, BeanGraphIteratorListener listener, Object ctx) {
this.referenceDetector = referenceDetector;
this.entityCollectionDetector = collectionDetector;
this.listener = listener;
this.ctx = ctx;
if (listener == null) {
throw new IllegalArgumentException("when creating a " + getClass().getSimpleName() + " the " + BeanGraphIteratorListener.class.getSimpleName() + " can not be null.");
}
}
public void traverse(Object bean) {
if (bean == null) {
return;
}
Class> contextType = listener.getIterationContextType();
if (contextType != null && ctx == null) {
try {
ctx = contextType.newInstance();
} catch (Exception ex) {
throw new IllegalStateException("could not instantiate context " + contextType.getSimpleName());
}
}
Collection collection;
if (Collection.class.isAssignableFrom(bean.getClass())) {
collection = (Collection) bean;
} else {
collection = new ArrayList