/** * Ctor that creates a tracestate object from a parent one */ public Tracestate(Tracestate parent, String key, String value) { if (key == null) { throw new IllegalArgumentException("key is null"); } if (!KEY_VALIDATION_RE.matcher(key).find()) { throw new IllegalArgumentException("invalid key format"); } if (value == null) { throw new IllegalArgumentException("value is null"); } if (!VALUE_VALIDATION_RE.matcher(value).find()) { throw new IllegalArgumentException("invalid value format"); } internalList.put(key, value); if (parent != null) { for (String k : parent.internalList.keySet()) { internalList.put(k, parent.internalList.get(k)); } internalList.put(key, value); } internalString = toInternalString(); }
/** * Ctor that creates tracestate object from given value */ public Tracestate(String input) { if (input == null) { throw new IllegalArgumentException("input is null"); } String[] values = DELIMITER_FORMAT_RE.split(input); for (String item : values) { Matcher m = MEMBER_FORMAT_RE.matcher(item); if (!m.find()) { throw new IllegalArgumentException(String.format("invalid string %s in tracestate", item)); } String key = m.group(1); String value = m.group(3); if (internalList.get(key) != null) { throw new IllegalArgumentException(String.format("duplicated keys %s in tracestate", key)); } internalList.put(key, value); } if (internalList.size() > MAX_KEY_VALUE_PAIRS) { throw new IllegalArgumentException(String.format("cannot have more than %d key-value pairs", MAX_KEY_VALUE_PAIRS)); } internalString = toInternalString(); }
/** * Ctor that creates a tracestate object from a parent one */ public Tracestate(Tracestate parent, String key, String value) { if (key == null) { throw new IllegalArgumentException("key is null"); } if (!KEY_VALIDATION_RE.matcher(key).find()) { throw new IllegalArgumentException("invalid key format"); } if (value == null) { throw new IllegalArgumentException("value is null"); } if (!VALUE_VALIDATION_RE.matcher(value).find()) { throw new IllegalArgumentException("invalid value format"); } internalList.put(key, value); if (parent != null) { for (String k : parent.internalList.keySet()) { internalList.put(k, parent.internalList.get(k)); } internalList.put(key, value); } internalString = toInternalString(); }
/** * Ctor that creates tracestate object from given value */ public Tracestate(String input) { if (input == null) { throw new IllegalArgumentException("input is null"); } String[] values = DELIMITER_FORMAT_RE.split(input); for (String item : values) { Matcher m = MEMBER_FORMAT_RE.matcher(item); if (!m.find()) { throw new IllegalArgumentException(String.format("invalid string %s in tracestate", item)); } String key = m.group(1); String value = m.group(3); if (internalList.get(key) != null) { throw new IllegalArgumentException(String.format("duplicated keys %s in tracestate", key)); } internalList.put(key, value); } if (internalList.size() > MAX_KEY_VALUE_PAIRS) { throw new IllegalArgumentException(String.format("cannot have more than %d key-value pairs", MAX_KEY_VALUE_PAIRS)); } internalString = toInternalString(); }