Uploaded image for project: 'Talend Component Kit'
  1. Talend Component Kit
  2. TCOMP-2085

Add extras manipulations on Record BuilderImpl

Apply templateInsert Lucidchart Diagram
    XMLWordPrintable

Details

    • All
    • GreenHopper Ranking:
      0|i2d3zf:
    • 9223372036854775807
    • Small

    Description

      Extend the TCOMP-2008 feature with extra methods on

      Schema.Builder

      /**
        * Same as {@link Builder#build()} but entries order is specified by {@code order}. This takes precedence on any
        * previous defined order with builder and may void it.
        *
        * @param order the wanted order for entries.
        * @return the described schema.
        */
       default Schema build(Comparator<Entry> order) {
           throw new UnsupportedOperationException("#build(EntriesOrder) is not implemented");
      }
      

      Record.Builder:

      /**
       * Mark that next entry created {@code withXXXX()} will be before {@code entryName} in schema order.
       *
       * @see
       * <ul>
       * <li>{@link Schema#naturalOrder()}</li>
       * <li>{@link Schema#getEntriesOrdered()}</li>
       * <li>{@link Schema#getEntriesOrdered(Comparator)}</li>
       * </ul>
       *
       * @param entryName target entry name. This entry <b>must</b> exist!
       *
       * @return this Builder
       */
      Builder before(String entryName);
      
      /**
       * Mark that next entry created {@code withXXXX()} will be after {@code entryName} in schema order.
       *
       * @see
       * <ul>
       * <li>{@link Schema#naturalOrder()}</li>
       * <li>{@link Schema#getEntriesOrdered()}</li>
       * <li>{@link Schema#getEntriesOrdered(Comparator)}</li>
       * </ul>
       *
       * @param entryName target entry name. This entry <b>must</b> exist!
       *
       * @return this Builder
       */
      Builder after(String entryName);
      

      Here's same code example for manipulations:

      @Test
      void recordAfterBefore() {
          final Record record = new RecordImpl.BuilderImpl()
                  .withString("_10", "10")
                  .withString("_20", "20")
                  .withString("_30", "30")
                  .withString("_40", "40")
                  .withString("_50", "50")
                  .before("_10")
                  .withString("_00", "0")
                  .after("_20")
                  .withString("_25", "25")
                  .after("_50")
                  .withString("_55", "55")
                  .before("_55")
                  .withString("_53", "53")
                  .build();
          assertEquals("_00,_10,_20,_25,_30,_40,_50,_53,_55", getSchemaFields(record.getSchema()));
          assertEquals("_00,_10,_20,_25,_30,_40,_50,_53,_55", record.getSchema().naturalOrder().toFields());
          assertEquals("0,10,20,25,30,40,50,53,55", getRecordValues(record));
      }
      
      @Test
      void recordOrderingWithProvidedSchema() {
          final Schema schema = new RecordImpl.BuilderImpl()
                  .withString("_10", "10")
                  .withString("_20", "20")
                  .withString("_30", "30")
                  .withString("_40", "40")
                  .withString("_50", "50")
                  .withString("_00", "0")
                  .withString("_25", "25")
                  .withString("_55", "55")
                  .withString("_53", "53")
                  .build()
                  .getSchema();
          final EntriesOrder order = schema.naturalOrder()
                  .moveBefore("_10", "_00")
                  .moveAfter("_20", "_25")
                  .swap("_53", "_55");
          assertEquals("_00,_10,_20,_25,_30,_40,_50,_53,_55", order.toFields());
          final Record record = new RecordImpl.BuilderImpl(schema.toBuilder().build(order))
                  .withString("_10", "10")
                  .withString("_20", "20")
                  .withString("_30", "30")
                  .withString("_40", "40")
                  .withString("_50", "50")
                  .withString("_00", "0")
                  .withString("_25", "25")
                  .withString("_55", "55")
                  .before("_30")
                  .withString("_53", "53")
                  .build();
          assertTrue(RecordImpl.class.isInstance(record));
          assertEquals("_00,_10,_20,_25,_53,_30,_40,_50,_55", getSchemaFields(record.getSchema()));
          assertEquals("_00,_10,_20,_25,_53,_30,_40,_50,_55", record.getSchema().naturalOrder().toFields());
          assertEquals("0,10,20,25,53,30,40,50,55", getRecordValues(record));
      }
      

       

      Attachments

        Issue Links

          Activity

            People

              emmanuel_g emmanuel gallois
              emmanuel_g emmanuel gallois
              Christophe LeSaec, emmanuel gallois, Fabien Desiles
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: