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.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.brooklyn.util.collections;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import org.apache.brooklyn.util.guava.Maybe;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/** Does a configurable deep merge, taking the order from the first argument,
* and configurable through the builder how to act on lists or conflicts. */
@Beta
public class CollectionMerger {
public static class Builder {
protected int depth = Integer.MAX_VALUE;
protected boolean mergeNestedMaps = true;
protected boolean preferSecondOnConflict = false;
protected BiFunction, Collection, Collection> mergeNestedLists = null;
/** Sets effectively infinite {@link #depth(int)} (the default) */
public Builder deep(boolean val) {
return depth(val ? Integer.MAX_VALUE : 1);
}
/**
* Depth 1 means a shallow copy - i.e. only looking one layer down (e.g. at the values within the top-level map).
* Depth 2 would mean going one-deep into the values inside the top-level map/list/set.
* Default is infinite.
s *
* By default, depth only applies to nested maps. One needs to set {@link #mergeNestedLists(boolean)} for
* it to do this to nested iterables.
*/
public Builder depth(int val) {
checkArgument(val > 0, "val %s must be positive", val);
this.depth = val;
return this;
}
/** @deprecated since 1.0, never did anything */
@Deprecated
public Builder mergeNestedMaps(boolean val) {
this.mergeNestedMaps = val;
return this;
}
/** By default lists will not be merged, and either the first or second will be kept
* depending on {@link #preferSecondOnConflict(boolean)}. Set this to true to cause
* lists in the second merge argument to be appended to lists in the first, or false for the default behaviour.
* For more complex behaviours use {@link #mergeNestedLists(BiFunction)}.
*/
public Builder mergeNestedLists(boolean val) {
if (val) {
mergeNestedLists((l1,l2) -> {
Collection