/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.model;
/**
* Defines a type to be used with a symbol table. A type definition contains a
* name, a data type and a description.
*
* @author Markus Kraetzig
*/
public final class JSCTypeDef {
public final String name;
public final JSCTypes type;
public final String description;
/**
* Creates a type definition with a name, a type and an optional
* description.
*
* @param name
* the name of this type
* @param type
* the data type
* @param description
* a description of the data that is stored under this type
* @throws IllegalArgumentException
* if (type == null) or if name is
* not valid or if description contains / * or * /
* @see com.jstatcom.model.JSCConstants#isValidName
*/
public JSCTypeDef(String name, JSCTypes type, String description) {
super();
JSCConstants.checkNameThrowEx(name);
if (type == null)
throw new IllegalArgumentException("Type was null");
if (description != null
&& (description.indexOf("/*") > -1 || description.indexOf("*/") > -1))
throw new IllegalArgumentException("Description \"" + description
+ "\" contains /* or */.");
this.name = name.toUpperCase();
this.type = type;
this.description = (description == null) ? "" : description.trim();
}
/**
* Creates a type definition with a name, a type and no description.
*
* @param name
* the name of this type
* @param type
* the data type
* @throws IllegalArgumentException
* if (type == null) or if name is
* not valid
* @see com.jstatcom.model.JSCConstants#isValidName
*/
public JSCTypeDef(String name, JSCTypes type) {
this(name, type, null);
}
/**
* Gets string representation of this object.
*
* @return a string
*/
public final String toString() {
String des = description;
if (description.length() > 40)
des = des.substring(0, 40) + "...";
return "";
}
/**
* Gets an empty instance of this typedef with the same name.
*
* @return empty JSCData object of type
*/
public JSCData getInstance() {
return type.valueOfEmpty(name);
}
}
Ads help maintain this website.