diff --git a/src/core/dimension.ts b/src/core/dimension.ts index 202d5b62522dbffcb2df9de165a8b659ee6f3bf2..37161a4f5f320f70fdc921e46cbcd14907672c9b 100644 --- a/src/core/dimension.ts +++ b/src/core/dimension.ts @@ -19,7 +19,7 @@ */ import { RelationType, DataType } from "../common/types"; -import { EnumType } from "./enumType"; +import { EnumHandler } from "../util/enumHandler"; /** Parameters used to create a Dimension object. */ export interface DimensionOptions { @@ -96,14 +96,14 @@ export class Dimension { if (this.relation === RelationType.NONE) { return { name: this.name, - dataType: (this.dataType !== DataType.NONE) ? EnumType.stringfyDataType(this.dataType) : this.enumType , + dataType: EnumHandler.selectDataType(this.dataType, this.enumType), description: this.description }; } else { return { name: this.name, - dataType: (this.dataType !== DataType.NONE) ? EnumType.stringfyDataType(this.dataType) : this.enumType , + dataType: EnumHandler.selectDataType(this.dataType, this.enumType), parent: this.parent.name, relation: Dimension.stringifyRelationType(this.relation), description: this.description diff --git a/src/core/source.ts b/src/core/source.ts index 7a04687fd169aff80a284e6bb84ea5fa2575962b..f9e112815937820e7d8c4f1d1736385cffeeb13d 100644 --- a/src/core/source.ts +++ b/src/core/source.ts @@ -20,6 +20,7 @@ import { EnumType } from "./enumType"; import { DataType } from "../common/types"; +import { EnumHandler } from "../util/enumHandler"; /** Attribute of a source. */ export interface Field { @@ -121,7 +122,7 @@ export class Source { return { name : i.name, description: i.description, - dataType: (i.dataType !== DataType.NONE) ? EnumType.stringfyDataType(i.dataType) : i.enumType + dataType: EnumHandler.selectDataType(i.dataType, i.enumType) }; }); return str; @@ -138,7 +139,7 @@ export class Source { name : i.name, description: i.description, dataType: EnumType.parseDataType(i.dataType), - enumType: (EnumType.parseDataType(i.dataType) === DataType.NONE) ? i.dataType : "" + enumType: EnumHandler.selectEnumType(i.dataType) }; }); return str; diff --git a/src/util/configParser.ts b/src/util/configParser.ts index 8dbf87f669a53d7062fb2ebabf75ed3c47041354..96aaf88e8388e8439311a9d172ed1424963f04eb 100644 --- a/src/util/configParser.ts +++ b/src/util/configParser.ts @@ -22,6 +22,7 @@ import { Metric, MetricOptions, MetricStrOptions } from "../core/metric"; import { Dimension, DimensionOptions, DimensionStrOptions } from "../core/dimension"; import { View, ViewOptions, LoadView } from "../core/view"; import { EnumType, EnumTypeOptions } from "../core/enumType"; +import { EnumHandler } from "./enumHandler"; import { RelationType, DataType } from "../common/types"; import { Opcode } from "../common/expression"; import { Filter } from "../core/filter"; @@ -334,7 +335,7 @@ export class ConfigParser { description: opts.description, parent: dims[i], relation: Dimension.parseRelationType(opts.relation), - enumType: (EnumType.parseDataType(opts.dataType) === DataType.NONE) ? opts.dataType : "" + enumType: EnumHandler.selectEnumType(opts.dataType) }; } } @@ -347,7 +348,7 @@ export class ConfigParser { description: opts.description, parent: null, relation: RelationType.NONE, - enumType: (EnumType.parseDataType(opts.dataType) === DataType.NONE) ? opts.dataType : "" + enumType: EnumHandler.selectEnumType(opts.dataType) }; } diff --git a/src/util/enumHandler.ts b/src/util/enumHandler.ts new file mode 100644 index 0000000000000000000000000000000000000000..53ccae23f8bbb537c8374869ebf697482242d769 --- /dev/null +++ b/src/util/enumHandler.ts @@ -0,0 +1,52 @@ +import { DataType } from "../common/types"; + +/* + * Copyright (C) 2018 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana + * + * This file is part of blendb. + * + * blendb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * blendb 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with blendb. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * Enum's handler. Manage changes between + * string and enumtype. + */ + +import { EnumType } from "../core/enumType"; + +/** + * Enum's handler. Manage changes between + * string , datatype and enumtype. + */ +export class EnumHandler { + + /** + * Checks if it's a valid datatype, otherwise will be an enumtype + * @param dt datatype to compare, used as return if comparation succeed + * @param en enumtype as return if comparation fails + */ + public static selectDataType(dt: DataType , en: string): string{ + return (dt !== DataType.NONE) ? EnumType.stringfyDataType(dt) : en; + } + + /** + * Checks if it's a valid datatype, otherwise return an empity string + * @param data datatype to compare, used as return if comparation succeed + */ + public static selectEnumType(data: string): string{ + return (EnumType.parseDataType(data) === DataType.NONE) ? data : ""; + } +}