//------------------------------------------------------------------------- /// <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 test_builder_openClose_wrongCloseKey() { ExplainMapBuilder builder = ExplainMap.builder(); ExplainMapBuilder child = builder.openListEntry(ExplainKey.LEGS); child.put(ExplainKey.ACCRUAL_DAYS, 2); assertThrows(() => child.closeListEntry(ExplainKey.PAYMENT_PERIODS), typeof(System.InvalidOperationException)); }
//------------------------------------------------------------------------- public virtual void test_builder_simple() { ExplainMapBuilder builder = ExplainMap.builder(); builder.put(ExplainKey.ACCRUAL_DAYS, 2); ExplainMap test = builder.build(); assertEquals(test.Map.size(), 1); assertEquals(test.get(ExplainKey.ACCRUAL_DAYS), 2); assertEquals(test.get(ExplainKey.ACCRUAL_DAY_COUNT), null); }
/// <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)); }
public virtual void test_builder_addListEntry() { ExplainMapBuilder @base = ExplainMap.builder(); ExplainMapBuilder result1 = @base.addListEntry(ExplainKey.LEGS, child => child.put(ExplainKey.ACCRUAL_DAYS, 2)); ExplainMapBuilder result2 = result1.addListEntry(ExplainKey.LEGS, child => child.put(ExplainKey.ACCRUAL_DAYS, 3)); ExplainMap test = result2.build(); assertEquals(test.Map.size(), 1); assertEquals(test.get(ExplainKey.LEGS).Present, true); assertEquals(test.get(ExplainKey.LEGS).get().size(), 2); assertEquals(test.get(ExplainKey.LEGS).get().get(0).get(ExplainKey.ACCRUAL_DAYS), 2); assertEquals(test.get(ExplainKey.LEGS).get().get(1).get(ExplainKey.ACCRUAL_DAYS), 3); }
public virtual void test_builder_openClose() { ExplainMapBuilder builder = ExplainMap.builder(); ExplainMapBuilder child = builder.openListEntry(ExplainKey.LEGS); child.put(ExplainKey.ACCRUAL_DAYS, 2); ExplainMapBuilder result = child.closeListEntry(ExplainKey.LEGS); ExplainMap test = result.build(); assertEquals(test.Map.size(), 1); assertEquals(test.get(ExplainKey.LEGS).Present, true); assertEquals(test.get(ExplainKey.LEGS).get().size(), 1); assertEquals(test.get(ExplainKey.LEGS).get().get(0).get(ExplainKey.ACCRUAL_DAYS), 2); }
/// <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> /// Creates a new instance. /// </summary> /// <param name="parent"> the parent builder </param> internal ExplainMapBuilder(ExplainMapBuilder parent) { this.parent = parent; }
/// <summary> /// Creates a new instance. /// </summary> internal ExplainMapBuilder() { this.parent = null; }