List of usage examples for com.google.common.collect ImmutableMap.Builder put
public final V put(K k, V v)
From source file:com.jgaap.backend.EventDrivers.java
private static ImmutableMap<String, EventDriver> loadEventDriversMap() { // Load the event drivers dynamically ImmutableMap.Builder<String, EventDriver> builder = ImmutableMap.builder(); for (EventDriver eventDriver : EVENT_DRIVERS) { builder.put(eventDriver.displayName().toLowerCase().trim(), eventDriver); }/*from ww w. j a v a 2s. co m*/ return builder.build(); }
From source file:org.jclouds.rackspace.autoscale.v1.internal.ParseHelper.java
public static ImmutableMap<String, Object> buildScalingPolicyMap(CreateScalingPolicy scalingPolicy) { ImmutableMap.Builder<String, Object> scalingPolicyMapBuilder = ImmutableMap.builder(); scalingPolicyMapBuilder.put("cooldown", scalingPolicy.getCooldown()); scalingPolicyMapBuilder.put("type", scalingPolicy.getType().toString()); scalingPolicyMapBuilder.put("name", scalingPolicy.getName()); // A couple of different scaling policies are supported, such as percent or number based, or targeting specific numbers of instances String targetString = scalingPolicy.getTarget(); Integer targetInt = Ints.tryParse(targetString); // Notes:/*from www.ja v a 2 s . co m*/ // 1. Refactor when autoscale is complete and service is released to dry this code. // 2. Refactor to use simpler code for the number parsing. Polymorphism or a facade might work. // 3. Potentially remove or rework the enum code. Float targetFloat; if (targetInt != null) { scalingPolicyMapBuilder.put(scalingPolicy.getTargetType().toString(), targetInt); } else if ((targetFloat = Floats.tryParse(targetString)) != null) { scalingPolicyMapBuilder.put(scalingPolicy.getTargetType().toString(), targetFloat); } else { scalingPolicyMapBuilder.put(scalingPolicy.getTargetType().toString(), targetString); } if (scalingPolicy.getSchedulingType() != null && scalingPolicy.getType().equals(ScalingPolicyType.SCHEDULE)) { // Have to use getters to rebuild map scalingPolicyMapBuilder.put("args", ImmutableMap.of(scalingPolicy.getSchedulingType().toString(), scalingPolicy.getSchedulingString())); } return scalingPolicyMapBuilder.build(); }
From source file:com.google.googlejavaformat.intellij.FormatterUtil.java
static Map<TextRange, String> getReplacements(Formatter formatter, String text, Collection<TextRange> ranges) { try {//w ww .j a v a2 s . c o m ImmutableMap.Builder<TextRange, String> replacements = ImmutableMap.builder(); formatter.getFormatReplacements(text, toRanges(ranges)).forEach(replacement -> replacements .put(toTextRange(replacement.getReplaceRange()), replacement.getReplacementString())); return replacements.build(); } catch (FormatterException e) { return ImmutableMap.of(); } }
From source file:rx.transformer.GuavaTransformers.java
/** * Returns a Transformer<T,ImmutableMap<K,V>> that maps an Observable<T> to an Observable<ImmutableMap<K,V>>><br><br> * with a given Func1<T,K> keyMapper and Func1<T,V> valueMapper *//*from ww w.j a v a 2s. c o m*/ public static <T, K, V> Observable.Transformer<T, ImmutableMap<K, V>> toImmutableMap( final Func1<T, K> keyMapper, final Func1<T, V> valueMapper) { return new Observable.Transformer<T, ImmutableMap<K, V>>() { @Override public Observable<ImmutableMap<K, V>> call(Observable<T> observable) { return observable.collect(new Func0<ImmutableMap.Builder<K, V>>() { @Override public ImmutableMap.Builder<K, V> call() { return ImmutableMap.builder(); } }, new Action2<ImmutableMap.Builder<K, V>, T>() { @Override public void call(ImmutableMap.Builder<K, V> builder, T t) { builder.put(keyMapper.call(t), valueMapper.call(t)); } }).map(new Func1<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>>() { @Override public ImmutableMap<K, V> call(ImmutableMap.Builder<K, V> builder) { return builder.build(); } }); } }; }
From source file:com.sos.scheduler.engine.kernel.command.DispatchingResultXmlizer.java
private static ImmutableMap<Class<?>, ResultXmlizer> mapOfXmlizers(Iterable<ResultXmlizer> rx) { ImmutableMap.Builder<Class<?>, ResultXmlizer> b = new ImmutableMap.Builder<Class<?>, ResultXmlizer>(); for (ResultXmlizer r : rx) b.put(r.getResultClass(), r); return b.build(); }
From source file:com.helion3.safeguard.commands.ZoneCommands.java
/** * Build a complete command hierarchy// w ww .ja v a 2 s .c o m * @return */ public static CommandSpec getCommand() { // Build child commands ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder(); builder.put(ImmutableList.of("create", "c"), new ZoneCreateCommand()); builder.put(ImmutableList.of("allow", "a"), new ZoneAllowCommand()); builder.put(ImmutableList.of("deny", "d"), new ZoneDenyCommand()); builder.put(ImmutableList.of("delete"), ZoneDeleteCommand.getCommand()); builder.put(ImmutableList.of("flag", "f"), ZoneFlagCommand.getCommand()); return CommandSpec.builder().executor((source, args) -> { if (!(source instanceof Player)) { source.sendMessage(Format.error("Command usable only by a player.")); return CommandResult.empty(); } Player player = (Player) source; List<Zone> zones = SafeGuard.getZoneManager().getZones(player.getLocation()); if (zones.isEmpty()) { source.sendMessage(Format.error("No zone found for your position.")); return CommandResult.empty(); } for (Zone zone : zones) { source.sendMessage(Format.heading("Zone " + zone.getName())); // Owners source.sendMessage(Format.subdued("Owners:")); for (GameProfile profile : zone.getOwners()) { source.sendMessage(Format.message(profile.getName())); } // Volume source.sendMessage(Format.subdued("Volume:")); source.sendMessage(Format.message( zone.getVolume().getMin().toString() + ", " + zone.getVolume().getMax().toString())); source.sendMessage(Format.message("Blocks: " + zone.getVolume().getVolume())); // Flags source.sendMessage(Format.subdued("Flags:")); for (Map.Entry<String, Boolean> entry : zone.getPermissions().getPermissions().entrySet()) { source.sendMessage(Format.message(entry.getKey(), TextColors.YELLOW, entry.getValue())); } } return CommandResult.empty(); }).children(builder.build()).build(); }
From source file:com.spectralogic.ds3contractcomparator.Ds3ApiSpecComparatorImpl.java
/** * Creates an {@link ImmutableMap} of {@link Ds3Request#getName()} to {@link Ds3Request} for easy searching *///from w w w .j a va 2 s.com static ImmutableMap<String, Ds3Request> toRequestMap(final ImmutableList<Ds3Request> requests) { if (isEmpty(requests)) { return ImmutableMap.of(); } final ImmutableMap.Builder<String, Ds3Request> builder = ImmutableMap.builder(); requests.forEach(request -> builder.put(request.getName(), request)); return builder.build(); }
From source file:com.spotify.missinglink.datamodel.PrimitiveTypeDescriptor.java
private static ImmutableMap<String, PrimitiveTypeDescriptor> createMapping() { ImmutableMap.Builder<String, PrimitiveTypeDescriptor> bob = ImmutableMap.builder(); for (PrimitiveTypeDescriptor type : PrimitiveTypeDescriptor.values()) { bob.put(Character.toString(type.raw), type); }/*from w w w . ja v a 2 s . c o m*/ return bob.build(); }
From source file:edu.bsu.cybersec.core.EmployeePool.java
private static ImmutableMap<EmployeeProfile, Image> makeDeveloperMap(GameAssets assets) { ImmutableMap.Builder<EmployeeProfile, Image> builder = ImmutableMap.builder(); builder.put(EmployeeProfile.firstName("Esteban").lastName("Cortez") .withDegree("Bachelors in Computer Science").from("Ball State University") .bio("Esteban worked in a factory until he was 33, then he went to college and decided to get involved in software development."), assets.getImage(GameAssets.ImageKey.ESTEBAN)); builder.put(EmployeeProfile.firstName("Nancy").lastName("Stevens").withDegree("Bachelors in English") .from("Georgetown University").withDegree("Masters in Computer Security").from("Purdue University") .bio("Nancy has a popular podcast about being a woman in technology."), assets.getImage(GameAssets.ImageKey.NANCY)); builder.put(EmployeeProfile.firstName("Jerry").lastName("Chen").withDegree("Bachelors in Computer Science") .from("University of Hong Kong") .bio("Jerry interned at a local company in high school and has been working as a software developer ever since."), assets.getImage(GameAssets.ImageKey.JERRY)); builder.put(EmployeeProfile.firstName("Vani").lastName("Mishra") .withDegree("Bachelors in Computer Engineering").from("Indian Institute of Science") .withDegree("Masters in Software Engineering").from("Ball State University") .bio("Vani was born in India and came to the United States for graduate school. She loves music, dancing, and PHP."), assets.getImage(GameAssets.ImageKey.VANI)); builder.put(EmployeeProfile.firstName("Abdullah").lastName("Nasr") .withDegree("Bachelors in Electrical Engineering").from("Iowa State University") .bio("Abdullah used to work for a larger social media company, but he prefers the excitement of a small startup."), assets.getImage(GameAssets.ImageKey.ABDULLAH)); builder.put(EmployeeProfile.firstName("Janine").lastName("Palmer") .withDegree("Bachelors in Computer Science").from("Virginia Tech") .bio("Janine is especially talented at meeting with customers and understanding what they want from a product."), assets.getImage(GameAssets.ImageKey.JANINE)); builder.put(EmployeeProfile.firstName("Melissa").lastName("Bernard").withDegree("Bachelors in Mathematics") .from("Stanford University") .bio("Melissa has always loved games and puzzles, but she especially loves bicycling and walking her German Shepherd."), assets.getImage(GameAssets.ImageKey.MELISSA)); builder.put(// ww w . ja va 2 s . c om EmployeeProfile.firstName("Ivar").lastName("Johansen").withDegree("Bachelors in Chemistry") .from("Stockholm University").withDegree("Masters in Electrical Engineering") .from("Uppsala University") .bio("Ivar teaches kids how to build simple robots as a volunteer in a local school."), assets.getImage(GameAssets.ImageKey.IVAR)); builder.put(EmployeeProfile.firstName("Bruce").lastName("Powers") .withDegree("Bachelors in Computer Science").from("Ball State University") .bio("Bruce was recently married and enjoys going to the gym and watching documentaries about history."), assets.getImage(GameAssets.ImageKey.BRUCE)); return builder.build(); }
From source file:com.spotify.helios.common.descriptors.ServicePorts.java
private static ServicePorts of(final Iterable<String> ports) { final ImmutableMap.Builder<String, ServicePortParameters> builder = ImmutableMap.builder(); for (final String port : ports) { builder.put(port, new ServicePortParameters(null)); }//from ww w . ja v a 2s . c o m return new ServicePorts(builder.build()); }