Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1034654 // PersistableOKOrError

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6597L/38K).

persistable sclass PersistableOKOrError<A> implements IF0<A> {
  A value;
  gettable PersistableThrowable error;
  
  *() {}
  *(A *value) {}
  *(bool dummy, PersistableThrowable *error) { assertNotNull(error); }
  
  bool ok aka isOK() { ret error == null; }
  
  toString {
    ret ok()
      ? /*"OK: " +*/ str(value)
      : "Error: " + str(error);
  }
  
  public A get() { ret !ok() ? null : value; }
  
  public A getMandatory() { if (!ok()) throw error.asRuntimeException(); ret value; }
  
  static <A> PersistableOKOrError<A> ok(A a) { ret new PersistableOKOrError(a); }
  static PersistableOKOrError error(PersistableThrowable error) { ret new PersistableOKOrError(false, error); }
}

Author comment

Began life as a copy of #1012580

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034654
Snippet name: PersistableOKOrError
Eternal ID of this version: #1034654/2
Text MD5: e969cd941218345afa4cc4bb9fbfcd61
Transpilation MD5: 5cea877cbd07cc7736102aebed167a73
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-28 20:37:06
Source code size: 716 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 68 / 126
Version history: 1 change(s)
Referenced in: [show references]