下面列出了com.google.common.collect.ImmutableSortedMap#copyOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
LongPositions(Iterable<? extends Object> elements, final int bitPerLong) {
this.elements = ImmutableList.copyOf(elements);
checkArgument(bitPerLong <= BITS_IN_LONG, bitPerLong);
for (int i = 0; i < this.elements.size(); i++) {
positions.put(
this.elements.get(i),
new BitPosition(
i / bitPerLong,
i % bitPerLong));
}
this.longPositions = ImmutableSortedMap.copyOf(
Maps.transformEntries(
Multimaps.index(positions.values(), ToLongIndex.FUNCTION).asMap(),
new Maps.EntryTransformer<Integer, Collection<BitPosition>, LongSet>() {
@Override
public LongSet transformEntry(Integer key, Collection<BitPosition> position) {
return new LongSet(key, position);
}
}));
}
/** Expand flag macros in all CxxPlatform StringArg flags. */
public static void translateCxxPlatformFlags(
CxxPlatform.Builder cxxPlatformBuilder,
CxxPlatform cxxPlatform,
ImmutableMap<String, Arg> flagMacros) {
Function<Arg, Arg> translateFunction =
new CxxFlags.TranslateMacrosArgsFunction(ImmutableSortedMap.copyOf(flagMacros));
Function<ImmutableList<Arg>, ImmutableList<Arg>> expandMacros =
flags -> flags.stream().map(translateFunction).collect(ImmutableList.toImmutableList());
cxxPlatformBuilder.setAsflags(expandMacros.apply(cxxPlatform.getAsflags()));
cxxPlatformBuilder.setAsppflags(expandMacros.apply(cxxPlatform.getAsppflags()));
cxxPlatformBuilder.setCflags(expandMacros.apply(cxxPlatform.getCflags()));
cxxPlatformBuilder.setCxxflags(expandMacros.apply(cxxPlatform.getCxxflags()));
cxxPlatformBuilder.setCppflags(expandMacros.apply(cxxPlatform.getCppflags()));
cxxPlatformBuilder.setCxxppflags(expandMacros.apply(cxxPlatform.getCxxppflags()));
cxxPlatformBuilder.setCudappflags(expandMacros.apply(cxxPlatform.getCudappflags()));
cxxPlatformBuilder.setCudaflags(expandMacros.apply(cxxPlatform.getCudaflags()));
cxxPlatformBuilder.setHipppflags(expandMacros.apply(cxxPlatform.getHipppflags()));
cxxPlatformBuilder.setHipflags(expandMacros.apply(cxxPlatform.getHipflags()));
cxxPlatformBuilder.setAsmppflags(expandMacros.apply(cxxPlatform.getAsmppflags()));
cxxPlatformBuilder.setAsmflags(expandMacros.apply(cxxPlatform.getAsmflags()));
cxxPlatformBuilder.setLdflags(expandMacros.apply(cxxPlatform.getLdflags()));
cxxPlatformBuilder.setStripFlags(expandMacros.apply(cxxPlatform.getStripFlags()));
cxxPlatformBuilder.setArflags(expandMacros.apply(cxxPlatform.getArflags()));
cxxPlatformBuilder.setRanlibflags(expandMacros.apply(cxxPlatform.getRanlibflags()));
}
/**
* Returns a TreeArtifactValue out of the given Artifact-relative path fragments and their
* corresponding FileArtifactValues.
*/
static TreeArtifactValue create(
Map<TreeFileArtifact, ? extends FileArtifactValue> childFileValues) {
if (childFileValues.isEmpty()) {
return EMPTY;
}
Map<String, FileArtifactValue> digestBuilder =
Maps.newHashMapWithExpectedSize(childFileValues.size());
boolean entirelyRemote = true;
for (Map.Entry<TreeFileArtifact, ? extends FileArtifactValue> e : childFileValues.entrySet()) {
TreeFileArtifact child = e.getKey();
FileArtifactValue value = e.getValue();
Preconditions.checkState(
!FileArtifactValue.OMITTED_FILE_MARKER.equals(value),
"Cannot construct TreeArtifactValue because child %s was omitted",
child);
// Tolerate a tree artifact having a mix of local and remote children (b/152496153#comment80).
entirelyRemote &= value.isRemote();
digestBuilder.put(child.getParentRelativePath().getPathString(), value);
}
return new TreeArtifactValue(
DigestUtils.fromMetadata(digestBuilder),
ImmutableSortedMap.copyOf(childFileValues),
entirelyRemote);
}
/** Convert frequent sequences to sorted Map<Sequence, Integer> */
public static SortedMap<Sequence, Integer> toMap(final SequentialPatterns patterns) {
if (patterns == null) {
return null;
} else {
final HashMap<Sequence, Integer> sequences = new HashMap<>();
for (final List<SequentialPattern> level : patterns.levels) {
for (final SequentialPattern pattern : level) {
final Sequence seq = new Sequence();
for (final Itemset set : pattern.getItemsets())
seq.add(set.get(0)); // Assumes a seq is just singleton
// itemsets
sequences.put(seq, pattern.getAbsoluteSupport());
}
}
// Sort patterns by support
final Ordering<Sequence> comparator = Ordering.natural().reverse().onResultOf(Functions.forMap(sequences))
.compound(Ordering.usingToString());
return ImmutableSortedMap.copyOf(sequences, comparator);
}
}
private Map<String, String> createLookup() {
Map<String, String> lookup = new HashMap<>(items.size());
for (LionItem item : items) {
lookup.put(item.key(), item.value());
}
return ImmutableSortedMap.copyOf(lookup);
}
/** Sort sequences by interestingness */
public static Map<Sequence, Double> sortSequences(final HashMap<Sequence, Double> sequences,
final HashMap<Sequence, Double> intMap) {
final Ordering<Sequence> comparator = Ordering.natural().reverse().onResultOf(Functions.forMap(intMap))
.compound(Ordering.natural().reverse().onResultOf(Functions.forMap(sequences)))
.compound(Ordering.usingToString());
final Map<Sequence, Double> sortedSequences = ImmutableSortedMap.copyOf(sequences, comparator);
return sortedSequences;
}
@JsonProperty(PROP_IPSEC_PEER_CONFIGS)
public void setIpsecPeerConfigs(
@Nullable NavigableMap<String, IpsecPeerConfig> ipsecPeerConfigs) {
_ipsecPeerConfigs =
ipsecPeerConfigs == null
? ImmutableSortedMap.of()
: ImmutableSortedMap.copyOf(ipsecPeerConfigs);
}
private static Map<String, Long> sortByValues(Map<String, Long> result) {
//Sort result by time in reverse order
final Ordering<String> reversValueOrdering =
Ordering.natural().reverse().nullsLast().onResultOf(Functions.forMap(result, null));
Map<String, Long> orderedMap = ImmutableSortedMap.copyOf(result, reversValueOrdering);
return orderedMap;
}
AddedFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, Username username, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) {
this.eventId = eventId;
this.path = path;
this.mailboxId = mailboxId;
this.username = username;
this.sessionId = sessionId;
this.metaData = ImmutableSortedMap.copyOf(metaData);
}
/** Sort map by value (highest first) */
public static <K extends Comparable<K>, V extends Comparable<V>> Map<K, V> sortMapByValueDescending(
final Map<K, V> map) {
final Ordering<K> valueThenKeyComparator = Ordering.natural().reverse()
.onResultOf(Functions.forMap(map))
.compound(Ordering.<K> natural().reverse());
return ImmutableSortedMap.copyOf(map, valueThenKeyComparator);
}
public void setAppliedRibGroups(Map<RoutingProtocol, RibGroup> appliedRibGroups) {
_appliedRibGroups = ImmutableSortedMap.copyOf(appliedRibGroups);
}
public ConfigFeatureFlagValuesTransition(Map<Label, String> flagValues) {
this(ImmutableSortedMap.copyOf(flagValues), flagValues.hashCode());
}
public FeatureVector(Map<Integer, Double> features)
{
this.features = ImmutableSortedMap.copyOf(features);
}
@Override
public SortedMap<Integer, ? extends Number> load(SparseArray<?> sparseArray){
return ImmutableSortedMap.copyOf(parse(sparseArray));
}
@JsonProperty(PROP_COMMUNITY_SET_EXPRS)
private @Nonnull NavigableMap<String, CommunitySetExpr> getCommunitySetExprsSorted() {
return ImmutableSortedMap.copyOf(_communitySetExprs);
}
/** Creates a NameMap that is an immutable copy of a given map. */
public static <V> NameMap immutableCopyOf(Map<String, V> names) {
return new NameMap<>(ImmutableSortedMap.copyOf(names, COMPARATOR));
}
public void scan(boolean report)
{
TreeMap<Integer, SnowMerkleProof> fmap = new TreeMap<>();
for(Map.Entry<Integer, String> me : params.getFieldSeeds().entrySet())
{
int field_number = me.getKey();
SnowFieldInfo info = params.getSnowFieldInfo(field_number);
String name = me.getValue();
File field_folder = new File(path, name);
if (field_folder.exists() && field_folder.isDirectory())
{
try
{
double precacheGig = config.getDoubleWithDefault("memfield_precache_gb", 0);
int minDepthToDisk = config.getIntWithDefault("min_depth_to_disk", 0);
boolean memfield = config.getBoolean("memfield");
long precache = 0;
if (precacheGig > 0.01)
{
memfield = false;
precache = (long)(precacheGig * 1024.0 * 1024.0 * 1024.0);
}
logger.info("creating field: " + field_folder + " memfield=" + memfield + ", precache=" + precache + ", minDepthToDisk=" + minDepthToDisk);
SnowMerkleProof proof = new SnowMerkleProof(field_folder, name, memfield, precache, minDepthToDisk);
for(int i = 0; i<64; i++)
{
checkField(field_number, proof);
}
fmap.put(field_number, proof);
logger.info(String.format("Snow field %d %s (%s) is working", field_number,
name,
info.getName()));
}
catch(Throwable e)
{
logger.info(String.format("Unable to load %s, error: %s", name, e.toString()));
}
}
else
{
logger.info(String.format("Not loading %d %s (%s), directory not present: %s",
field_number,
name,
info.getName(),
field_folder));
}
}
availible_fields = ImmutableSortedMap.copyOf(fmap);
}
/** Creates a new file tree with the given root directories. */
FileTree(Map<Name, Directory> roots) {
this.roots = ImmutableSortedMap.copyOf(roots, Name.canonicalOrdering());
}
@JsonProperty(PROP_IKE_PHASE1_KEYS)
public void setIkePhase1Keys(@Nullable NavigableMap<String, IkePhase1Key> ikePhase1Keys) {
_ikePhase1keys =
ikePhase1Keys == null ? ImmutableSortedMap.of() : ImmutableSortedMap.copyOf(ikePhase1Keys);
}
@ImmutableConstructor
private MultiCurrencyAmountArray(int size, Map<Currency, DoubleArray> values) {
this.values = ImmutableSortedMap.copyOf(values);
this.size = size;
}