Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/InterModuleComm/InterModuleComm/src/InterModuleComm/HelloMessage.java

Diff revisions: vs.
  @@ -1,81 +1,82 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package InterModuleComm;
3 -
4 - import org.litesoft.commonfoundation.typeutils.*;
5 -
6 - public final class HelloMessage implements Message {
7 - public static final String PREFIX =
8 - Constants.PROTOCOL_PREFIX + ModuleMsgLifecycleForm.Hello + Constants.NV_SEP;
9 - private String mFromType;
10 - private String mId;
11 -
12 - protected HelloMessage( String pFromType, String pId ) {
13 - mFromType = pFromType;
14 - mId = pId;
15 - }
16 -
17 - @Override
18 - public String toString() {
19 - return getHeader();
20 - }
21 -
22 - public String ToSendText() {
23 - return getHeader() + "\n";
24 - }
25 -
26 - public String getFromType() {
27 - return mFromType;
28 - }
29 -
30 - public String getId() {
31 - return mId;
32 - }
33 -
34 - public String getHeader() {
35 - return PREFIX + getFromType() + Constants.SPECIAL_ID_SEP + getId();
36 - }
37 -
38 - public static class Builder {
39 - private String mFromType;
40 - private String mId;
41 -
42 - public static Builder FromHeader( String pHeader ) {
43 - if ( (pHeader != null) && pHeader.startsWith( PREFIX ) ) {
44 - String zRest = Strings.trimLeadingSpaces( pHeader.substring( PREFIX.length() ) );
45 - int zSepAt = zRest.indexOf( Constants.SPECIAL_ID_SEP );
46 - if ( zSepAt != -1 ) {
47 - String zFromType = zRest.substring( 0, zSepAt ).trim();
48 - String zId = zRest.substring( zSepAt + 1 ).trim();
49 - return FromParams( zFromType, zId );
50 - }
51 - }
52 - return null;
53 - }
54 -
55 - private Builder( String pFromType, String pId ) {
56 - mFromType = pFromType;
57 - mId = pId;
58 - }
59 -
60 - public static Builder FromParams( String pFromType, String pId ) {
61 - pFromType = Strings.noEmpty( pFromType );
62 - pId = Strings.noEmpty( pId );
63 - if ( Strings.isAsciiIdentifier( pFromType ) && Strings.isNoSpaceAscii( pId ) ) {
64 - return new Builder( pFromType, pId );
65 - }
66 - return null;
67 - }
68 -
69 - public HelloMessage ToMsg() {
70 - return new HelloMessage( mFromType, mId );
71 - }
72 -
73 - public String getFromType() {
74 - return mFromType;
75 - }
76 -
77 - public String getId() {
78 - return mId;
79 - }
80 - }
81 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package InterModuleComm;
3 +
4 + import org.litesoft.commonfoundation.base.*;
5 + import org.litesoft.commonfoundation.typeutils.*;
6 +
7 + public final class HelloMessage implements Message {
8 + public static final String PREFIX =
9 + Constants.PROTOCOL_PREFIX + ModuleMsgLifecycleForm.Hello + Constants.NV_SEP;
10 + private String mFromType;
11 + private String mId;
12 +
13 + protected HelloMessage( String pFromType, String pId ) {
14 + mFromType = pFromType;
15 + mId = pId;
16 + }
17 +
18 + @Override
19 + public String toString() {
20 + return getHeader();
21 + }
22 +
23 + public String ToSendText() {
24 + return getHeader() + "\n";
25 + }
26 +
27 + public String getFromType() {
28 + return mFromType;
29 + }
30 +
31 + public String getId() {
32 + return mId;
33 + }
34 +
35 + public String getHeader() {
36 + return PREFIX + getFromType() + Constants.SPECIAL_ID_SEP + getId();
37 + }
38 +
39 + public static class Builder {
40 + private String mFromType;
41 + private String mId;
42 +
43 + public static Builder FromHeader( String pHeader ) {
44 + if ( (pHeader != null) && pHeader.startsWith( PREFIX ) ) {
45 + String zRest = Strings.trimLeadingSpaces( pHeader.substring( PREFIX.length() ) );
46 + int zSepAt = zRest.indexOf( Constants.SPECIAL_ID_SEP );
47 + if ( zSepAt != -1 ) {
48 + String zFromType = zRest.substring( 0, zSepAt ).trim();
49 + String zId = zRest.substring( zSepAt + 1 ).trim();
50 + return FromParams( zFromType, zId );
51 + }
52 + }
53 + return null;
54 + }
55 +
56 + private Builder( String pFromType, String pId ) {
57 + mFromType = pFromType;
58 + mId = pId;
59 + }
60 +
61 + public static Builder FromParams( String pFromType, String pId ) {
62 + pFromType = ConstrainTo.significantOrNull( pFromType );
63 + pId = ConstrainTo.significantOrNull( pId );
64 + if ( Strings.isAsciiIdentifier( pFromType ) && Strings.isNoSpaceAscii( pId ) ) {
65 + return new Builder( pFromType, pId );
66 + }
67 + return null;
68 + }
69 +
70 + public HelloMessage ToMsg() {
71 + return new HelloMessage( mFromType, mId );
72 + }
73 +
74 + public String getFromType() {
75 + return mFromType;
76 + }
77 +
78 + public String getId() {
79 + return mId;
80 + }
81 + }
82 + }