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

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

The newest version!
package com.aliyun.datahub.client.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashMap;
import java.util.Map;

public class RecordEntry extends RecordRespMeta {
    @JsonIgnore
    private int attrSize;

    @JsonProperty("ShardId")
    private String shardId;

    @JsonProperty("PartitionKey")
    private String partitionKey;

    @JsonProperty("HashKey")
    private String hashKey;

    @JsonProperty("Attributes")
    private Map attributes;

    @JsonProperty("Data")
    private RecordData recordData;

    private RecordKey key;

    public void addAttribute(String key, String value) {
        if (attributes == null) {
            attributes = new HashMap<>();
        }

        boolean exist = attributes.containsKey(key);
        String oldValue = attributes.put(key, value);
        if (!exist) {
            attrSize += key.length();
            attrSize += (value == null ? 0 : value.length());
        } else {
            attrSize -= (oldValue == null ? 0 : oldValue.length());
            attrSize += (value == null ? 0 : value.length());
        }
    }

    public String getShardId() {
        return shardId;
    }

    public void setShardId(String shardId) {
        this.shardId = shardId;
    }

    public String getPartitionKey() {
        return partitionKey;
    }

    public void setPartitionKey(String partitionKey) {
        this.partitionKey = partitionKey;
    }

    public String getHashKey() {
        return hashKey;
    }

    public void setHashKey(String hashKey) {
        this.hashKey = hashKey;
    }

    public Map getAttributes() {
        return attributes;
    }

    public void setAttributes(Map attributes) {
        this.attributes = attributes;
    }

    public RecordData getRecordData() {
        return recordData;
    }

    public void setRecordData(RecordData recordData) {
        this.recordData = recordData;
    }

    public RecordKey getKey() {
        return key;
    }

    public void setKey(RecordKey key) {
        this.key = key;
    }

    @JsonIgnore
    public int getEstimateSize() {
        return attrSize + recordData.getDataSize();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy