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

com.toshiba.mwcloud.gs.IndexInfo Maven / Gradle / Ivy

/*
   Copyright (c) 2017 TOSHIBA Digital Solutions Corporation

   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 com.toshiba.mwcloud.gs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.toshiba.mwcloud.gs.common.GSErrorCode;

/**
 * shows the index setting
 *
 * 

The notation of column names and the validity of column numbers * are not inspected.

* * @since 3.5 */ public class IndexInfo { private IndexType type; private String name; private List columnList = Collections.emptyList(); private List columnNameList = Collections.emptyList(); /** * Create empty index information. * *

Creates index information with no index type, index name, * column number, column name.

*/ public IndexInfo() { } /** * Inherits the specified content and creates new index information. * * @param info Index information * * @throws NullPointerException when {@code null} is specified as argument */ public IndexInfo(IndexInfo info) { final boolean sameClass; try { sameClass = (info.getClass() == IndexInfo.class); } catch (NullPointerException e) { throw GSErrorCode.checkNullParameter(info, "info", e); } if (sameClass) { type = info.type; name = info.name; columnList = info.columnList; columnNameList = info.columnNameList; } else { setType(info.getType()); setName(info.getName()); setColumnList(info.getColumnList()); setColumnNameList(info.getColumnNameList()); } } /** * If necessary, create index information by specifying the column name and index type. * * @param columnName Column name. If not specified {@code null} * @param type Index type. If not specified {@code null} */ public static IndexInfo createByColumn(String columnName, IndexType type) { final IndexInfo info = new IndexInfo(); info.setColumnName(columnName); info.setType(type); return info; } /** * Creates index information by specifying the list of column names and index * type as needed. * * @param columnNames List of column names. Length {@code 0} is allowed, but * {@code null} cannot be specified * @param type Index type. If not specified {@code null} * * @throws NullPointerException If {@code null} is specified in the argument * {@code columnNames} * * @since 4.3 */ public static IndexInfo createByColumnList( List columnNames, IndexType type) { final IndexInfo info = new IndexInfo(); info.setColumnNameList(columnNames); info.setType(type); return info; } /** * Creates index information by specifying the index name and index type as necessary. * * @param name Index name. If not specified {@code null} * @param type Index type. If not specified {@code null} */ public static IndexInfo createByName(String name, IndexType type) { final IndexInfo info = new IndexInfo(); info.setName(name); info.setType(type); return info; } /** * Returns the index type. * * @return Index type. If not set {@code null} */ public IndexType getType() { return type; } /** * Sets the index type. * * @param type Index type. Not set when {@code null} is specified. */ public void setType(IndexType type) { this.type = type; } /** * Returns the index name. * * @return index name. If not set {@code null} */ public String getName() { return name; } /** * Sets the index name. * * @param name index name. Not set when {@code null} is specified. */ public void setName(String name) { this.name = name; } /** * Returns the column number of the single column corresponding to the index. * * @return column number. If not set {@code null} * * @throws IllegalStateException If a list of column numbers or a list of * column names is set for the composite index */ public Integer getColumn() { if (columnList.size() > 1 || columnNameList.size() > 1) { throw new IllegalStateException( "This method cannot be used for composite index"); } else if (columnList.isEmpty()) { return null; } else { return columnList.get(0); } } /** * Sets the list of the column numbers consisting of a single column corresponding to * the index. * * @param column Column number. Not set when {@code null} is specified. */ public void setColumn(Integer column) { if (column == null) { this.columnList = Collections.emptyList(); } else { this.columnList = Collections.singletonList(column); } } /** * Returns the column name of the single column corresponding to the index. * * @return column name. If not set {@code null} * * @throws IllegalStateException If a list of column numbers or a list of column * names is set for the composite index */ public String getColumnName() { if (columnList.size() > 1 || columnNameList.size() > 1) { throw new IllegalStateException( "This method cannot be used for composite index"); } else if (columnNameList.isEmpty()) { return null; } else { return columnNameList.get(0); } } /** * Sets the list of the column names consisting of a single column * corresponding to the index. * * @param columnName column name. Not set when {@code null} is specified. */ public void setColumnName(String columnName) { if (columnName == null) { this.columnNameList = Collections.emptyList(); } else { this.columnNameList = Collections.singletonList(columnName); } } /** * Sets the list of the column numbers of any number of columns corresponding * to the index. * * @param columns List of column numbers. Length {@code 0} is allowed, but * {@code null} cannot be specified * * @throws NullPointerException If {@code null} is specified in the argument * {@code columns} * * @since 4.3 */ public void setColumnList(List columns) { final List dest; try { dest = Collections.unmodifiableList( new ArrayList(columns)); } catch (NullPointerException e) { throw GSErrorCode.checkNullParameter(columns, "columns", e); } this.columnList = checkListElements(dest, "columns"); } /** * Returns the list of the column numbers of any number of columns corresponding * to the index. * * @return List of column numbers. If not set, a list of length {@code 0} * * @since 4.3 */ public List getColumnList() { return columnList; } /** * Sets the list of the column names of any number of columns * corresponding to the index. * * @param columnNames List of column names. Length {@code 0} is allowed, but * {@code null} cannot be specified * * @throws NullPointerException If {@code null} is specified in the argument * {@code columnNames} * * @since 4.3 */ public void setColumnNameList(List columnNames) { final List dest; try { dest = Collections.unmodifiableList( new ArrayList(columnNames)); } catch (NullPointerException e) { throw GSErrorCode.checkNullParameter(columnNames, "columnNames", e); } this.columnNameList = checkListElements(dest, "columnNames"); } /** * Returns the list of the column names of any number of columns corresponding * to the index. * * @return List of column names. If not set, a list of length 0 * * @since 4.3 */ public List getColumnNameList() { return columnNameList; } private static List checkListElements(List list, String listName) { for (T elem : list) { GSErrorCode.checkNullParameter( elem, "element of " + listName, null); } return list; } static IndexInfo toImmutable(IndexInfo base) { if (base instanceof Immutable) { return (Immutable) base; } return new Immutable(base); } private static class Immutable extends IndexInfo { private Immutable(IndexInfo info) { super(info); } @Override public void setType(IndexType type) { throw new UnsupportedOperationException(); } @Override public void setName(String name) { throw new UnsupportedOperationException(); } @Override public void setColumn(Integer column) { throw new UnsupportedOperationException(); } @Override public void setColumnName(String columnName) { throw new UnsupportedOperationException(); } @Override public void setColumnList(List columns) { throw new UnsupportedOperationException(); } @Override public void setColumnNameList(List columnNames) { throw new UnsupportedOperationException(); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy