java enum 用法
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.annotations;
import org.hibernate.cache.spi.access.AccessType;
/**
* Cache concurrency strategy.
*
* @author Emmanuel Bernard
*/
public enum CacheConcurrencyStrategy {
/**
* Indicates no concurrency strategy should be applied.
*/
NONE( null ),
/**
* Indicates that read-only strategy should be applied.
*
* @see AccessType#READ_ONLY
*/
READ_ONLY( AccessType.READ_ONLY ),
/**
* Indicates that the non-strict read-write strategy should be applied.
*
* @see AccessType#NONSTRICT_READ_WRITE
*/
NONSTRICT_READ_WRITE( AccessType.NONSTRICT_READ_WRITE ),
/**
* Indicates that the read-write strategy should be applied.
*
* @see AccessType#READ_WRITE
*/
READ_WRITE( AccessType.READ_WRITE ),
/**
* Indicates that the transaction strategy should be applied.
*
* @see AccessType#TRANSACTIONAL
*/
TRANSACTIONAL( AccessType.TRANSACTIONAL );
private final AccessType accessType;
private CacheConcurrencyStrategy(AccessType accessType) {
this.accessType = accessType;
}
/**
* Get the AccessType corresponding to this concurrency strategy.
*
* @return The corresponding concurrency strategy. Note that this will return {@code null} for
* {@link #NONE}
*/
public AccessType toAccessType() {
return accessType;
}
/**
* Conversion from {@link AccessType} to {@link CacheConcurrencyStrategy}.
*
* @param accessType The access type to convert
*
* @return The corresponding enum value. {@link #NONE} is returned by default if unable to
* recognize {@code accessType} or if {@code accessType} is {@code null}.
*/
public static CacheConcurrencyStrategy fromAccessType(AccessType accessType) {
if ( null == accessType ) {
return NONE;
}
switch ( accessType ) {
case READ_ONLY: {
return READ_ONLY;
}
case READ_WRITE: {
return READ_WRITE;
}
case NONSTRICT_READ_WRITE: {
return NONSTRICT_READ_WRITE;
}
case TRANSACTIONAL: {
return TRANSACTIONAL;
}
default: {
return NONE;
}
}
}
/**
* Parse an external representation of a CacheConcurrencyStrategy value.
*
* @param name The external representation
*
* @return The corresponding enum value, or {@code null} if not match was found.
*/
public static CacheConcurrencyStrategy parse(String name) {
if ( READ_ONLY.isMatch( name ) ) {
return READ_ONLY;
}
else if ( READ_WRITE.isMatch( name ) ) {
return READ_WRITE;
}
else if ( NONSTRICT_READ_WRITE.isMatch( name ) ) {
return NONSTRICT_READ_WRITE;
}
else if ( TRANSACTIONAL.isMatch( name ) ) {
return TRANSACTIONAL;
}
else if ( NONE.isMatch( name ) ) {
return NONE;
}
else {
return null;
}
}
private boolean isMatch(String name) {
return ( accessType != null && accessType.getExternalName().equalsIgnoreCase( name ) )
|| name().equalsIgnoreCase( name );
}
}
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache.spi.access;
/**
* The types of access strategies available.
*
* @author Steve Ebersole
*/
public enum AccessType {
/**
* Read-only access. Data may be added and removed, but not mutated.
*/
READ_ONLY( "read-only" ),
/**
* Read and write access (strict). Data may be added, removed and mutated.
*/
READ_WRITE( "read-write" ),
/**
* Read and write access (non-strict). Data may be added, removed and mutated. The non-strictness comes from
* the fact that locks are not maintained as tightly as in {@link #READ_WRITE}, which leads to better throughput
* but may also lead to inconsistencies.
*/
NONSTRICT_READ_WRITE( "nonstrict-read-write" ),
/**
* A read and write strategy where isolation/locking is maintained in conjunction with a JTA transaction.
*/
TRANSACTIONAL( "transactional" );
private final String externalName;
private AccessType(String externalName) {
this.externalName = externalName;
}
/**
* Get the corresponding externalized name for this value.
*
* @return The corresponding externalized name.
*/
public String getExternalName() {
return externalName;
}
@Override
public String toString() {
return "AccessType[" + externalName + "]";
}
/**
* Resolve an AccessType from its external name.
*
* @param externalName The external representation to resolve
*
* @return The access type.
*
* @throws UnknownAccessTypeException If the externalName was not recognized.
*
* @see #getExternalName()
*/
public static AccessType fromExternalName(String externalName) {
if ( externalName == null ) {
return null;
}
for ( AccessType accessType : AccessType.values() ) {
if ( accessType.getExternalName().equals( externalName ) ) {
return accessType;
}
}
throw new UnknownAccessTypeException( externalName );
}
}
java enum 用法的更多相关文章
- Java Enum用法详解
Java Enum用法详解 用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举 ...
- java enum用法
基本用法 enum Day { SUNDAY, MONDAY, TUESDAY, WENDSDAY, THURSDAY, FRIDAY, SATURDAY; } 枚举是常量,所以应该用大写. 枚举是对 ...
- java Enum 用法示例
public enum MyEnum { Monday, Tuesday, Wednesday, Thursady, Friday, Saturday, Sunday; public static v ...
- Java Enum解析【转】
Enum用法: 1:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多 ...
- MVC图片上传详解 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS C#中Enum用法小结 表达式目录树 “村长”教你测试用例 引用provinces.js的三级联动
MVC图片上传详解 MVC图片上传--控制器方法 新建一个控制器命名为File,定义一个Img方法 [HttpPost]public ActionResult Img(HttpPostedFile ...
- 如何使用Java Enum
简单的用法:JavaEnum简单的用法一般用于代表一组常用常量,可用来代表一类相同类型的常量值.如: 性别: public enum SexEnum { male, female; } 颜色: pub ...
- (转)java enum枚举
转载自: 原理:http://singleant.iteye.com/blog/686349 应用:http://www.cnblogs.com/happyPawpaw/archive/2013/04 ...
- 你真的了解java的lambda吗?- java lambda用法与源码分析
你真的了解java的lambda吗?- java lambda用法与源码分析 转载请注明来源:cmlanche.com 用法 示例:最普遍的一个例子,执行一个线程 new Thread(() -> ...
- java enum
小谈Java Enum的多态性 博客分类: Java JavaAppleJDKJVMIDEA Enum+多态,我没说错,不过Enum是不可以被继承的,也不可以继承自别人,只是能实现接口而已,何谈多态 ...
随机推荐
- JVM菜鸟进阶高手之路
http://www.jianshu.com/u/3def157aab07?utm_medium=note-author-link&utm_source=mobile
- myeclipse和eclipse的区别和联系,以及版本间的对应关系
Eclipse:IBM花了4千万美金来开发这个IDE(Integrated Development Environment).第一版1.0在2001年11月释出,随后逐渐受到欢迎.Eclipse已经成 ...
- 使用IProgress实现异步编程的进程通知
在异步编程中,有时候希望把进度展示出来,借助IProgress<in T>可以实现. IProgress<in T>只提供了一个方法void Report(T value),通 ...
- 【linux】linux命令grep + awk 详解
linux命令grep + awk 详解 grep:https://www.cnblogs.com/flyor/p/6411140.html awk:https://www.cnblogs.com ...
- 解决Oracle EM 乱码问题
原创 作者:fa042 时间:2012-11-17 16:50:34 199 0 Oracle 10g提供了一个基于Web的管理工具EM(Enterprise Manager),使用比较方便.不过,如 ...
- Java集合类: Set、List、Map、Queue使用场景
目录 1. Java集合类基本概念 2. Java集合类架构层次关系 3. Java集合类的应用场景代码 1. Java集合类基本概念 在编程中,常常需要集中存放多个数据.从传统意义上讲,数组是我们的 ...
- 用level-list让同一个ImageView根据条件来显示不同的内容
感谢:http://blog.sina.com.cn/s/blog_6111ce890100psq9.html 有时候,我们为了在一个ImageView中显示不同的图片,平时往往会使用: if (条件 ...
- 整合 Ext JS 和第三方类库
介绍 ExtJS提供了许多高度可定制化内置组件.如果它不在框架(framework)里面,你可以很容易的扩展这些类,或者浏览Sencha市场(Sencha Market) 寻找你可能需要的任何东西.那 ...
- golang的Flag和Pflag
Flag和Pflag类似于python的argparse:解析命令行 flag是golang自带的包:github.com/spf13/pflag 参考:https://o-my-chenjian.c ...
- Java NIO Pipe
A Java NIO Pipe is a one-way data connection between two threads. A Pipe has a source channel and a ...