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

com.paritytrading.philadelphia.client.message.Field Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package com.paritytrading.philadelphia.client.message;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Field {

    private static final Pattern PATTERN = Pattern.compile("(?\\d{1,5})=(?.+)");

    private int    tag;
    private String value;

    public Field(int tag, String value) {
        this.tag   = tag;
        this.value = value;
    }

    public static Field get(String s) {
        Matcher matcher = PATTERN.matcher(s);
        if (!matcher.matches())
            throw new IllegalArgumentException();

        int    tag   = Integer.parseInt(matcher.group("tag"));
        String value = matcher.group("value");

        return new Field(tag, value);
    }

    public int getTag() {
        return tag;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return String.format("%d=%s", tag, value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy