001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.core.model; 007 008import edu.umd.cs.findbugs.annotations.NonNull; 009 010/** 011 * Represents a flag instance within a field or assembly definition. 012 * <p> 013 * A flag instance references a flag definition and specifies how that flag is 014 * used within its containing definition, including whether the flag is 015 * required. 016 */ 017public interface IFlagInstance extends IFlag, IValuedInstance, IInstanceAbsolute { 018 019 /** 020 * The default value for whether a flag is required. 021 */ 022 boolean DEFAULT_FLAG_REQUIRED = false; 023 024 /** 025 * Retrieves the parent container that contains this flag instance. 026 * 027 * @return the parent model definition 028 */ 029 @Override 030 IModelDefinition getParentContainer(); 031 032 /** 033 * Retrieves the flag definition referenced by this instance. 034 * 035 * @return the flag definition 036 */ 037 @Override 038 IFlagDefinition getDefinition(); 039 040 @Override 041 default IModelDefinition getContainingDefinition() { 042 return getParentContainer(); 043 } 044 045 /** 046 * Determines if a flag value is required to be provided. 047 * 048 * @return {@code true} if a value is required, or {@code false} otherwise 049 * @see #DEFAULT_FLAG_REQUIRED 050 */ 051 default boolean isRequired() { 052 return DEFAULT_FLAG_REQUIRED; 053 } 054 055 /** 056 * A visitor callback. 057 * 058 * @param <CONTEXT> 059 * the type of the context parameter 060 * @param <RESULT> 061 * the type of the visitor result 062 * @param visitor 063 * the calling visitor 064 * @param context 065 * a parameter used to pass contextual information between visitors 066 * @return the visitor result 067 */ 068 @Override 069 default <CONTEXT, RESULT> RESULT accept(@NonNull IModelElementVisitor<CONTEXT, RESULT> visitor, CONTEXT context) { 070 return visitor.visitFlagInstance(this, context); 071 } 072}