Example #1
0
        public virtual void getValues()
        {
            IDictionary <string, object> values  = ImmutableMap.of("foo", 1, "bar", 2);
            SingleTypeMarketDataConfig   configs = SingleTypeMarketDataConfig.builder().configType(typeof(Integer)).configObjects(values).build();

            assertThat(configs.get("foo")).isEqualTo(1);
            assertThat(configs.get("bar")).isEqualTo(2);
            assertThrowsIllegalArg(() => configs.get("baz"), "No configuration found with type java.lang.Integer and name baz");
        }
Example #2
0
        public virtual void addValue()
        {
            IDictionary <string, object> values  = ImmutableMap.of("foo", 1, "bar", 2);
            SingleTypeMarketDataConfig   configs = SingleTypeMarketDataConfig.builder().configType(typeof(Integer)).configObjects(values).build().withConfig("baz", 3);

            assertThat(configs.get("foo")).isEqualTo(1);
            assertThat(configs.get("bar")).isEqualTo(2);
            assertThat(configs.get("baz")).isEqualTo(3);
        }
        /// <summary>
        /// Returns the configuration object with the specified type and name if available.
        /// </summary>
        /// <param name="type"> the type of the configuration object </param>
        /// <param name="name"> the name of the configuration object </param>
        /// @param <T> the type of the configuration object </param>
        /// <returns> the configuration with the specified type and name </returns>
        /// <exception cref="IllegalArgumentException"> if no configuration is found with the specified type and name </exception>
        public T get <T>(Type <T> type, string name)
        {
            SingleTypeMarketDataConfig typeConfigs = configs.get(type);

            // simple match
            if (typeConfigs != null)
            {
                object config = typeConfigs.get(name);
                if (config == null)
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new System.ArgumentException(Messages.format("No configuration found with type {} and name {}", type.FullName, name));
                }
                return(type.cast(config));
            }
            // try looking for subclasses of an interface
            if (!type.IsInterface)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new System.ArgumentException("No configuration found for type " + type.FullName);
            }
            ImmutableList <SingleTypeMarketDataConfig> potentialTypes = MapStream.of(configs).filterKeys(type.isAssignableFrom).map((t, config) => config).filter(config => config.ConfigObjects.containsKey(name)).collect(toImmutableList());

            if (potentialTypes.Empty)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new System.ArgumentException("No configuration found for type " + type.FullName + " or subclasses");
            }
            if (potentialTypes.size() > 1)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new System.ArgumentException("Multiple configuration found for type " + type.FullName);
            }
            return(type.cast(potentialTypes.get(0).get(name)));
        }