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

com.blazebit.query.spi.DataFormat Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 * Copyright Blazebit
 */
package com.blazebit.query.spi;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

/**
 * An object that describes the data format of a type.
 *
 * @author Christian Beikov
 * @since 1.0.0
 */
public interface DataFormat {

	/**
	 * Returns the Java type for this format.
	 *
	 * @return the Java type for this format
	 */
	Type getType();

	/**
	 * Returns the fields encapsulated by this format.
	 *
	 * @return the fields encapsulated by this format
	 */
	List getFields();

	/**
	 * Returns whether this data format represents an enum.
	 *
	 * @return whether this data format represents an enum.
	 */
	default boolean isEnum() {
		return false;
	}

	/**
	 * Returns a new data format for the given type and fields.
	 *
	 * @param type The type
	 * @param fields The fields of the type
	 * @return the data format
	 */
	static DataFormat of(Type type, List fields) {
		return new DataFormat() {
			@Override
			public Type getType() {
				return type;
			}

			@Override
			public List getFields() {
				return fields;
			}
		};
	}

	/**
	 * Returns a new enum data format for the given type.
	 *
	 * @param type The enum type
	 * @return the data format
	 */
	static DataFormat enumType(Type type) {
		return new DataFormat() {
			@Override
			public Type getType() {
				return type;
			}

			@Override
			public List getFields() {
				return Collections.emptyList();
			}

			@Override
			public boolean isEnum() {
				return true;
			}
		};
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy