@Override public Set<String> get() { String regionString = config.apply(configKey); if (regionString == null) { logger.debug("no %s configured for provider %s", configKey, provider); return ImmutableSet.of(); } else { return ImmutableSet.copyOf(Splitter.on(',').split(regionString)); } }
@Override public Set<String> get() { String regionString = config.apply(configKey); if (regionString == null) { logger.debug("no %s configured for provider %s", configKey, provider); return ImmutableSet.of(); } else { return ImmutableSet.copyOf(Splitter.on(',').split(regionString)); } }
@Override public Set<String> get() { String regionString = config.apply(configKey); if (regionString == null) { logger.debug("no %s configured for provider %s", configKey, provider); return ImmutableSet.of(); } else { return ImmutableSet.copyOf(Splitter.on(',').split(regionString)); } }
@Override public Set<String> get() { String regionString = config.apply(configKey); if (regionString == null) { logger.debug("no %s configured for provider %s", configKey, provider); return ImmutableSet.of(); } else { return ImmutableSet.copyOf(Splitter.on(',').split(regionString)); } }
@Override public Set<String> get() { String regionString = config.apply(configKey); if (regionString == null) { logger.debug("no %s configured for provider %s", configKey, provider); return ImmutableSet.of(); } else { return ImmutableSet.copyOf(Splitter.on(',').split(regionString)); } }
@Override public Set<String> get() { String regionString = config.apply(configKey); if (regionString == null) { logger.debug("no %s configured for provider %s", configKey, provider); return ImmutableSet.of(); } else { return ImmutableSet.copyOf(Splitter.on(',').split(regionString)); } }
@Override public Map<String, Supplier<URI>> get() { Builder<String, Supplier<URI>> locations = ImmutableMap.builder(); for (String location : locationIds.get()) { String configKey = configPrefix + "." + location + "." + ENDPOINT; String locationUri = config.apply(configKey); if (locationUri == null) { logger.debug("config key %s not present, defaulting to %s", configKey, providerURI); locations.put(location, providerURI); } else { locations.put(location, Suppliers.ofInstance(URI.create(locationUri))); } } return locations.build(); }
@Override public Map<String, Supplier<URI>> get() { Builder<String, Supplier<URI>> locations = ImmutableMap.builder(); for (String location : locationIds.get()) { String configKey = configPrefix + "." + location + "." + ENDPOINT; String locationUri = config.apply(configKey); if (locationUri == null) { logger.debug("config key %s not present, defaulting to %s", configKey, providerURI); locations.put(location, providerURI); } else { locations.put(location, Suppliers.ofInstance(URI.create(locationUri))); } } return locations.build(); }
@Override public Map<String, Supplier<URI>> get() { Builder<String, Supplier<URI>> locations = ImmutableMap.builder(); for (String location : locationIds.get()) { String configKey = configPrefix + "." + location + "." + ENDPOINT; String locationUri = config.apply(configKey); if (locationUri == null) { logger.debug("config key %s not present, defaulting to %s", configKey, providerURI); locations.put(location, providerURI); } else { locations.put(location, Suppliers.ofInstance(URI.create(locationUri))); } } return locations.build(); }
@Override public Map<String, Supplier<URI>> get() { Builder<String, Supplier<URI>> locations = ImmutableMap.builder(); for (String location : locationIds.get()) { String configKey = configPrefix + "." + location + "." + ENDPOINT; String locationUri = config.apply(configKey); if (locationUri == null) { logger.debug("config key %s not present, defaulting to %s", configKey, providerURI); locations.put(location, providerURI); } else { locations.put(location, Suppliers.ofInstance(URI.create(locationUri))); } } return locations.build(); }
@Override public ReferenceType apply(Iterable<ReferenceType> referenceTypes) { checkNotNull(referenceTypes, "referenceTypes"); checkArgument(Iterables.size(referenceTypes) > 0, "No referenceTypes corresponding to configuration key %s present", configurationKey); if (Iterables.size(referenceTypes) == 1) return Iterables.getLast(referenceTypes); String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey); if (namingPattern != null) { return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern); } else { return defaultReferenceType(referenceTypes); } }
@Override public ReferenceType apply(Iterable<ReferenceType> referenceTypes) { checkNotNull(referenceTypes, "referenceTypes"); checkArgument(Iterables.size(referenceTypes) > 0, "No referenceTypes corresponding to configuration key %s present", configurationKey); if (Iterables.size(referenceTypes) == 1) return Iterables.getLast(referenceTypes); String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey); if (namingPattern != null) { return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern); } else { return defaultReferenceType(referenceTypes); } }
@Override public ReferenceType apply(Iterable<ReferenceType> referenceTypes) { checkNotNull(referenceTypes, "referenceTypes"); checkArgument(Iterables.size(referenceTypes) > 0, "No referenceTypes corresponding to configuration key %s present", configurationKey); if (Iterables.size(referenceTypes) == 1) return Iterables.getLast(referenceTypes); String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey); if (namingPattern != null) { return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern); } else { return defaultReferenceType(referenceTypes); } }
@Override public ReferenceType apply(Iterable<ReferenceType> referenceTypes) { checkNotNull(referenceTypes, "referenceTypes"); checkArgument(Iterables.size(referenceTypes) > 0, "No referenceTypes corresponding to configuration key %s present", configurationKey); if (Iterables.size(referenceTypes) == 1) return Iterables.getLast(referenceTypes); String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey); if (namingPattern != null) { return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern); } else { return defaultReferenceType(referenceTypes); } }
@Test public void testNotThere() { assertEquals(Guice.createInjector().getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), null); }
@Test public void testThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to("bar"); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "bar"); }
@Test public void testEmptyIsThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to(""); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), ""); } }
@Test public void testEmptyIsThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to(""); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), ""); } }
@Test public void testNotThere() { assertEquals(Guice.createInjector().getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), null); }
@Test public void testThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to("bar"); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "bar"); }