/// <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)));
        }
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);
        }
Example #3
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");
        }
        /// <summary>
        /// Adds an item of configuration under the specified name.
        /// </summary>
        /// <param name="name">  the name of the configuration item </param>
        /// <param name="value">  the configuration item </param>
        /// <returns> this builder </returns>
        public MarketDataConfigBuilder add <T1>(TypedString <T1> name, object value)
        {
            ArgChecker.notNull(name, "name");
            ArgChecker.notNull(value, "value");

            Type configType = value.GetType();
            SingleTypeMarketDataConfig configs = configsForType(configType);

            values[configType] = configs.withConfig(name.Name, value);
            return(this);
        }
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         SingleTypeMarketDataConfig other = (SingleTypeMarketDataConfig)obj;
         return(JodaBeanUtils.equal(configType, other.configType) && JodaBeanUtils.equal(configObjects, other.configObjects));
     }
     return(false);
 }
        /// <summary>
        /// Returns a set of configuration object for the specified type, creating one and adding it to
        /// the map if not found.
        /// </summary>
        private SingleTypeMarketDataConfig configsForType(Type configType)
        {
            SingleTypeMarketDataConfig configs = values[configType];

            if (configs != null)
            {
                return(configs);
            }
            SingleTypeMarketDataConfig newConfigs = SingleTypeMarketDataConfig.builder().configType(configType).build();

            values[configType] = newConfigs;
            return(newConfigs);
        }
Example #7
0
 public virtual void addValueWrongType()
 {
     assertThrowsIllegalArg(() => SingleTypeMarketDataConfig.builder().configType(typeof(Integer)).build().withConfig("baz", "3"), ".* not of the required type .*");
 }