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

com.github.zthulj.zcopybook.model.ValueNode Maven / Gradle / Ivy

Go to download

Library helping to convert positionnal inputs (cobol) to json, using a copybook format

The newest version!
package com.github.zthulj.zcopybook.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.github.zthulj.zcopybook.factory.NodeFactory;
import com.github.zthulj.zcopybook.serializer.ValueNodeSerializer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@JsonSerialize(using = ValueNodeSerializer.class)
@Getter
@Setter
@EqualsAndHashCode(callSuper=true)
@ToString
public final class ValueNode extends Node {

	private static final long serialVersionUID = -3833993476849963456L;

	private T value;
    private final Coordinates coordinates;
    private final ValueType valueType;

    public enum ValueType{
        STRING, SIGNED_INT, SIGNED_FLOAT
    }

    public ValueNode(ParentNode parent,Coordinates coordinates, ValueType valueType){
        super(parent, false);
        this.coordinates = coordinates;
        this.valueType = valueType;
    }

    @Override
    public int copyInto(ParentNode destination, int cursorPosition, String name) {
        Coordinates nextCoords = calculateCoordinates(this, cursorPosition);
        ValueNode valueNode = NodeFactory.createValueNode(destination,nextCoords,this.valueType);
        destination.addChild(valueNode,name);
        cursorPosition += nextCoords.getSize();
        return cursorPosition;
    }

    private Coordinates calculateCoordinates(ValueNode value, int nextStart) {
        return Coordinates.create(nextStart, nextStart + value.getCoordinates().getSize());
    }

    @Override
    public List> getAllValueNodes() {
        return Collections.singletonList(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy