This repository was archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Code
cezarmathe edited this page Jun 21, 2019
·
6 revisions
This is a Java Bean for a basic code.
- identifier the 4-character code identifier
- owner the owner of the code(user name, extracted by parsing, not by interacting with the database)
- passcode the passcode of this code(extracted by parsing, not by interacting with the database)
- name the name of this code(or description)
- url the base API URL for this code(for future requests or operations)
- publicStatus flag that describes whether the code is public or not(extracted by parsing, not by interacting with the database)
- createTime a timestamp that describes when this code was created
- updateTime a timestamp that describes when this codes was last updated
- toString() return the String version of this code, like the one used by parsing
- toJson() return the JSON representation of this Code
- fromJson() parse a JSON and return an appropriate Code
- getCodeType() get the CodeType of this Code
// Create a new Code instance
Code code = new Code();
// Assign field values
code.setIdentifier("aB12");
code.setOwner("examplename");
code.setPasscode("mY-_PasScode1213");
code.setName("An example code for the wiki");
code.setUrl("https://example.com");
code.setPublicStatus(true);
code.setCreateTime(new Instant(1561031256));
code.setUpdateTime(new Instant(1561031256));
// Get field values
code.getIdentifier(); // returns "aB12"
code.getCodeType(); // returns CodeType.PUBLIC_WITH_PASSCODECode code = new Code();
code.setIdentifier("aB12");
code.setOwner("examplename");
code.setPasscode("mY-_PasScode1213");
code.toString(); // returns <aB12@examplename!mY-_PasScode1213>// Create a new Code instance
Code code = new Code();
// Assign a few field values
code.setIdentifier("aB12");
code.setOwner("examplename");
code.setPasscode("mY-_PasScode1213");
code.toJson(); // returns the JSON from belowThe generated JSON:
{
"identifier": "aB12",
"owner": "examplename",
"passcode": "mY-_PasScode1213"
}The JSON used for parsing:
{
"identifier": "aB12",
"owner": "examplename",
"passcode": "mY-_PasScode1213"
}// Use the static fromJson() method to parse a JSON
Code code = Code.fromJson("the JSON from above ^");
// Get some field values
code.getIdentifier(); // returns "aB12"
code.getOwner(); // returns "examplename"
code.getPasscode(); // returns "mY-_PasScode1213"
code.getName(); // returns null// Create a new Code instance
Code code = new Code();
// Assign field values to see how the CodeType changes
code.setIdentifier("aB12");
code.getCodeType(); // returns CodeType.PRIVATE
code.setOwner("examplename");
code.getCodeType(); // returns CodeType.PUBLIC_NO_PASSCODE
code.setPasscode("mY-_PasScode1213");
code.getCodeType(); // returns CodeType.PUBLIC_WITH_PASSCODE