001/* 002 * JDrupes Builder 003 * Copyright (C) 2025 Michael N. Lipp 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <https://www.gnu.org/licenses/>. 017 */ 018 019package org.jdrupes.builder.api; 020 021import java.lang.reflect.Type; 022 023/// Instances of this class define keys for a [Project]'s properties. 024/// See [CoreProperties] for examples. 025/// 026/// @param <T> the value's type 027/// 028public class PropertyKey<T> { 029 030 private final Type type; 031 private final T defaultValue; 032 033 /// Initializes a PropertyKey with the given default value. The 034 /// type information is obtained from the value. 035 /// 036 /// @param defaultValue the default value 037 /// 038 @SuppressWarnings("unchecked") 039 public PropertyKey(T defaultValue) { 040 this.defaultValue = defaultValue; 041 type = (Class<T>) defaultValue.getClass(); 042 } 043 044 /// Initializes a PropertyKey with the given type information. 045 /// The default value is set to `null`. 046 /// 047 /// @param type the type 048 /// 049 public PropertyKey(Type type) { 050 this.type = type; 051 defaultValue = null; 052 } 053 054 /// Returns the property's type. 055 /// 056 /// @return the type 057 /// 058 public Type type() { 059 return type; 060 } 061 062 /// Returns the property's default value. 063 /// 064 /// @return the default value 065 /// 066 public T defaultValue() { 067 return defaultValue; 068 } 069 070}