Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.
cezarmathe edited this page Jun 20, 2019 · 6 revisions

This is a Java Bean for a basic code.

Fields

  • 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

Methods

  • 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

Examples

Create a new Code, assign field values and get field values

// 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_PASSCODE

Convert a Code to String

Code code = new Code();

code.setIdentifier("aB12");
code.setOwner("examplename");
code.setPasscode("mY-_PasScode1213");

code.toString(); // returns <aB12@examplename!mY-_PasScode1213>

Create a JSON representation for a Code

Code code = new Code();

code.setIdentifier("aB12");
code.setOwner("examplename");
code.setPasscode("mY-_PasScode1213");

code.toJson(); // returns the JSON from below

The generated JSON:

{
  "identifier": "aB12",
  "owner": "examplename",
  "passcode": "mY-_PasScode1213"
}

Get a Code from a JSON String

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

Get the CodeType for a given Code

Code code = new Code();

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;

Clone this wiki locally