All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.datahub.client.model.RecordSchema Maven / Gradle / Ivy

There is a newer version: 2.25.6
Show newest version
package com.aliyun.datahub.client.model;

import com.aliyun.datahub.client.exception.InvalidParameterException;
import com.aliyun.datahub.client.impl.serializer.RecordSchemaDeserializer;
import com.aliyun.datahub.client.impl.serializer.RecordSchemaSerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@JsonSerialize(using = RecordSchemaSerializer.class)
@JsonDeserialize(using = RecordSchemaDeserializer.class)
public class RecordSchema {
    /** Schema contains a Field array, which you can treat as data Column */
    private List fieldList = new ArrayList<>();
    private Map fieldMap = new HashMap<>();

    public void addField(Field field) {
        if (field == null) {
            throw new InvalidParameterException("Field is null");
        }

        if (fieldMap.containsKey(field.getName())) {
            throw new InvalidParameterException("Filed already exists");
        }

        fieldMap.put(field.getName(), field);
        fieldList.add(field);
    }

    public Field getField(String name) {
        if (name == null) {
            throw new InvalidParameterException("Name is null");
        }

        return fieldMap.get(name.toLowerCase());
    }

    public Field getField(int idx) {
        if (idx < 0 || idx >= fieldList.size()) {
            throw new InvalidParameterException("idx out of range");
        }

        return fieldList.get(idx);
    }

    public int getFieldIndex(String name) {
        if (name == null) {
            throw new InvalidParameterException("Field name is null");
        }
        Field field = getField(name);
        return fieldList.indexOf(field);
    }

    public List getFields() {
        return fieldList;
    }

    public boolean containsField(String filedName) {
        return fieldMap.containsKey(filedName);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy