📄 defaultcredentialbehaviour.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package issrg.pba.credentials;
/**
* This class defines the default behaviour of the credential: the equals method,
* the methods for intersection and union operations.
*/
public abstract class DefaultCredentialBehaviour implements Credential {
private boolean busy=false; // this is a flag to prevent endless recursion in intersect
private boolean busy1=false; // this is a flag to prevent endless recursion in join
protected DefaultCredentialBehaviour() {}
public boolean equals(Object o){
if (o instanceof Property){
Property p = (Property)o;
return p.contains(this) && this.contains(p);
}else{
return false;
}
}
/**
* The default contains operation says that all null properties are contained by
* any other property (returns true, if property is null)
*/
public boolean contains(Property p){
if (p instanceof Sum){
return ((Sum)p).partOf(this);
}
if (p instanceof Product){
return ((Product)p).partOf(this);
}
return p==null;
}
/**
* The default intersection operation returns lhs (this) credential if it contains the
* rhs one (passed to the method); otherwise it returns the result of intersecting
* the rhs credential with lhs one.
*/
public synchronized Credential intersect(Credential c){
if (busy){
return null;
}
if (contains(c)){
return c;
}
if (c instanceof Product || c instanceof Sum){
return c.intersect(this);
} else {
busy=true;
Credential r=null;
try{
//if (!c.busy){ // if that credential is not being intersected with already
r=c.intersect(this);
//}
}catch(RuntimeException th){
throw th;
}finally{
busy=false;
}
return r;
}
}
/**
* The default union operation returns lhs (this) credential if it contains the
* rhs one; otherwise it returns the union of rhs and lhs ( c.join(this) ).
*/
public synchronized Credential join(Credential c){
if (busy1){
return new Sum(new Credential[]{this, c});
}
if (contains(c)){
return this;
}
if (c instanceof Sum){
return c.join(this);
}else {
busy1=true;
Credential r;
try{
//if (!c.busy1){ // if that credential is not being joined with already
r=c.join(this);
//}else{
// r=new Sum(new Credential[]{this, c});
//}
}catch(RuntimeException th){
throw th;
}finally{
busy1=false;
}
return r;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -