//------------------------------------------------------------------------- /// <summary> /// Puts a single value into the map. /// <para> /// If the key already exists, the value will be replaced. /// /// </para> /// </summary> /// @param <R> the type of the value </param> /// <param name="key"> the key to add </param> /// <param name="value"> the value to add </param> /// <returns> this builder </returns> public ExplainMapBuilder put <R>(ExplainKey <R> key, R value) { ArgChecker.notNull(key, "key"); ArgChecker.notNull(value, "value"); map[key] = value; return(this); }
//------------------------------------------------------------------------- /// <summary> /// Adds a list entry using a consumer callback function. /// <para> /// This is an alternative to using <seealso cref="#openListEntry(ExplainKey)"/> and /// <seealso cref="#closeListEntry(ExplainKey)"/> directly. /// The consumer function receives the child builder and must add data to it. /// /// </para> /// </summary> /// @param <R> the type of the value </param> /// <param name="key"> the list key to open </param> /// <param name="consumer"> the consumer that receives the list entry builder and adds to it </param> /// <returns> this builder </returns> public ExplainMapBuilder addListEntry <R>(ExplainKey <R> key, System.Action <ExplainMapBuilder> consumer) { ExplainMapBuilder child = openListEntry(key); consumer(child); return(child.closeListEntry(key)); }
//----------------------------------------------------------------------- public virtual void coverage() { ExplainKey <string> test = ExplainKey.of("Foo"); assertEquals(test.ToString(), "Foo"); assertSerialization(test); assertJodaConvert(typeof(ExplainKey), test); }
/// <summary> /// Adds a list entry using a consumer callback function, including the list index. /// <para> /// This is an alternative to using <seealso cref="#openListEntry(ExplainKey)"/> and /// <seealso cref="#closeListEntry(ExplainKey)"/> directly. /// The consumer function receives the child builder and must add data to it. /// /// </para> /// </summary> /// @param <R> the type of the value </param> /// <param name="key"> the list key to open </param> /// <param name="consumer"> the consumer that receives the list entry builder and adds to it </param> /// <returns> this builder </returns> public ExplainMapBuilder addListEntryWithIndex <R>(ExplainKey <R> key, System.Action <ExplainMapBuilder> consumer) { ExplainMapBuilder child = openListEntry(key); // find index object value = map[key]; //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.ArrayList<Object> list = (java.util.ArrayList<Object>) value; List <object> list = (List <object>)value; child.put(ExplainKey.ENTRY_INDEX, list.Count - 1); consumer(child); return(child.closeListEntry(key)); }
/// <summary> /// Closes the currently open list. /// <para> /// This returns the parent builder. /// /// </para> /// </summary> /// @param <R> the type of the value </param> /// <param name="key"> the list key to close </param> /// <returns> the parent builder </returns> public ExplainMapBuilder closeListEntry <R>(ExplainKey <R> key) { object value = parent.map[key]; if (value is ArrayList == false) { throw new System.InvalidOperationException("ExplainMapBuilder.closeList() called but no list found to close"); } // close entry by converting it from ExplainMapBuilder to ExplainMap //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.ArrayList<Object> list = (java.util.ArrayList<Object>) value; List <object> list = (List <object>)value; ExplainMapBuilder closedEntry = (ExplainMapBuilder)list[list.Count - 1]; list[list.Count - 1] = closedEntry.build(); return(parent); }
//------------------------------------------------------------------------- /// <summary> /// Opens a list entry to be populated. /// <para> /// This returns the builder for the new list entry. /// If the list does not exist, it is created and the first entry added. /// If the list has already been created, the entry is appended. /// </para> /// <para> /// Once opened, the child builder resulting from this method must be used. /// The method <seealso cref="#closeListEntry(ExplainKey)"/> must be used to close the /// child and receive an instance of the parent back again. /// /// </para> /// </summary> /// @param <R> the type of the value </param> /// <param name="key"> the list key to open </param> /// <returns> the child builder </returns> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") public <R extends java.util.List<?>> ExplainMapBuilder openListEntry(ExplainKey<R> key) public ExplainMapBuilder openListEntry <R>(ExplainKey <R> key) { // list entry is a ExplainMapBuilder, making use of erasure in generics // builder is converted to ExplainMap when entry is closed ExplainMapBuilder child = new ExplainMapBuilder(this); object value = map[key]; List <object> list; if (value is List <object> ) { list = (List <object>)value; } else { list = new List <>(); map[key] = list; } list.Add(child); return(child); }
//------------------------------------------------------------------------- /// <summary> /// Gets a value by key. /// </summary> /// @param <R> the type of the key </param> /// <param name="key"> the key to lookup </param> /// <returns> the value associated with the key </returns> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") public <R> java.util.Optional<R> get(ExplainKey<R> key) public Optional <R> get <R>(ExplainKey <R> key) { return((Optional <R>)Optional.ofNullable(map.get(key))); }