|
| 1 | +/** |
| 2 | + * ************************************************************************* |
| 3 | + * Copyright (C) 2015 EPAM |
| 4 | +
|
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + * ************************************************************************* |
| 18 | + */ |
| 19 | + |
| 20 | +package com.epam.parso; |
| 21 | + |
| 22 | +/** |
| 23 | + * A class to store column format metadata. |
| 24 | + */ |
| 25 | +public class ColumnFormat { |
| 26 | + /** |
| 27 | + * The column format name. |
| 28 | + */ |
| 29 | + private String name; |
| 30 | + /** |
| 31 | + * The column format width. |
| 32 | + */ |
| 33 | + private int width; |
| 34 | + /** |
| 35 | + * The column format precision. |
| 36 | + */ |
| 37 | + private int precision; |
| 38 | + |
| 39 | + /** |
| 40 | + * The constructor that defines all parameters of the ColumnFormat class. |
| 41 | + * |
| 42 | + * @param name - column format name. |
| 43 | + * @param width - olumn format width. |
| 44 | + * @param precision - column format precision. |
| 45 | + */ |
| 46 | + public ColumnFormat(String name, int width, int precision) { |
| 47 | + this.name = name; |
| 48 | + this.width = width; |
| 49 | + this.precision = precision; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * The constructor that defines name of the ColumnFormat class. |
| 54 | + * |
| 55 | + * @param name - column format name. |
| 56 | + */ |
| 57 | + public ColumnFormat(String name) { |
| 58 | + this.name = name; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * The function to get {@link ColumnFormat#name}. |
| 63 | + * |
| 64 | + * @return the string that contains the column format name. |
| 65 | + */ |
| 66 | + public String getName() { |
| 67 | + return name; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * The function to get {@link ColumnFormat#width}. |
| 72 | + * |
| 73 | + * @return the number that contains the column format width. |
| 74 | + */ |
| 75 | + public int getWidth() { |
| 76 | + return width; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * The function to get {@link ColumnFormat#precision}. |
| 81 | + * |
| 82 | + * @return the number that contains the column format precision. |
| 83 | + */ |
| 84 | + public int getPrecision() { |
| 85 | + return precision; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns true if there are no information about column format, otherwise false. |
| 90 | + * |
| 91 | + * @return true if column name is empty and width and precision are 0, otherwise false. |
| 92 | + */ |
| 93 | + public boolean isEmpty() { |
| 94 | + return name.isEmpty() && width == 0 && precision == 0; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * The function to ColumnFormat class string representation. |
| 99 | + * |
| 100 | + * @return string representation of the column format. |
| 101 | + */ |
| 102 | + @Override |
| 103 | + public String toString() { |
| 104 | + return isEmpty() ? "" : name + (width != 0 ? width : "") + "." + (precision != 0 ? precision : ""); |
| 105 | + } |
| 106 | +} |
0 commit comments