Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:14:06+00:00 2026-05-29T05:14:06+00:00

I want to port this c# permission module to java, but I am confused

  • 0

I want to port this c# permission module to java, but I am confused how I can do this when I can’t save the numeric value in the database and then cast it to the enumeration representation.

In c#, I create a enum like this:

public enum ArticlePermission
{
     CanRead   = 1,
     CanWrite  = 2,
     CanDelete = 4,
     CanMove   = 16
}

I then can create a permission set like:

ArticlePermission johnsArticlePermission = ArticlePermission.CanRead | ArticlePermission.CanMove;

I then save this into the database using:

(int)johnsArticlePermission

Now I can read it from the database as an integer/long, and cast it like:

johnsArticlePermission = (ArticlePermission) dr["articlePermissions"];

And I can check permissions like:

if(johnsArticlePermission & ArticlePermission.CanRead == ArticlePermission.CanRead) 
{

}

How can I do this in java?
From what I understand, in java, you can convert the enumeration into a numeric value, and then convert it back to a java enumeration.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:14:06+00:00Added an answer on May 29, 2026 at 5:14 am

    What you really need here is an EnumSet, described in the API like this:

    Enum sets are represented internally as bit vectors. This
    representation is extremely compact and efficient. The space and time
    performance of this class should be good enough to allow its use as a
    high-quality, typesafe alternative to traditional int-based “bit
    flags.”

    An enum is a class under the hood so you can add methods to it. For example,

    public enum ArticlePermission
    {
      CanRead(1),
      CanWrite(2),
      CanDelete(4),
      CanMove(16); // what happened to 8?
    
      private int _val;
      ArticlePermission(int val)
      {
        _val = val;
      }
    
      public int getValue()
      {
        return _val;
      }
    
      public static List<ArticlePermission> parseArticlePermissions(int val)
      {
        List<ArticlePermission> apList = new ArrayList<ArticlePermission>();
        for (ArticlePermission ap : values())
        {
          if (val & ap.getValue() != 0)
            apList.add(ap);
        }
        return apList;
      }
    }
    

    parseArticlePermissions will give you a List of ArticlePermission objects from an integer value, presumably created by ORing the value of ArticlePermission objects.

    Here is a more detailed explanation of EnumSet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know Java apps can be run in Android. But what I want to
I want to port this SQL query, which works just fine on SQL Server,
I want to port a python app that uses mechanize for the iPhone. This
I want to port data from one server's database to another server's database. The
i want to port my application to CodeIgniter but i am wondering whether i
A friend and I have written an encryption module and we want to port
I am programing VIX API from python 2.5, but now I want to port
I have a Db of Quartz CronTriggers. I want to port this entire system
I want port some my Python scripts into web apps so that others can
I'm trying to port this java to php: String _value = '1111122222'; if (_value.matches((1{5}|2{5}|3{5}|4{5}|5{5}|6{5}|7{5}|8{5}|9{5}){2}))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.