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

co.cask.wrangler.api.parser.TokenDefinition Maven / Gradle / Ivy

There is a newer version: 3.2.2
Show newest version
/*
 * Copyright © 2017 Cask Data, Inc.
 *
 * 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 co.cask.wrangler.api.parser;

import co.cask.wrangler.api.annotations.PublicEvolving;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.io.Serializable;

/**
 * The TokenDefinition class represents a definition of token as specified
 * by the user while defining a directive usage. All definitions of a token are represented
 * by a instance of this class.
 *
 * The definition are constant (immutable) and they cannot be changed once defined.
 * For example :
 * 
 *   TokenDefinition token = new TokenDefintion("column", TokenType.COLUMN_NAME, null, 0, Optional.FALSE);
 * 
 *
 * 

The class TokenDefinition includes methods for retrieveing different members of * like name of the token, type of the token, label associated with token, whether it's optional or not * and the ordinal number of the token in the TokenGroup.

* *

As this class is immutable, the constructor requires all the member variables to be presnted * for an instance of this object to be created.

*/ @PublicEvolving public final class TokenDefinition implements Serializable { private final int ordinal; private final boolean optional; private final String name; private final TokenType type; private final String label; public TokenDefinition(String name, TokenType type, String label, int ordinal, boolean optional) { this.name = name; this.type = type; this.label = label; this.ordinal = ordinal; this.optional = optional; } /** * @return Label associated with the token. Label provides a way to override the usage description * for this TokenDefinition. If a label is not provided, then this return null. */ public String label() { return label; } /** * @return Returns the oridinal number of this TokenDefinition within * the TokenGroup, */ public int ordinal() { return ordinal; } /** * @return true, if this TokenDefinition is optional, false otherwise. */ public boolean optional() { return optional; } /** * @return Name of this TokenDefinition */ public String name() { return name; } /** * @return Returns the type of this TokenDefinition. */ public TokenType type() { return type; } /** * Returns the JsonElement of this object TokenDefinition. * @return An instance of JsonElement representing TokenDefinition * this object. */ public JsonElement toJson() { JsonObject object = new JsonObject(); object.addProperty("name", name); object.addProperty("type", type.name()); object.addProperty("ordinal", ordinal); object.addProperty("optional", optional); object.addProperty("label", label); return object; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy