001package io.ebeaninternal.dbmigration.ddlgeneration.platform.util; 002 003import java.util.ArrayList; 004import java.util.Collections; 005import java.util.List; 006 007/** 008 * Set of columns making up a particular index (column order is important). 009 */ 010public class IndexColumns { 011 012 List<String> columns = new ArrayList<>(4); 013 014 /** 015 * Construct representing as a single column index. 016 */ 017 public IndexColumns(String column) { 018 columns.add(column); 019 } 020 021 /** 022 * Construct representing index. 023 */ 024 public IndexColumns(String[] columnNames) { 025 Collections.addAll(columns, columnNames); 026 } 027 028 /** 029 * Return true if this index matches (same single column). 030 */ 031 public boolean isMatch(String singleColumn) { 032 return columns.size() == 1 && columns.get(0).equals(singleColumn); 033 } 034 035 /** 036 * Return true if this index matches (same single column). 037 */ 038 public boolean isMatch(List<String> columnNames) { 039 if (columns.size() != columnNames.size()) { 040 return false; 041 } 042 for (int i = 0; i < columns.size(); i++) { 043 if (!columns.get(i).equals(columnNames.get(i))) { 044 return false; 045 } 046 } 047 return true; 048 } 049 050 /** 051 * Return true if this index matches (same columns same order). 052 */ 053 public boolean isMatch(IndexColumns other) { 054 return columns.equals(other.columns); 055 } 056 057 /** 058 * Add a unique index based on the single column. 059 */ 060 protected void add(String column) { 061 columns.add(column); 062 } 063 064}