test_class.declarator: NS = "namespace"
test_class.modifier: private static final
test_class.original_string: private static final String NS = "namespace";
test_class.type: String
test_class.var_name: NS
test_class.file: BackEnd/Core/sailfish-core/src/test/java/com/exactpro/sf/aml/scriptutil/LegReorderTest.java
test_class.identifier: LegReorderTest
test_class.superclass: extends AbstractTest
test_case.body: @SuppressWarnings("unchecked")
  	@Test
  	public void testSortByNestedLeg() {
          ComparatorSettings settings = new ComparatorSettings();
  
  		// Build Message:
  		IMessage msg_leg1 = fromString("leg", "FLD_1=10|FLD_2=20|", "NESTED", fromString("leg", "FLD_3=50|FLD_4=60|"));
  		IMessage msg_leg2 = fromString("leg", "FLD_1=30|FLD_2=40|", "NESTED", fromString("leg", "FLD_3=70|FLD_4=80|"));
  		IMessage message = fromString("name", "FIELD=value|", "LEGS", asList(msg_leg1, msg_leg2));
  
  		// Build Filter: Here we sort by nested legs
  		IMessage filter_leg1 = fromString("leg", null, "NESTED", fromString("leg", "FLD_3=50|FLD_4=60|"));
  		IMessage filter_leg2 = fromString("leg", null, "NESTED", fromString("leg", "FLD_3=70|FLD_4=80|"));
  		IMessage filter = fromString("name", null, "LEGS", asList(filter_leg1, filter_leg2));
  
  		IMessage result = LegReorder.reorder(message, filter, settings);
  		List<IMessage> result_legs = (List<IMessage>) result.getField("LEGS");
          Assert.assertEquals(msg_leg1.<Object>getField("FLD_1"), result_legs.get(0).<Object>getField("FLD_1"));
          Assert.assertEquals(msg_leg1.<Object>getField("FLD_2"), result_legs.get(0).<Object>getField("FLD_2"));
  		Assert.assertEquals("FLD_3=50|FLD_4=60", result_legs.get(0).getField("NESTED").toString());
          Assert.assertEquals(msg_leg2.<Object>getField("FLD_1"), result_legs.get(1).<Object>getField("FLD_1"));
          Assert.assertEquals(msg_leg2.<Object>getField("FLD_2"), result_legs.get(1).<Object>getField("FLD_2"));
  		Assert.assertEquals("FLD_3=70|FLD_4=80", result_legs.get(1).getField("NESTED").toString());
  
  		// Filter with swapped legs
  		IMessage filter_swap = fromString("name", null, "LEGS", asList(filter_leg2, filter_leg1));
  
  		IMessage result_swap = LegReorder.reorder(message, filter_swap, settings);
  		List<IMessage> result_legs_swapped = (List<IMessage>) result_swap.getField("LEGS");
          Assert.assertEquals(msg_leg2.<Object>getField("FLD_1"), result_legs_swapped.get(0).<Object>getField("FLD_1"));
          Assert.assertEquals(msg_leg2.<Object>getField("FLD_2"), result_legs_swapped.get(0).<Object>getField("FLD_2"));
  		Assert.assertEquals("FLD_3=70|FLD_4=80", result_legs_swapped.get(0).getField("NESTED").toString());
          Assert.assertEquals(msg_leg1.<Object>getField("FLD_1"), result_legs_swapped.get(1).<Object>getField("FLD_1"));
          Assert.assertEquals(msg_leg1.<Object>getField("FLD_2"), result_legs_swapped.get(1).<Object>getField("FLD_2"));
  		Assert.assertEquals("FLD_3=50|FLD_4=60", result_legs_swapped.get(1).getField("NESTED").toString());
  	}
test_case.class_method_signature: LegReorderTest.testSortByNestedLeg()
test_case.full_signature: @SuppressWarnings("unchecked") @Test public void testSortByNestedLeg()
test_case.identifier: testSortByNestedLeg
test_case.invocations: fromString fromString fromString fromString fromString asList fromString fromString fromString fromString fromString asList reorder getField assertEquals getField getField get assertEquals getField getField get assertEquals toString getField get assertEquals getField getField get assertEquals getField getField get assertEquals toString getField get fromString asList reorder getField assertEquals getField getField get assertEquals getField getField get assertEquals toString getField get assertEquals getField getField get assertEquals getField getField get assertEquals toString getField get
test_case.modifiers: @SuppressWarnings("unchecked") @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSortByNestedLeg()
focal_class.declarator: logger = LoggerFactory.getLogger(LegReorder.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(LegReorder.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/aml/scriptutil/LegReorder.java
focal_class.identifier: LegReorder
focal_class.class_method_signature: LegReorder.LegReorder()
focal_class.full_signature: private  LegReorder()
focal_class.identifier: LegReorder
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  LegReorder()
focal_class.class_method_signature: LegReorder.reorder(IMessage message, IMessage filter, ComparatorSettings settings)
focal_class.full_signature: public static IMessage reorder(IMessage message, IMessage filter, ComparatorSettings settings)
focal_class.identifier: reorder
focal_class.modifiers: public static
focal_class.parameters: (IMessage message, IMessage filter, ComparatorSettings settings)
focal_class.return: IMessage
focal_class.signature: IMessage reorder(IMessage message, IMessage filter, ComparatorSettings settings)
focal_class.class_method_signature: LegReorder.findPermute(List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.full_signature: private static int[] findPermute(List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.identifier: findPermute
focal_class.modifiers: private static
focal_class.parameters: (List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.return: int[]
focal_class.signature: int[] findPermute(List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.class_method_signature: LegReorder.findPermute(int[] arr, int k, Boolean[][] equality, List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.full_signature: private static boolean findPermute(int[] arr, int k, Boolean[][] equality, List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.identifier: findPermute
focal_class.modifiers: private static
focal_class.parameters: (int[] arr, int k, Boolean[][] equality, List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.return: boolean
focal_class.signature: boolean findPermute(int[] arr, int k, Boolean[][] equality, List<IMessage> message_legs, List<IMessage> filter_legs, ComparatorSettings settings)
focal_class.class_method_signature: LegReorder.swap(int[] arr, int i, int k)
focal_class.full_signature: private static void swap(int[] arr, int i, int k)
focal_class.identifier: swap
focal_class.modifiers: private static
focal_class.parameters: (int[] arr, int i, int k)
focal_class.return: void
focal_class.signature: void swap(int[] arr, int i, int k)
focal_method.body: public static IMessage reorder(IMessage message, IMessage filter, ComparatorSettings settings) {
  		logger.debug("start reorder legs");
  		logger.debug("message: {}", message);
  		logger.debug("filter: {}", filter);
  
  		for (String fieldName : message.getFieldNames()) {
  			Object message_field = message.getField(fieldName);
  			Object filter_field = filter.getField(fieldName);
  
  			if (message_field == null || filter_field == null) {
  				continue;
  			}
  
  			if (message_field instanceof List && filter_field instanceof List) {
                  @SuppressWarnings("unchecked")
                  List<IMessage> message_legs = (List<IMessage>)message_field;
  
                  @SuppressWarnings("unchecked")
                  List<IMessage> filter_legs = (List<IMessage>)filter_field;
  
  				int m_size = message_legs.size();
  				int f_size = filter_legs.size();
  
  				if (m_size == 0 || f_size == 0) {
  					continue;
  				}
  
  				// Mapping of legs: order[i]-th leg should be i-th in resulting list
  				int[] order = findPermute(message_legs, filter_legs, settings);
  				if (order == null) {
  					StringBuilder sb = new StringBuilder();
  					sb.append("\n").append("LEGS: ").append(message_legs);
  					sb.append("\n");
  					sb.append("FILTER: ").append(filter_field);
  					sb.append("\n");
  					throw new IllegalArgumentException("Failed to found correct order of legs: " + sb);
  				}
  
  				List<IMessage> new_legs = new ArrayList<>(message_legs.size());
  
  				for (int i = 0; i < order.length; i++) {
  					IMessage msg = message_legs.get(order[i]);
  					if (i < filter_legs.size()) {
  						IMessage fltr = filter_legs.get(i);
  						new_legs.add(reorder(msg, fltr, settings)); // recursion
  					} else {
  						new_legs.add(msg); // no recursion
  					}
  				}
  
  				message.addField(fieldName, new_legs);
  
  			}
  		}
  
  		return message;
  	}
focal_method.class_method_signature: LegReorder.reorder(IMessage message, IMessage filter, ComparatorSettings settings)
focal_method.full_signature: public static IMessage reorder(IMessage message, IMessage filter, ComparatorSettings settings)
focal_method.identifier: reorder
focal_method.invocations: debug debug debug getFieldNames getField getField size size findPermute append append append append append append append size get size get add reorder add addField
focal_method.modifiers: public static
focal_method.parameters: (IMessage message, IMessage filter, ComparatorSettings settings)
focal_method.return: IMessage
focal_method.signature: IMessage reorder(IMessage message, IMessage filter, ComparatorSettings settings)