|
Java example source code file (CacheBuilderFactory.java)
The CacheBuilderFactory.java Java example source code
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.google.common.cache;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.cache.LocalCache.Strength;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
/**
* Helper class for creating {@link CacheBuilder} instances with all combinations of several sets of
* parameters.
*
* @author mike nonemacher
*/
class CacheBuilderFactory {
// Default values contain only 'null', which means don't call the CacheBuilder method (just give
// the CacheBuilder default).
private Set<Integer> concurrencyLevels = Sets.newHashSet((Integer) null);
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
CacheBuilderFactory withConcurrencyLevels(Set<Integer> concurrencyLevels) {
this.concurrencyLevels = Sets.newLinkedHashSet(concurrencyLevels);
return this;
}
CacheBuilderFactory withInitialCapacities(Set<Integer> initialCapacities) {
this.initialCapacities = Sets.newLinkedHashSet(initialCapacities);
return this;
}
CacheBuilderFactory withMaximumSizes(Set<Integer> maximumSizes) {
this.maximumSizes = Sets.newLinkedHashSet(maximumSizes);
return this;
}
CacheBuilderFactory withExpireAfterWrites(Set<DurationSpec> durations) {
this.expireAfterWrites = Sets.newLinkedHashSet(durations);
return this;
}
CacheBuilderFactory withExpireAfterAccesses(Set<DurationSpec> durations) {
this.expireAfterAccesses = Sets.newLinkedHashSet(durations);
return this;
}
CacheBuilderFactory withRefreshes(Set<DurationSpec> durations) {
this.refreshes = Sets.newLinkedHashSet(durations);
return this;
}
CacheBuilderFactory withKeyStrengths(Set<Strength> keyStrengths) {
this.keyStrengths = Sets.newLinkedHashSet(keyStrengths);
Preconditions.checkArgument(!this.keyStrengths.contains(Strength.SOFT));
return this;
}
CacheBuilderFactory withValueStrengths(Set<Strength> valueStrengths) {
this.valueStrengths = Sets.newLinkedHashSet(valueStrengths);
return this;
}
Iterable<CacheBuilder
Other Java examples (source code examples)Here is a short list of links related to this Java CacheBuilderFactory.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.