/** * Parse a {@code UniqueId} from the supplied string representation. * * @return a properly constructed {@code UniqueId} * @throws JUnitException if the string cannot be parsed */ UniqueId parse(String source) throws JUnitException { String[] parts = source.split(String.valueOf(this.segmentDelimiter)); List<Segment> segments = Arrays.stream(parts).map(this::createSegment).collect(toList()); return new UniqueId(this, segments); }
/** * Construct a new {@code UniqueId} by appending a new {@link Segment} to * the end of this {@code UniqueId}. * * <p>This {@code UniqueId} will not be modified. * * @param segment the segment to be appended; never {@code null} * * @since 1.1 */ @API(status = STABLE, since = "1.1") public final UniqueId append(Segment segment) { Preconditions.notNull(segment, "segment must not be null"); List<Segment> baseSegments = new ArrayList<>(this.segments); baseSegments.add(segment); return new UniqueId(this.uniqueIdFormat, baseSegments); }
/** * Create a root unique ID from the supplied {@code segmentType} and * {@code value} using the default format. * * @param segmentType the segment type; never {@code null} or blank * @param value the value; never {@code null} or blank * @see #forEngine(String) */ public static UniqueId root(String segmentType, String value) { return new UniqueId(UniqueIdFormat.getDefault(), new Segment(segmentType, value)); }