package mil.nga.geopackage.extension.related.dublin;

import mil.nga.geopackage.user.UserColumn;
import mil.nga.geopackage.user.UserCoreRow;
import mil.nga.geopackage.user.UserTable;

/**
 * Dublin Core Metadata Initiative
 * 
 * @author osbornb
 * @since 3.0.1
 */
public class DublinCoreMetadata {

	/**
	 * Check if the table has a column for the Dublin Core Type term
	 * 
	 * @param table
	 *            user table
	 * @param type
	 *            Dublin Core Type
	 * @return true if has column
	 */
	public static boolean hasColumn(UserTable<?> table, DublinCoreType type) {

		boolean hasColumn = table.hasColumn(type.getName());

		if (!hasColumn) {
			for (String synonym : type.getSynonyms()) {
				hasColumn = table.hasColumn(synonym);
				if (hasColumn) {
					break;
				}
			}
		}

		return hasColumn;
	}

	/**
	 * Check if the row has a column for the Dublin Core Type term
	 * 
	 * @param row
	 *            user row
	 * @param type
	 *            Dublin Core Type
	 * @return true if has column
	 */
	public static boolean hasColumn(UserCoreRow<?, ?> row, DublinCoreType type) {
		return hasColumn(row.getTable(), type);
	}

	/**
	 * Get the column from the table for the Dublin Core Type term
	 * 
	 * @param table
	 *            user table
	 * @param type
	 *            Dublin Core Type
	 * @return column
	 */
	public static <T extends UserColumn> T getColumn(UserTable<T> table,
			DublinCoreType type) {

		T column = null;

		if (table.hasColumn(type.getName())) {
			column = table.getColumn(type.getName());
		} else {
			for (String synonym : type.getSynonyms()) {
				if (table.hasColumn(synonym)) {
					column = table.getColumn(synonym);
					break;
				}
			}
		}

		return column;
	}

	/**
	 * Get the column from the row for the Dublin Core Type term
	 * 
	 * @param row
	 *            user row
	 * @param type
	 *            Dublin Core Type
	 * @return column
	 */
	public static <T extends UserColumn> T getColumn(UserCoreRow<T, ?> row,
			DublinCoreType type) {
		return getColumn(row.getTable(), type);
	}

	/**
	 * Get the value from the row for the Dublin Core Type term
	 * 
	 * @param row
	 *            user row
	 * @param type
	 *            Dublin Core Type
	 * @return value
	 */
	public static Object getValue(UserCoreRow<?, ?> row, DublinCoreType type) {

		UserColumn column = getColumn(row, type);

		Object value = row.getValue(column.getIndex());

		return value;
	}

}

@@ -2412,10 +2412,393 @@
 ue;%0A%09%7D%0A%0A
+%09/**%0A%09 * Set the value in the row for the Dublin Core Type term%0A%09 * %0A%09 * @param row%0A%09 *            user row%0A%09 * @param type%0A%09 *            Dublin Core Type%0A%09 * @param value%0A%09 *            value%0A%09 */%0A%09public static void setValue(UserCoreRow%3C?, ?%3E row, DublinCoreType type,%0A%09%09%09Object value) %7B%0A%0A%09%09UserColumn column = getColumn(row, type);%0A%0A%09%09row.setValue(column.getIndex(), value);%0A%09%7D%0A%0A
 %7D%0A

set value method