Java enum usage

Source: Internet
Author: User

/*
* Hibernate, relational persistence for idiomatic Java
*
* Copyright (c), 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 is
* Distributed under license by Red Hat INC.
*
* This copyrighted material are 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 was distributed in the hope that it'll 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 has received a copy of the GNU Lesser general public License
* Along with this distribution; If not, write to:
* Free Software Foundation, Inc.
* Wuyi 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 is applied.
*
* @see Accesstype#read_only
*/
Read_Only (accesstype.read_only),
/**
* indicates that the non-strict Read-write strategy should is applied.
*
* @see Accesstype#nonstrict_read_write
*/
Nonstrict_read_write (Accesstype.nonstrict_read_write),
/**
* Indicates that the Read-write strategy should is applied.
*
* @see Accesstype#read_write
*/
Read_write (Accesstype.read_write),
/**
* Indicates that the transaction strategy should is 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 would return {@code null} for
* {@link #NONE}
*/
Public AccessType Toaccesstype () {
return accessType;
}

/**
* Conversion from {@link AccessType} to {@link cacheconcurrencystrategy}.
*
* @param AccessType the ACC ESS 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 nu LL}.
*/
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 is 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 is
* Distributed under license by Red Hat INC.
*
* This copyrighted material are 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 was distributed in the hope that it'll 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 has received a copy of the GNU Lesser general public License
* Along with this distribution; If not, write to:
* Free Software Foundation, Inc.
* Wuyi 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 is 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 is not maintained as tightly as in {@link #READ_WRITE}, which leads to better throughput
* But may also leads 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 is 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 usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.