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

br.com.objectos.flat.ColumnParseError Maven / Gradle / Ivy

There is a newer version: 0.5.2
Show newest version
/*
 * Copyright 2015 Objectos, Fábrica de Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package br.com.objectos.flat;

import java.util.Optional;

/**
 * @author [email protected] (Marcio Endo)
 */
abstract class ColumnParseError extends Token implements ParseError {

  private final Line line;

  ColumnParseError(Column column, Line line, String text) {
    super(column, text);
    this.line = line;
  }

  static ColumnParseError exception(Column column, Line line, String text, Exception e) {
    return new ParseException(column, line, text, e);
  }

  static ColumnParseError notEqual(Column column, Line line, String text, String expected) {
    return new NotEqual(column, line, text, expected);
  }

  @Override
  public Line line() {
    return line;
  }

  @Override
  public boolean valid() {
    return false;
  }

  @Override
  public Optional parseError() {
    return Optional.of(this);
  }

  private static class NotEqual extends ColumnParseError {

    private final String expected;

    public NotEqual(Column column, Line line, String text, String expected) {
      super(column, line, text);
      this.expected = expected;
    }

    @Override
    public String message() {
      return String.format("Expected '%s' but found '%s'", expected, text());
    }

  }

  private static class ParseException extends ColumnParseError {

    private final Exception e;

    public ParseException(Column column, Line line, String text, Exception e) {
      super(column, line, text);
      this.e = e;
    }

    @Override
    public String message() {
      return e.getMessage();
    }

  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy