TemporalElementToCSV.java

  1. /*
  2.  * Copyright © 2014 - 2021 Leipzig University (Database Research Group)
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.gradoop.temporal.io.impl.csv.functions;

  17. import org.apache.flink.api.java.tuple.Tuple;
  18. import org.apache.flink.api.java.tuple.Tuple2;
  19. import org.gradoop.flink.io.impl.csv.functions.ElementToCSV;
  20. import org.gradoop.temporal.model.impl.pojo.TemporalElement;

  21. /**
  22.  * Base class to convert an element into a CSV representation.
  23.  *
  24.  * @param <E> The element type.
  25.  * @param <T> The output tuple type.
  26.  */
  27. abstract class TemporalElementToCSV<E extends TemporalElement, T extends Tuple> extends ElementToCSV<E, T> {

  28.   /**
  29.    * Returns a CSV string representation of the temporal attributes in format:
  30.    *
  31.    * {@code (tx-from,tx-to),(val-from,val-to)}
  32.    *
  33.    * @param transactionTime the transaction time
  34.    * @param validTime the valid time
  35.    * @return CSV string representation
  36.    */
  37.   String getTemporalDataString(Tuple2<Long, Long> transactionTime, Tuple2<Long, Long> validTime) {
  38.     return String.format("(%d,%d),(%d,%d)",
  39.       transactionTime.f0,
  40.       transactionTime.f1,
  41.       validTime.f0,
  42.       validTime.f1);
  43.   }
  44. }