wherehows-dao/src/main/java/wherehows/dao/table/FieldDetailDao.java
public List<List<DictFieldDetail>> diffFieldList(List<DictFieldDetail> originalFields, int datasetId,
      DatasetSchema schema) {
    List<DictFieldDetail> updatedFields = new ArrayList<>(); // updated fields
    List<DictFieldDetail> removedFields = new ArrayList<>(originalFields);  // removed fields

    if (schema.fieldSchema == null || schema.fieldSchema.size() == 0) {
      return Arrays.asList(updatedFields, removedFields);
    }

    int fieldCount = 0;
    for (FieldSchema fs : schema.fieldSchema) {
      fieldCount++;

      String fieldPath = fs.fieldPath.toString();
      // find and update existing field
      for (DictFieldDetail field : originalFields) {
        if (fieldPath.equalsIgnoreCase(field.getFieldName())) {
          fillFieldDetailByFieldSchema(fs, field);

          updatedFields.add(field);
          break;
        }
      }

      // if field not exist, add a new field
      if (updatedFields.size() < fieldCount) {
        DictFieldDetail field = new DictFieldDetail();
        field.setDatasetId(datasetId);
        fillFieldDetailByFieldSchema(fs, field);

        updatedFields.add(field);
      }
    }

    removedFields.removeAll(updatedFields);

    return Arrays.asList(updatedFields, removedFields);
  }
/**
   * Find the updated list of fields, and the list of fields that don't exist anymore.
   * If new fields are empty, all existing fields will be removed.
   * @param originalFields List<DictFieldDetail>
   * @param datasetId int
   * @param schema DatasetSchema
   * @return [ updated list , removed list of fields]
   */
Find the updated list of fields, and the list of fields that don't exist anymore.
If new fields are empty, all existing fields will be removed.
@param originalFields List
@param datasetId int
@param schema DatasetSchema
@return [ updated list , removed list of fields]
Find the updated list of fields and the list of fields that don ' t exist anymore . If new fields are empty all existing fields will be removed . @param originalFields List @param datasetId int @param schema DatasetSchema @return [ updated list removed list of fields ]
public List<List<DictFieldDetail>> diffFieldList(List<DictFieldDetail> originalFields, int datasetId,
      DatasetSchema schema) {
    List<DictFieldDetail> updatedFields = new ArrayList<>(); 
    List<DictFieldDetail> removedFields = new ArrayList<>(originalFields);  
    if (schema.fieldSchema == null || schema.fieldSchema.size() == 0) {
      return Arrays.asList(updatedFields, removedFields);
    }
    int fieldCount = 0;
    for (FieldSchema fs : schema.fieldSchema) {
      fieldCount++;
      String fieldPath = fs.fieldPath.toString();
      for (DictFieldDetail field : originalFields) {
        if (fieldPath.equalsIgnoreCase(field.getFieldName())) {
          fillFieldDetailByFieldSchema(fs, field);
          updatedFields.add(field);
          break;
        }
      }
      if (updatedFields.size() < fieldCount) {
        DictFieldDetail field = new DictFieldDetail();
        field.setDatasetId(datasetId);
        fillFieldDetailByFieldSchema(fs, field);
        updatedFields.add(field);
      }
    }
    removedFields.removeAll(updatedFields);
    return Arrays.asList(updatedFields, removedFields);
  }
public List < List < DictFieldDetail > > diffFieldList ( List < DictFieldDetail > originalFields , int datasetId , DatasetSchema schema ) { List < DictFieldDetail > updatedFields = new ArrayList < > ( ) ; List < DictFieldDetail > removedFields = new ArrayList < > ( originalFields ) ; if ( schema . fieldSchema == null || schema . fieldSchema . size ( ) == 0 ) { return Arrays . asList ( updatedFields , removedFields ) ; } int fieldCount = 0 ; for ( FieldSchema fs : schema . fieldSchema ) { fieldCount ++ ; String fieldPath = fs . fieldPath . toString ( ) ; for ( DictFieldDetail field : originalFields ) { if ( fieldPath . equalsIgnoreCase ( field . getFieldName ( ) ) ) { fillFieldDetailByFieldSchema ( fs , field ) ; updatedFields . add ( field ) ; break ; } } if ( updatedFields . size ( ) < fieldCount ) { DictFieldDetail field = new DictFieldDetail ( ) ; field . setDatasetId ( datasetId ) ; fillFieldDetailByFieldSchema ( fs , field ) ; updatedFields . add ( field ) ; } } removedFields . removeAll ( updatedFields ) ; return Arrays . asList ( updatedFields , removedFields ) ; }
Find the updated list of fields, and the list of fields that don't exist anymore.
Find the updated list of fields and the list of fields that don ' t exist anymore .
// updated fields // removed fields // find and update existing field // if field not exist, add a new field