All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.moandjiezana.toml.BooleanValueReaderWriter Maven / Gradle / Ivy

There is a newer version: 0.7.2
Show newest version
package com.moandjiezana.toml;

import java.util.concurrent.atomic.AtomicInteger;


class BooleanValueReaderWriter implements ValueReader, ValueWriter {
  
  static final BooleanValueReaderWriter BOOLEAN_VALUE_READER_WRITER = new BooleanValueReaderWriter(); 

  @Override
  public boolean canRead(String s) {
    return s.startsWith("true") || s.startsWith("false");
  }

  @Override
  public Object read(String s, AtomicInteger index, Context context) {
    s = s.substring(index.get());
    Boolean b = s.startsWith("true") ? Boolean.TRUE : Boolean.FALSE;
    
    int endIndex = b == Boolean.TRUE ? 4 : 5;
    
    index.addAndGet(endIndex - 1);
    
    return b;
  }

  @Override
  public boolean canWrite(Object value) {
    return Boolean.class.isInstance(value);
  }

  @Override
  public void write(Object value, WriterContext context) {
    context.write(value.toString());
  }

  @Override
  public boolean isPrimitiveType() {
    return true;
  }

  private BooleanValueReaderWriter() {}

  @Override
  public String toString() {
    return "boolean";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy