位运算的运用-权限控制:add,query,modify,del

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_44367006/article/details/98471598

位运算的运用-权限控制:add,query,modify,del

public class Permission {

    private static final int ALLOW_SELECT = 1<<0;//0001
    private static final int ALLOW_INSERT = 1<<1;//0010
    private static final int ALLOW_UPDATE = 1<<2;//0100
    private static final int ALLOW_DELETE = 1<<3;//1000

    //当前的权限状态
    private int flag;

    public void setPermission(int permission){
        flag = permission;
    }


    /*增加权限,可以一项或者多项*/
    public void addPermission(int permission){
        flag = flag|permission;
    }

    /*删除权限,可以一项或者多项*/
    public void disablePermission(int permission){
        flag = flag&~permission;
    }

    /*是否拥有某些权限*/
    public boolean isAllowed(int permission){
        return (flag&permission)==permission;
    }

    /*是否不拥有某些权限*/
    public boolean isNotAllowed(int permission){
        return (flag&permission)==0;
    }


    public static void main(String[] args) {
		int flag = 15;//1111
		Permission permission = new Permission();
		permission.setPermission(flag);
		permission.disablePermission(ALLOW_DELETE|ALLOW_INSERT);
		System.out.println("ALLOW_SELECT="+permission.isAllowed(ALLOW_SELECT));
		System.out.println("ALLOW_INSERT="+permission.isAllowed(ALLOW_INSERT));
		System.out.println("ALLOW_UPDATE="+permission.isAllowed(ALLOW_UPDATE));
		System.out.println("ALLOW_DELETE="+permission.isAllowed(ALLOW_DELETE));
	}
}

结果:

ALLOW_SELECT=true
ALLOW_INSERT=false
ALLOW_UPDATE=true
ALLOW_DELETE=false

jdk里的NIO里的OP_WRITE、OP_READ等也是用的这种思想。

展开阅读全文

"input""brpws""add""Del"找不到标识符;“xuanze”:void函数返回值

10-27

#include“stdio.h”rn#include”stdlib.h“rn#include“string.h“rn#include”windows.h”rnrnmenu();rnrntypedef struct nodern char num[20];rnint YW;rnint SX;rnint YY;rnint WL;rnint HX;rnstruct node *next;rnLinkList;rnstruct node *L;rnrnrnvoid xuanze()rnint a;rnscanf("%d",&a);rnswitch(a)rnrncase 1:input();break;rncase 2:brows();break;rncase 3:add();break; rncase 4:Del();break;rnrnreturn 0;rnrnrnrnrnvoid input()rnrnLinkList *p=L,*s; rnchar t[20];rnprintf("请输入要输入的学生学号,以0结束!\n");rnscanf ("%s",t);rnwhile(1)rnrnif(strcmp(t,"0")==0)rnbreak;rns=(LinkList *)malloc(sizeof(LinkList));rnstrcpy(s->num,t);rnprintf("请输入语文成绩:");rnscanf("%d",&s->YW);rnprintf("请输入数学成绩:");rnscanf("%d",&s->SX);rnprintf("请输入英语成绩:");rnscanf("%d",&s->YY);rnprintf("请输入物理成绩:");rnscanf("%d",&s->WL);rnprintf("请输入化学成绩:");rnscanf("%d",&s->HX);rnp->next=s;rnp=s;rnp->next=NULL;rnprintf("请输入下一个学生学号,以0结束!");rnscanf("%s",t);rnrnmenu();rnrnrnrnrnvoid add()rnrnLinkList *p=L,*s;rnchar t[20];rnprintf("请输入要添加的学生学号,以0结束!\n");rnscanf ("%s",t);rnwhile(1)rnrnif(strcmp(t,"0")==0)rnbreak;rnLinkList * s=(LinkList *)malloc(sizeof(LinkList));rnstrcpy(s->num,t);rnprintf("请输入语文成绩:");rnscanf("%d",&s->YW);rnprintf("请输入数学成绩:");rnscanf("%d",&s->SX);rnprintf("请输入英语成绩:");rnscanf("%d",&s->YY);rnprintf("请输入物理成绩:");rnscanf("%d",&s->WL);rnprintf("请输入化学成绩:");rnscanf("%d",&s->HX);rnwhile(p->next=NULL)rnp=p->next;rnp->next=s;rnp=s;rnp->next=NULL;rnprintf("请输入下一个要添加的学生学号,以0结束!");rnscanf("%s",t);rnrnmenu();rnrnmenu();rnrnrn rn rnrnvoid brows()rnrnLinkList *p=L->next;rnif(p==NULL)rnprintf("该系统无学生!");rnwhile(p!=NULL)rnrnprintf("学号%s,语文%d,数学%d,英语%d,物理%d,化学%d",rnp->num,p->YW,p->SX,p->YY,p->WL,p->HX);rnp=p->next;rnrnmenu();rnrnrnrnvoid Del(LinkList *p) //删除学生信息rn rn LinkList *s; rn char num[100];rn printf("请输入要删除的学生的学号,以0结束\n");rn scanf("%s",&num);rn while(1) rnrn if(strcmp(num,"0")==0) break;rn if (p->next==NULL)rn printf("学生表中没有任何的学生记录\n");rn else rnrnwhile(p!=NULL)rn s = p->next;rn if(s!=NULL)rn rn if(strcmp(s->num,num)== 0) rnrn p->next=s->next;rn break;rn rn rn p = p->next; rn rn rnprintf("请输入要删除的学生的学号,以0结束\n");rnscanf("%s", &num);rn rnmenu(); rnrnrnrnvoid menu()rnrnprintf("\t\t\t\t欢迎使用学生成绩管理系统\n");rnprintf("1.输入学生成绩\n");rnprintf("2.浏览学生成绩\n");rnprintf("3.添加学生成绩\n");rnprintf("4.删除学生成绩\n");rnprintf("0.退出系统\n");rnprintf("输入选择的菜单序号<0--4>");rnrnreturn 0;rnrnrnint main()rnrn L=(LinkList *)malloc(sizeof(LinkList));rnL->next=NULL;rn 问答

没有更多推荐了,返回首页