CSegmentId

A Segment is a group of Nodes with the same ID. The SegmentId has its own class CSegmentId , which is derived from the IId.

Empty SegmentId

There is a public EMPTY field, which is an invalid SegmentId .

Constructors

The default constructor creates an invalid SegmentID .

public CSegmentId();

A SegmentId can be made from a normal ID.

public CSegmentId(@NotNull final IId aId);

Probably the most used is the constructor, which takes a string.

public CSegmentId(@NotNull final String aId);

Another constructor converts a UUID into an ID.

public CSegmentId(@NotNull final UUID aId);

Getter

There is a getter for the ID:

@NotNull
public IId getId();

Valid and Invalid

This method returns true if the passed SegmentId is not null and not invalid.

public boolean isValid();
public static boolean isValid(@Nullable final CSegmentId aSegmentId);

This method returns true if the passed SegmentId is null or invalid.

public static boolean isEmpty(@Nullable final CSegmentId aSegmentId);

If a null value is passed, this static method returns EMPTY, otherwise the passed value.

public boolean isEmpty();
public static CSegmentId getNonNullSegmentId(@Nullable final CSegmentId aSegmentId);

Comparison

This static method compares two SegmentIds considering null values.

public static boolean equals(@Nullable final CSegmentId aSegmentId1,
                             @Nullable final CSegmentId aSegmentId2);

CSegmentId implements the Comparable interface:

public int compareTo(@NotNull final CSegmentId aOther);

Lokale SegmentId

This static method returns the local SegmentId that is the SegmentId of the own Segment.

@NotNull
public static CSegmentId getLocal();

There is a static method that checks if a given SegmentId belongs to its own Segment. A null value or an invalid value is assumed to be local.

public static boolean isLocal(@Nullable final CSegmentId aSegmentId);

Stream I/O

A static method writes a SegmentId to a DataOutput stream.

public static void toStream(@NotNull final DataOutput aStream,
                            @Nullable final CSegmentId aSegmentId) throws IOException;

This static method reads a SegmentId from a DataInput stream.

@Nullable
public static CSegmentId fromStream(@NotNull final DataInput aStream) throws IOException;

String I/O

Beside the toString() method there is also a valueToString() method, which in contrast to the first one stores a SegmentId in a string in such a way that it can be read out again.

public static String valueToString(@Nullable final CSegmentId aValue);

Notes

CSegmentId supports the equals() and hashCode() methods.

nyssr.net - Innovative Distributed System