test_class.file: csv-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/csv/TestMultiBundleCSVFilter.java
test_class.identifier: TestMultiBundleCSVFilter
test_case.body: @Test
      public void testParse() {
          TestResourceStringData[] expectedFoods = {
                  new TestResourceStringData("apple", "Apple", 1),
                  new TestResourceStringData("orange", "Orange", 2)
          };
  
          TestResourceStringData[] expectedGreetings = {
                  new TestResourceStringData("msg_hello", "Hello", 1),
                  new TestResourceStringData("msg_bye", "Bye", 2)
          };
  
          Map<String, TestResourceStringData[]> expectedDataMap = new HashMap<>();
          expectedDataMap.put("foods", expectedFoods);
          expectedDataMap.put("greetings", expectedGreetings);
  
          MultiBundleResourceFilter filter = ResourceFilterFactory.getMultiBundleResourceFilter(MultiBundleCSVFilter.ID);
          try (InputStream inStream = this.getClass().getResourceAsStream("/test-multi.csv")) {
              Map<String, LanguageBundle> bundles = filter.parse(inStream, new FilterOptions(Locale.ENGLISH));
  
              assertEquals("Number of modules", expectedDataMap.size(), bundles.size());
  
              for (Entry<String, LanguageBundle> bundleEntry : bundles.entrySet()) {
                  String module = bundleEntry.getKey();
                  LanguageBundle bundle = bundleEntry.getValue();
  
                  TestResourceStringData[] expStrings = expectedDataMap.get(module);
                  assertNotNull("Module " + module, expStrings);
  
                  List<ResourceString> resStrings = bundle.getSortedResourceStrings();
                  assertEquals("Number of resource strings for module " + module, expStrings.length, resStrings.size());
  
                  int idx = 0;
                  for (ResourceString resString : resStrings) {
                      String key = resString.getKey();
                      String value = resString.getValue();
                      int seqNum = resString.getSequenceNumber();
  
                      TestResourceStringData expected = expStrings[idx++];
  
                      assertEquals("Resource key in module (" + module + ") at index " + idx, expected.key, key);
                      assertEquals("Resource value in module(" + module + ") at index " + idx, expected.value, value);
                      assertEquals("Resource sequence number in module(" + module + ") at index " + idx, expected.seq, seqNum);
                  }
              }
          } catch (IOException e) {
              fail(e.getMessage());
          } catch (ResourceFilterException e) {
              fail(e.getMessage());
          }
      }
test_case.class_method_signature: TestMultiBundleCSVFilter.testParse()
test_case.full_signature: @Test public void testParse()
test_case.identifier: testParse
test_case.invocations: put put getMultiBundleResourceFilter getResourceAsStream getClass parse assertEquals size size entrySet getKey getValue get assertNotNull getSortedResourceStrings assertEquals size getKey getValue getSequenceNumber assertEquals assertEquals assertEquals fail getMessage fail getMessage
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testParse()
focal_class.declarator: ID = "CSV-MULTI"
focal_class.modifier: public static final
focal_class.original_string: public static final String ID = "CSV-MULTI";
focal_class.type: String
focal_class.var_name: ID
focal_class.declarator: TYPE = Type.MULTI
focal_class.modifier: public static final
focal_class.original_string: public static final Type TYPE = Type.MULTI;
focal_class.type: Type
focal_class.var_name: TYPE
focal_class.file: csv-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/csv/MultiBundleCSVFilter.java
focal_class.identifier: MultiBundleCSVFilter
focal_class.class_method_signature: MultiBundleCSVFilter.parse(InputStream inStream, FilterOptions options)
focal_class.full_signature: @Override public Map<String, LanguageBundle> parse(InputStream inStream, FilterOptions options)
focal_class.identifier: parse
focal_class.modifiers: @Override public
focal_class.parameters: (InputStream inStream, FilterOptions options)
focal_class.return: Map<String, LanguageBundle>
focal_class.signature: Map<String, LanguageBundle> parse(InputStream inStream, FilterOptions options)
focal_class.class_method_signature: MultiBundleCSVFilter.write(OutputStream outStream, Map<String, LanguageBundle> languageBundles, FilterOptions options)
focal_class.full_signature: @Override public void write(OutputStream outStream, Map<String, LanguageBundle> languageBundles, FilterOptions options)
focal_class.identifier: write
focal_class.modifiers: @Override public
focal_class.parameters: (OutputStream outStream, Map<String, LanguageBundle> languageBundles, FilterOptions options)
focal_class.return: void
focal_class.signature: void write(OutputStream outStream, Map<String, LanguageBundle> languageBundles, FilterOptions options)
focal_class.class_method_signature: MultiBundleCSVFilter.merge(InputStream baseStream, OutputStream outStream, Map<String, LanguageBundle> languageBundles,
              FilterOptions options)
focal_class.full_signature: @Override public void merge(InputStream baseStream, OutputStream outStream, Map<String, LanguageBundle> languageBundles,
              FilterOptions options)
focal_class.identifier: merge
focal_class.modifiers: @Override public
focal_class.parameters: (InputStream baseStream, OutputStream outStream, Map<String, LanguageBundle> languageBundles,
              FilterOptions options)
focal_class.return: void
focal_class.signature: void merge(InputStream baseStream, OutputStream outStream, Map<String, LanguageBundle> languageBundles,
              FilterOptions options)
focal_class.superclass: extends MultiBundleResourceFilter
focal_method.body: @Override
      public Map<String, LanguageBundle> parse(InputStream inStream, FilterOptions options)
              throws IOException, ResourceFilterException {
          Map<String, LanguageBundleBuilder> builders = new HashMap<String, LanguageBundleBuilder>();
          CSVParser parser = CSVParser.parse(inStream, StandardCharsets.UTF_8,
                  CSVFormat.RFC4180.withHeader("module", "key", "value").withSkipHeaderRecord(true));
  
          for (CSVRecord record : parser) {
              String bundle = record.get(0);
              String key = record.get(1);
              String value = record.get(2);
  
              LanguageBundleBuilder bundleBuilder = builders.get(bundle);
              if (bundleBuilder == null) {
                  bundleBuilder = new LanguageBundleBuilder(true);
                  builders.put(bundle, bundleBuilder);
              }
              bundleBuilder.addResourceString(key, value);
          }
  
          Map<String, LanguageBundle> result = new TreeMap<String, LanguageBundle>();
          for (Entry<String, LanguageBundleBuilder> bundleEntry : builders.entrySet()) {
              String bundleName = bundleEntry.getKey();
              LanguageBundle bundleData = bundleEntry.getValue().build();
              result.put(bundleName, bundleData);
          }
  
          return result;
      }
focal_method.class_method_signature: MultiBundleCSVFilter.parse(InputStream inStream, FilterOptions options)
focal_method.full_signature: @Override public Map<String, LanguageBundle> parse(InputStream inStream, FilterOptions options)
focal_method.identifier: parse
focal_method.invocations: parse withSkipHeaderRecord withHeader get get get get put addResourceString entrySet getKey build getValue put
focal_method.modifiers: @Override public
focal_method.parameters: (InputStream inStream, FilterOptions options)
focal_method.return: Map<String, LanguageBundle>
focal_method.signature: Map<String, LanguageBundle> parse(InputStream inStream, FilterOptions options)