Java Code Examples for com.google.common.collect.ImmutableSortedMap#copyOf()

The following examples show how to use com.google.common.collect.ImmutableSortedMap#copyOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrequentSequenceMining.java    From sequence-mining with GNU General Public License v3.0 6 votes vote down vote up
/** 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);
	}
}
 
Example 2
Source File: TreeArtifactValue.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: CxxFlags.java    From buck with Apache License 2.0 6 votes vote down vote up
/** 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()));
}
 
Example 4
Source File: LongBits.java    From immutables with Apache License 2.0 6 votes vote down vote up
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);
            }
          }));
}
 
Example 5
Source File: CollectionUtil.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/** 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);
}
 
Example 6
Source File: EventFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: VertexLevelCriticalPathAnalyzer.java    From tez with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: Configuration.java    From batfish with Apache License 2.0 5 votes vote down vote up
@JsonProperty(PROP_IPSEC_PEER_CONFIGS)
public void setIpsecPeerConfigs(
    @Nullable NavigableMap<String, IpsecPeerConfig> ipsecPeerConfigs) {
  _ipsecPeerConfigs =
      ipsecPeerConfigs == null
          ? ImmutableSortedMap.of()
          : ImmutableSortedMap.copyOf(ipsecPeerConfigs);
}
 
Example 9
Source File: SequenceMiningCore.java    From sequence-mining with GNU General Public License v3.0 5 votes vote down vote up
/** 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;
}
 
Example 10
Source File: LionBundle.java    From onos with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: FileTree.java    From jimfs with Apache License 2.0 4 votes vote down vote up
/** Creates a new file tree with the given root directories. */
FileTree(Map<Name, Directory> roots) {
  this.roots = ImmutableSortedMap.copyOf(roots, Name.canonicalOrdering());
}
 
Example 12
Source File: FieldScan.java    From snowblossom with Apache License 2.0 4 votes vote down vote up
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);

}
 
Example 13
Source File: NameMap.java    From Quicksql with MIT License 4 votes vote down vote up
/** 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));
}
 
Example 14
Source File: Configuration.java    From batfish with Apache License 2.0 4 votes vote down vote up
@JsonProperty(PROP_COMMUNITY_SET_EXPRS)
private @Nonnull NavigableMap<String, CommunitySetExpr> getCommunitySetExprsSorted() {
  return ImmutableSortedMap.copyOf(_communitySetExprs);
}
 
Example 15
Source File: SparseArrayUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SortedMap<Integer, ? extends Number> load(SparseArray<?> sparseArray){
	return ImmutableSortedMap.copyOf(parse(sparseArray));
}
 
Example 16
Source File: FeatureVector.java    From presto with Apache License 2.0 4 votes vote down vote up
public FeatureVector(Map<Integer, Double> features)
{
    this.features = ImmutableSortedMap.copyOf(features);
}
 
Example 17
Source File: Configuration.java    From batfish with Apache License 2.0 4 votes vote down vote up
@JsonProperty(PROP_IKE_PHASE1_KEYS)
public void setIkePhase1Keys(@Nullable NavigableMap<String, IkePhase1Key> ikePhase1Keys) {
  _ikePhase1keys =
      ikePhase1Keys == null ? ImmutableSortedMap.of() : ImmutableSortedMap.copyOf(ikePhase1Keys);
}
 
Example 18
Source File: MultiCurrencyAmountArray.java    From Strata with Apache License 2.0 4 votes vote down vote up
@ImmutableConstructor
private MultiCurrencyAmountArray(int size, Map<Currency, DoubleArray> values) {
  this.values = ImmutableSortedMap.copyOf(values);
  this.size = size;
}
 
Example 19
Source File: ConfigFeatureFlagTransitionFactory.java    From bazel with Apache License 2.0 4 votes vote down vote up
public ConfigFeatureFlagValuesTransition(Map<Label, String> flagValues) {
  this(ImmutableSortedMap.copyOf(flagValues), flagValues.hashCode());
}
 
Example 20
Source File: Vrf.java    From batfish with Apache License 2.0 4 votes vote down vote up
public void setAppliedRibGroups(Map<RoutingProtocol, RibGroup> appliedRibGroups) {
  _appliedRibGroups = ImmutableSortedMap.copyOf(appliedRibGroups);
}