Code Monkey home page Code Monkey logo

yaml-base's Introduction

yaml-base

Build Status License: MIT Maven Central

Base classes for YAML implementation.

The specification of YAML is contained in a document entitled YAML Ain't Markup Language (YAML™) Version 1.2, and that document (in §1.3. Relation to JSON) states "YAML can … be viewed as a natural superset of JSON". Accordingly, each of the classes in this library derives from the equivalent class in the jsonutil library (and that library is a transitive dependency of this one). A tree of YAMLNode objects can therefore be navigated as if it were a tree of JSONValues.

Reference

YAMLNode

The root interface for all YAML nodes. It extends JSONValue, and it adds a single method:

  • String getTag(): return the tag associated with the node

Each of the implementing classes has a constructor that takes a tag in the form of a String, along with constructors that supply a default tag name (from the specification §10.3. Core Schema). The tag name is immutable and no setter is provided.

YAMLScalar

This is a marker interface, implemented by the implementation classes for the various forms of YAML scalar. It extends YAMLNode and adds no additional methods.

YAMLString

YAMLString extends JSONString and implements YAMLScalar. The JSONString.getValue() function returns the value.

Example:

        YAMLString yamlString = new YAMLString("Hello!");
        System.out.println(yamlString.getValue()); // prints Hello!

YAMLInt

YAMLInt extends JSONInteger and implements YAMLScalar. The JSONInteger.getValue() function returns the value.

Example:

        YAMLInt yamlInt = new YAMLInt(3 * 3 * 3);
        System.out.println(yamlInt.getValue()); // prints 27

YAMLLong

YAMLLong extends JSONLong and implements YAMLScalar. The YAMLLong.getValue() function returns the value.

Example:

        YAMLLong yamlLong = new YAMLLong(1234567812345678L);
        System.out.println(yamlLong.getValue()); // prints 1234567812345678

YAMLDecimal

YAMLDecimal extends JSONDecimal and implements YAMLScalar. The YAMLDecimal.getValue() function returns the value.

Example:

        YAMLDecimal yamlDecimal = new YAMLDecimal(new BigDecimal("123.45"));
        System.out.println(yamlDecimal.getValue()); // prints 123.45

YAMLBoolean

YAMLBoolean extends JSONBoolean and implements YAMLScalar. The YAMLBoolean.getValue() function returns the value.

Example:

        YAMLBoolean yamlBoolean = YAMLBoolean.TRUE;
        System.out.println(yamlBoolean.getValue()); // prints true

YAMLSequence

YAMLSequence extends JSONSequence<YAMLNode> and implements YAMLNode. JSONSequence<YAMLNode> implements List<YAMLNode>, so all of the functionality of the List interface is available to access the members of the sequence.

Example:

        YAMLSequence yamlSequence = new YAMLSequence(Arrays.asList(new YAMLString("Hello"), new YAMLString("World")));
        for (YAMLNode node : yamlSequence)
            System.out.println(node); // prints Hello (first time), World (second time)

YAMLMapping

YAMLMapping extends JSONMapping<YAMLNode> and implements YAMLNode. JSONMapping<YAMLNode> implements Map<String, YAMLNode>, so all of the functionality of the Map interface is available to access the members of the mapping.

Example:

        Map<String, YAMLNode> map = new HashMap<>();
        map.put("greeting", new YAMLString("Hello"));
        map.put("who", new YAMLString("World"));
        YAMLMapping yamlMapping = new YAMLMapping(map);
        System.out.println(yamlMapping.get("greeting")); // prints Hello
        System.out.println(yamlMapping.get("who")); // prints World

YAMLDocument

YAMLDocument is a container to hold the results of a YAML parse operation. It contains the root node of the parsed document, along with the version number from the %YAML directive (if provided).

Constructors:

  • YAMLDocument(YAMLNode rootNode, int majorVersion, int minorVersion)
  • YAMLDocument(YAMLNode rootNode) (defaults majorVersion to 1 and minorVersion to 2)

Functions:

  • YAMLNode getRootNode()
  • int getMajorVersion()
  • int getMinorVersion()

Dependency Specification

The latest version of the library is 1.3, and it may be obtained from the Maven Central repository.

Maven

    <dependency>
      <groupId>net.pwall.yaml</groupId>
      <artifactId>yaml-base</artifactId>
      <version>1.3</version>
    </dependency>

Gradle

    testImplementation 'net.pwall.yaml:yaml-base:1.3'

Gradle (kts)

    testImplementation("net.pwall.yaml:yaml-base:1.3")

Peter Wall

2023-07-10

yaml-base's People

Contributors

pwall567 avatar

Stargazers

Alex avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.