R/LithoStratigraphy.r

# Netherlands Biodiversity API
#
# Access to the digitised Natural History collection at the Naturalis Biodiversity Center
#
# OpenAPI spec version: v2
# Contact: support@naturalis.nl
# Generated by: https://github.com/swagger-api/swagger-codegen.git

#'
#' @docType class
#'
#' @format R6 class
#'
#' @usage
#' # LithoStratigraphy$new()
#'
#' @format
#' R6 class
#'
#' @title LithoStratigraphy Class
#'
#' @description
#' For more information on the NBA object model, please refer to the
#' official NBA documentation at
#' \href{https://docs.biodiversitydata.nl}{https://docs.biodiversitydata.nl} and
#' the NBA model and endpoints reference at
#' \href{https://docs.biodiversitydata.nl/endpoints-reference}{https://docs.biodiversitydata.nl/endpoints-reference}.
#'
#' @details Model class for LithoStratigraphy objects.
#'
#'
#' @field qualifier  character
#'
#' @field preferredFlag  logical
#'
#' @field member2  character
#'
#' @field member  character
#'
#' @field informalName2  character
#'
#' @field informalName  character
#'
#' @field importedName2  character
#'
#' @field importedName1  character
#'
#' @field lithoIdentifier  character
#'
#' @field formation2  character
#'
#' @field formationGroup2  character
#'
#' @field formationGroup  character
#'
#' @field formation  character
#'
#' @field certainty2  character
#'
#' @field certainty  character
#'
#' @field bed2  character
#'
#' @field bed  character
#'
#'
#'
#' @section Methods:
#' \describe{
#'
#' \item{\code{$new()}}{
#'
#'   Constructor LithoStratigraphy object.
#'
#' }
#' \item{\code{$fromList(LithoStratigraphyList)}}{
#'
#'   Create LithoStratigraphy object from list.
#'
#' }
#'
#' \item{\code{$toList()}}{
#'
#'   Get list representation of LithoStratigraphy.
#'
#' }
#' \item{\code{fromJSONString(LithoStratigraphyJson)}}{
#'
#'   Create LithoStratigraphy object from JSON.
#'
#' }
#' \item{\code{toJSONString(pretty=TRUE)}}{
#'
#'   Get JSON representation of LithoStratigraphy.
#'
#' }
#' }
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
LithoStratigraphy <- R6::R6Class(
  "LithoStratigraphy",
  public = list(
    `qualifier` = NULL,
    `preferredFlag` = NULL,
    `member2` = NULL,
    `member` = NULL,
    `informalName2` = NULL,
    `informalName` = NULL,
    `importedName2` = NULL,
    `importedName1` = NULL,
    `lithoIdentifier` = NULL,
    `formation2` = NULL,
    `formationGroup2` = NULL,
    `formationGroup` = NULL,
    `formation` = NULL,
    `certainty2` = NULL,
    `certainty` = NULL,
    `bed2` = NULL,
    `bed` = NULL,
    initialize = function(
                              `qualifier`,
                              `preferredFlag`,
                              `member2`,
                              `member`,
                              `informalName2`,
                              `informalName`,
                              `importedName2`,
                              `importedName1`,
                              `lithoIdentifier`,
                              `formation2`,
                              `formationGroup2`,
                              `formationGroup`,
                              `formation`,
                              `certainty2`,
                              `certainty`,
                              `bed2`,
                              `bed`) {
      if (!missing(`qualifier`)) {
        stopifnot(
          is.character(`qualifier`),
          length(`qualifier`) == 1
        )
        self[["qualifier"]] <- `qualifier`
      }
      if (!missing(`preferredFlag`)) {
        self[["preferredFlag"]] <- `preferredFlag`
      }
      if (!missing(`member2`)) {
        stopifnot(
          is.character(`member2`),
          length(`member2`) == 1
        )
        self[["member2"]] <- `member2`
      }
      if (!missing(`member`)) {
        stopifnot(
          is.character(`member`),
          length(`member`) == 1
        )
        self[["member"]] <- `member`
      }
      if (!missing(`informalName2`)) {
        stopifnot(
          is.character(`informalName2`),
          length(`informalName2`) == 1
        )
        self[["informalName2"]] <- `informalName2`
      }
      if (!missing(`informalName`)) {
        stopifnot(
          is.character(`informalName`),
          length(`informalName`) == 1
        )
        self[["informalName"]] <- `informalName`
      }
      if (!missing(`importedName2`)) {
        stopifnot(
          is.character(`importedName2`),
          length(`importedName2`) == 1
        )
        self[["importedName2"]] <- `importedName2`
      }
      if (!missing(`importedName1`)) {
        stopifnot(
          is.character(`importedName1`),
          length(`importedName1`) == 1
        )
        self[["importedName1"]] <- `importedName1`
      }
      if (!missing(`lithoIdentifier`)) {
        stopifnot(
          is.character(`lithoIdentifier`),
          length(`lithoIdentifier`) == 1
        )
        self[["lithoIdentifier"]] <- `lithoIdentifier`
      }
      if (!missing(`formation2`)) {
        stopifnot(
          is.character(`formation2`),
          length(`formation2`) == 1
        )
        self[["formation2"]] <- `formation2`
      }
      if (!missing(`formationGroup2`)) {
        stopifnot(
          is.character(`formationGroup2`),
          length(`formationGroup2`) == 1
        )
        self[["formationGroup2"]] <- `formationGroup2`
      }
      if (!missing(`formationGroup`)) {
        stopifnot(
          is.character(`formationGroup`),
          length(`formationGroup`) == 1
        )
        self[["formationGroup"]] <- `formationGroup`
      }
      if (!missing(`formation`)) {
        stopifnot(
          is.character(`formation`),
          length(`formation`) == 1
        )
        self[["formation"]] <- `formation`
      }
      if (!missing(`certainty2`)) {
        stopifnot(
          is.character(`certainty2`),
          length(`certainty2`) == 1
        )
        self[["certainty2"]] <- `certainty2`
      }
      if (!missing(`certainty`)) {
        stopifnot(
          is.character(`certainty`),
          length(`certainty`) == 1
        )
        self[["certainty"]] <- `certainty`
      }
      if (!missing(`bed2`)) {
        stopifnot(
          is.character(`bed2`),
          length(`bed2`) == 1
        )
        self[["bed2"]] <- `bed2`
      }
      if (!missing(`bed`)) {
        stopifnot(
          is.character(`bed`),
          length(`bed`) == 1
        )
        self[["bed"]] <- `bed`
      }
    },
    toList = function() {
      LithoStratigraphyList <- list()
      if (!is.null(self[["qualifier"]])) {
        LithoStratigraphyList[["qualifier"]] <-
          self[["qualifier"]]
      }
      if (!is.null(self[["preferredFlag"]])) {
        LithoStratigraphyList[["preferredFlag"]] <-
          self[["preferredFlag"]]
      }
      if (!is.null(self[["member2"]])) {
        LithoStratigraphyList[["member2"]] <-
          self[["member2"]]
      }
      if (!is.null(self[["member"]])) {
        LithoStratigraphyList[["member"]] <-
          self[["member"]]
      }
      if (!is.null(self[["informalName2"]])) {
        LithoStratigraphyList[["informalName2"]] <-
          self[["informalName2"]]
      }
      if (!is.null(self[["informalName"]])) {
        LithoStratigraphyList[["informalName"]] <-
          self[["informalName"]]
      }
      if (!is.null(self[["importedName2"]])) {
        LithoStratigraphyList[["importedName2"]] <-
          self[["importedName2"]]
      }
      if (!is.null(self[["importedName1"]])) {
        LithoStratigraphyList[["importedName1"]] <-
          self[["importedName1"]]
      }
      if (!is.null(self[["lithoIdentifier"]])) {
        LithoStratigraphyList[["lithoIdentifier"]] <-
          self[["lithoIdentifier"]]
      }
      if (!is.null(self[["formation2"]])) {
        LithoStratigraphyList[["formation2"]] <-
          self[["formation2"]]
      }
      if (!is.null(self[["formationGroup2"]])) {
        LithoStratigraphyList[["formationGroup2"]] <-
          self[["formationGroup2"]]
      }
      if (!is.null(self[["formationGroup"]])) {
        LithoStratigraphyList[["formationGroup"]] <-
          self[["formationGroup"]]
      }
      if (!is.null(self[["formation"]])) {
        LithoStratigraphyList[["formation"]] <-
          self[["formation"]]
      }
      if (!is.null(self[["certainty2"]])) {
        LithoStratigraphyList[["certainty2"]] <-
          self[["certainty2"]]
      }
      if (!is.null(self[["certainty"]])) {
        LithoStratigraphyList[["certainty"]] <-
          self[["certainty"]]
      }
      if (!is.null(self[["bed2"]])) {
        LithoStratigraphyList[["bed2"]] <-
          self[["bed2"]]
      }
      if (!is.null(self[["bed"]])) {
        LithoStratigraphyList[["bed"]] <-
          self[["bed"]]
      }
      ## omit empty nested lists in returned list
      LithoStratigraphyList[vapply(
        LithoStratigraphyList,
        length,
        FUN.VALUE = integer(1)
      ) > 0]
    },
    fromList = function(LithoStratigraphyList,
                            typeMapping = NULL) {
      self[["qualifier"]] <-
        LithoStratigraphyList[["qualifier"]]
      self[["preferredFlag"]] <-
        LithoStratigraphyList[["preferredFlag"]]
      self[["member2"]] <-
        LithoStratigraphyList[["member2"]]
      self[["member"]] <-
        LithoStratigraphyList[["member"]]
      self[["informalName2"]] <-
        LithoStratigraphyList[["informalName2"]]
      self[["informalName"]] <-
        LithoStratigraphyList[["informalName"]]
      self[["importedName2"]] <-
        LithoStratigraphyList[["importedName2"]]
      self[["importedName1"]] <-
        LithoStratigraphyList[["importedName1"]]
      self[["lithoIdentifier"]] <-
        LithoStratigraphyList[["lithoIdentifier"]]
      self[["formation2"]] <-
        LithoStratigraphyList[["formation2"]]
      self[["formationGroup2"]] <-
        LithoStratigraphyList[["formationGroup2"]]
      self[["formationGroup"]] <-
        LithoStratigraphyList[["formationGroup"]]
      self[["formation"]] <-
        LithoStratigraphyList[["formation"]]
      self[["certainty2"]] <-
        LithoStratigraphyList[["certainty2"]]
      self[["certainty"]] <-
        LithoStratigraphyList[["certainty"]]
      self[["bed2"]] <-
        LithoStratigraphyList[["bed2"]]
      self[["bed"]] <-
        LithoStratigraphyList[["bed"]]
      invisible(self)
    },
    toJSONString = function(pretty = TRUE) {
      jsonlite::toJSON(
        self$toList(),
        simplifyVector = TRUE,
        auto_unbox = TRUE,
        pretty = pretty
      )
    },
    fromJSONString = function(LithoStratigraphyJson,
                                  typeMapping = NULL) {
      LithoStratigraphyList <- jsonlite::fromJSON(
        LithoStratigraphyJson,
        simplifyVector = FALSE
      )
      self <- self$fromList(LithoStratigraphyList)
      invisible(self)
    },
    print = function(...) {
      ## print class name
      cat("<LithoStratigraphy>\n")
      ## print all members with values
      cat("Fields:\n")
      if (typeof(self$qualifier) == "environment") {
        cat("\tqualifier:\tobject of class", paste0("<", class(self$qualifier)[1], ">"), "\n")
      }
      else if (typeof(self$qualifier) == "list") {
        cat("\tqualifier:\tlist of length", length(self$qualifier), "\n")
      }
      else {
        cat("\tqualifier:\t", self$qualifier, "\n")
      }
      if (typeof(self$preferredFlag) == "environment") {
        cat("\tpreferredFlag:\tobject of class", paste0("<", class(self$preferredFlag)[1], ">"), "\n")
      }
      else if (typeof(self$preferredFlag) == "list") {
        cat("\tpreferredFlag:\tlist of length", length(self$preferredFlag), "\n")
      }
      else {
        cat("\tpreferredFlag:\t", self$preferredFlag, "\n")
      }
      if (typeof(self$member2) == "environment") {
        cat("\tmember2:\tobject of class", paste0("<", class(self$member2)[1], ">"), "\n")
      }
      else if (typeof(self$member2) == "list") {
        cat("\tmember2:\tlist of length", length(self$member2), "\n")
      }
      else {
        cat("\tmember2:\t", self$member2, "\n")
      }
      if (typeof(self$member) == "environment") {
        cat("\tmember:\tobject of class", paste0("<", class(self$member)[1], ">"), "\n")
      }
      else if (typeof(self$member) == "list") {
        cat("\tmember:\tlist of length", length(self$member), "\n")
      }
      else {
        cat("\tmember:\t", self$member, "\n")
      }
      if (typeof(self$informalName2) == "environment") {
        cat("\tinformalName2:\tobject of class", paste0("<", class(self$informalName2)[1], ">"), "\n")
      }
      else if (typeof(self$informalName2) == "list") {
        cat("\tinformalName2:\tlist of length", length(self$informalName2), "\n")
      }
      else {
        cat("\tinformalName2:\t", self$informalName2, "\n")
      }
      if (typeof(self$informalName) == "environment") {
        cat("\tinformalName:\tobject of class", paste0("<", class(self$informalName)[1], ">"), "\n")
      }
      else if (typeof(self$informalName) == "list") {
        cat("\tinformalName:\tlist of length", length(self$informalName), "\n")
      }
      else {
        cat("\tinformalName:\t", self$informalName, "\n")
      }
      if (typeof(self$importedName2) == "environment") {
        cat("\timportedName2:\tobject of class", paste0("<", class(self$importedName2)[1], ">"), "\n")
      }
      else if (typeof(self$importedName2) == "list") {
        cat("\timportedName2:\tlist of length", length(self$importedName2), "\n")
      }
      else {
        cat("\timportedName2:\t", self$importedName2, "\n")
      }
      if (typeof(self$importedName1) == "environment") {
        cat("\timportedName1:\tobject of class", paste0("<", class(self$importedName1)[1], ">"), "\n")
      }
      else if (typeof(self$importedName1) == "list") {
        cat("\timportedName1:\tlist of length", length(self$importedName1), "\n")
      }
      else {
        cat("\timportedName1:\t", self$importedName1, "\n")
      }
      if (typeof(self$lithoIdentifier) == "environment") {
        cat("\tlithoIdentifier:\tobject of class", paste0("<", class(self$lithoIdentifier)[1], ">"), "\n")
      }
      else if (typeof(self$lithoIdentifier) == "list") {
        cat("\tlithoIdentifier:\tlist of length", length(self$lithoIdentifier), "\n")
      }
      else {
        cat("\tlithoIdentifier:\t", self$lithoIdentifier, "\n")
      }
      if (typeof(self$formation2) == "environment") {
        cat("\tformation2:\tobject of class", paste0("<", class(self$formation2)[1], ">"), "\n")
      }
      else if (typeof(self$formation2) == "list") {
        cat("\tformation2:\tlist of length", length(self$formation2), "\n")
      }
      else {
        cat("\tformation2:\t", self$formation2, "\n")
      }
      if (typeof(self$formationGroup2) == "environment") {
        cat("\tformationGroup2:\tobject of class", paste0("<", class(self$formationGroup2)[1], ">"), "\n")
      }
      else if (typeof(self$formationGroup2) == "list") {
        cat("\tformationGroup2:\tlist of length", length(self$formationGroup2), "\n")
      }
      else {
        cat("\tformationGroup2:\t", self$formationGroup2, "\n")
      }
      if (typeof(self$formationGroup) == "environment") {
        cat("\tformationGroup:\tobject of class", paste0("<", class(self$formationGroup)[1], ">"), "\n")
      }
      else if (typeof(self$formationGroup) == "list") {
        cat("\tformationGroup:\tlist of length", length(self$formationGroup), "\n")
      }
      else {
        cat("\tformationGroup:\t", self$formationGroup, "\n")
      }
      if (typeof(self$formation) == "environment") {
        cat("\tformation:\tobject of class", paste0("<", class(self$formation)[1], ">"), "\n")
      }
      else if (typeof(self$formation) == "list") {
        cat("\tformation:\tlist of length", length(self$formation), "\n")
      }
      else {
        cat("\tformation:\t", self$formation, "\n")
      }
      if (typeof(self$certainty2) == "environment") {
        cat("\tcertainty2:\tobject of class", paste0("<", class(self$certainty2)[1], ">"), "\n")
      }
      else if (typeof(self$certainty2) == "list") {
        cat("\tcertainty2:\tlist of length", length(self$certainty2), "\n")
      }
      else {
        cat("\tcertainty2:\t", self$certainty2, "\n")
      }
      if (typeof(self$certainty) == "environment") {
        cat("\tcertainty:\tobject of class", paste0("<", class(self$certainty)[1], ">"), "\n")
      }
      else if (typeof(self$certainty) == "list") {
        cat("\tcertainty:\tlist of length", length(self$certainty), "\n")
      }
      else {
        cat("\tcertainty:\t", self$certainty, "\n")
      }
      if (typeof(self$bed2) == "environment") {
        cat("\tbed2:\tobject of class", paste0("<", class(self$bed2)[1], ">"), "\n")
      }
      else if (typeof(self$bed2) == "list") {
        cat("\tbed2:\tlist of length", length(self$bed2), "\n")
      }
      else {
        cat("\tbed2:\t", self$bed2, "\n")
      }
      if (typeof(self$bed) == "environment") {
        cat("\tbed:\tobject of class", paste0("<", class(self$bed)[1], ">"), "\n")
      }
      else if (typeof(self$bed) == "list") {
        cat("\tbed:\tlist of length", length(self$bed), "\n")
      }
      else {
        cat("\tbed:\t", self$bed, "\n")
      }
      ## print all methods
      cat("Methods:\n")
      cat("\tfromJSONString\n")
      cat("\ttoJSONString\n")
      cat("\tfromList\n")
      cat("\ttoList\n")
      cat("\tprint\n")
      invisible(self)
    }
  )
)
naturalis/nbaR documentation built on Nov. 12, 2023, 4:47 p.m.