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

com.joyzl.EnumCodeText Maven / Gradle / Ivy

The newest version!
/*-
 * www.joyzl.net
 * 中翌智联(重庆)科技有限公司
 * Copyright © JOY-Links Company. All rights reserved.
 */
package com.joyzl;

/**
 * 枚举自定义代码和文本
 * 
 * @author ZhangXi 2020年6月6日
 */
public interface EnumCodeText extends EnumCode, EnumText {

	/**
	 * 根据聚合值获取枚举字符串(逗号分隔)
	 * 
	 * @param  实现{@link EnumCodeText}接口的枚举实例
	 * @param clazz
	 * @param code
	 * @return 实例 / null
	 */
	static  String stringOf(Class clazz, int code) {
		StringBuilder builder = new StringBuilder();
		final T[] items = clazz.getEnumConstants();
		for (int index = 0; index < items.length; index++) {
			if ((items[index].code() & code) != 0) {
				if (builder.length() > 0) {
					builder.append(',');
				}
				builder.append(items[index].text());
			}
		}
		return builder.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy