List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.openqa.selenium.server.htmlrunner.CoreTestStep.java
private static ImmutableMap<String, SeleneseCommand> buildCommands() { ImmutableMap.Builder<String, SeleneseCommand> commands = ImmutableMap.builder(); Set<String> seenNames = new HashSet<>(); // seed the seen names with methods we definitely don't want folks accessing seenNames.add("addCustomRequestHeader"); seenNames.add("allowNativeXpath"); seenNames.add("pause"); seenNames.add("rollup"); seenNames.add("setBrowserLogLevel"); seenNames.add("setExtensionJs"); seenNames.add("start"); seenNames.add("stop"); for (final Method method : Selenium.class.getMethods()) { if (!seenNames.add(method.getName())) { continue; }/*w w w .j av a2 s . c o m*/ if (method.getParameterCount() > 3) { continue; } SeleneseCommand underlyingCommand = (driver, selenium, locator, value) -> { try { switch (method.getParameterCount()) { case 0: return method.invoke(selenium); case 1: return method.invoke(selenium, locator); case 2: return method.invoke(selenium, locator, value); default: throw new RuntimeException("Exceptionally unlikely to get here"); } } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } }; commands.put(method.getName(), underlyingCommand); // Methods of the form getFoo(target) result in commands: // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo // storeFoo, waitForFoo, and waitForNotFoo. final String shortName; if (method.getName().startsWith("get")) { shortName = method.getName().substring("get".length()); } else if (method.getName().startsWith("is")) { shortName = method.getName().substring("is".length()); } else { shortName = null; } if (shortName != null) { SeleneseCommand performComparison = (driver, selenium, locator, value) -> { Object result = underlyingCommand.execute(driver, selenium, locator, value); if ("is".equals(shortName)) { return (Boolean) result; } String comparisonValue; switch (method.getParameterCount()) { case 0: comparisonValue = locator; break; case 1: comparisonValue = value; break; default: throw new RuntimeException("Unsure how to process this assert: " + method.getName()); } return Objects.equals(comparisonValue, String.valueOf(result)); }; commands.put("assert" + shortName, (driver, selenium, locator, value) -> { boolean result = (Boolean) performComparison.execute(driver, selenium, locator, value); if (!result) { throw new SeleniumException("Assertion failed"); } return null; }); commands.put("assertNot" + shortName, (driver, selenium, locator, value) -> { boolean result = (Boolean) performComparison.execute(driver, selenium, locator, value); if (result) { throw new SeleniumException("Negative assertion failed"); } return null; }); commands.put("verify" + shortName, (driver, selenium, locator, value) -> { boolean result = (Boolean) performComparison.execute(driver, selenium, locator, value); if (!result) { System.out.println("Verification failed"); } return null; }); commands.put("verifyNot" + shortName, (driver, selenium, locator, value) -> { boolean result = (Boolean) performComparison.execute(driver, selenium, locator, value); if (result) { System.out.println("Negative verification failed"); } return null; }); } } commands.put("pause", (driver, selenium, locator, value) -> { try { long timeout = Long.parseLong(locator); Thread.sleep(timeout); return null; } catch (NumberFormatException e) { throw new SeleniumException("Unable to parse timeout: " + locator); } catch (InterruptedException e) { System.exit(255); throw new RuntimeException("We never get this far"); } }); return commands.build(); }
From source file:com.opengamma.strata.examples.marketdata.timeseries.FixingSeriesCsvLoader.java
/** * Loads a set of historical fixing series into memory from CSV resources. * //from w w w . j a v a 2s .c o m * @param fixingSeriesResources the fixing series CSV resources * @return the loaded fixing series, mapped by {@linkplain ObservableId observable ID} */ public static Map<ObservableId, LocalDateDoubleTimeSeries> loadFixingSeries( Collection<ResourceLocator> fixingSeriesResources) { ImmutableMap.Builder<ObservableId, LocalDateDoubleTimeSeries> builder = ImmutableMap.builder(); for (ResourceLocator timeSeriesResource : fixingSeriesResources) { // builder ensures keys can only be seen once builder.putAll(loadFixingSeries(timeSeriesResource)); } return builder.build(); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.model.KubernetesV2Application.java
public Map<String, String> getAttributes() { return new ImmutableMap.Builder<String, String>().put("name", name).build(); }
From source file:com.teradata.tpcds.row.generator.AbstractRowGenerator.java
public AbstractRowGenerator(Table table) { ImmutableMap.Builder<GeneratorColumn, RandomNumberStream> mapBuilder = ImmutableMap.builder(); for (GeneratorColumn column : table.getGeneratorColumns()) { mapBuilder.put(column,/*from w w w .j a v a 2s. co m*/ new RandomNumberStreamImpl(column.getGlobalColumnNumber(), column.getSeedsPerRow())); } randomNumberStreamMap = mapBuilder.build(); }
From source file:com.fizzbuzz.vroom.core.api.resource.ResourceRegistry.java
public static <KR extends KeyedResource> String getPath(Class<KR> keyedResourceClass, String id) { return UriHelper.formatUriTemplate(getPathTemplate(keyedResourceClass), new ImmutableMap.Builder<String, String>().put(getIdToken(keyedResourceClass), id).build()); }
From source file:co.indexia.antiquity.graph.ElementUtils.java
/** * Returns {@link Element}'s properties as an immutable map. * /* w w w . jav a2 s. com*/ * @return An immutable map of the specified {@link Element} properties * exlcuding the specified keys */ public static Map<String, Object> getPropertiesAsMap(Element element, Set<String> excludedKeys) { Builder<String, Object> props = ImmutableMap.builder(); for (String key : element.getPropertyKeys()) { if ((excludedKeys != null) && excludedKeys.contains(key)) { continue; } props.put(key, element.getProperty(key)); } return props.build(); }
From source file:com.spectralogic.ds3autogen.converters.UpdateElementsConverter.java
/** * Updates all Ds3Type's Ds3Elements to properly denote nullability or exclusion *//*w w w .j ava 2 s .c o m*/ protected static ImmutableMap<String, Ds3Type> updateElementsInTypeMap( final ImmutableMap<String, Ds3Type> typeMap) { if (isEmpty(typeMap)) { return ImmutableMap.of(); } final ImmutableMap.Builder<String, Ds3Type> builder = ImmutableMap.builder(); for (final Map.Entry<String, Ds3Type> entry : typeMap.entrySet()) { builder.put(entry.getKey(), updateElementsInType(entry.getValue())); } return builder.build(); }
From source file:org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.environment.EnvironmentParser.java
@Override public Map<String, String> parse(CommonTree environment, ICommonTreeParserParameter param) { ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>(); List<CommonTree> children = environment.getChildren(); for (CommonTree child : children) { String left;/*from w w w .ja v a2 s.co m*/ String right; left = child.getChild(0).getChild(0).getChild(0).getText(); right = child.getChild(1).getChild(0).getChild(0).getText(); builder.put(left, right); } return builder.build(); }
From source file:be.fror.ecs.Engine.java
Engine(EngineBuilder builder) { components = new Component[builder.componentTypes.size()][32]; processors = builder.processors.toArray(new Processor[0]); {/* ww w . j a va2 s.co m*/ ImmutableMap.Builder<Type, ComponentMapper<?>> componentMappersBuilder = ImmutableMap.builder(); int i = 0; for (Type c : builder.componentTypes) { componentMappersBuilder.put(c, new ComponentMapper(this, i)); i++; } componentMappers = componentMappersBuilder.build(); } }
From source file:org.feature4j.FeatureBundleProviderImpl.java
@Override public FeatureBundle getFeatures(FeaturesContext context) { final ImmutableMap.Builder<String, Object> featureMapBuilder = ImmutableMap.builder(); for (Feature feature : features) { Object value = getValue(context, feature); featureMapBuilder.put(feature.key(), value); }/*from www.j a v a 2 s .c om*/ return new FeatureBundle(featureMapBuilder.build()); }