Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllBottom: simplify and fix meetWith #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/heros/edgefunc/AllBottom.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,52 @@
* are made available under the terms of the GNU Lesser Public License v2.1
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
*
* Contributors:
* Eric Bodden - initial API and implementation
* Eric Bodden - initial API and implementation
******************************************************************************/
package heros.edgefunc;

import heros.EdgeFunction;


public class AllBottom<V> implements EdgeFunction<V> {

private final V bottomElement;

public AllBottom(V bottomElement){
this.bottomElement = bottomElement;
}
}

@Override
public V computeTarget(V source) {
return bottomElement;
}

@Override
public EdgeFunction<V> composeWith(EdgeFunction<V> secondFunction) {
if (secondFunction instanceof EdgeIdentity)
return this;
return secondFunction;
}

// The meet (greatest lower bound) of bottom with anything is bottom
@Override
public EdgeFunction<V> meetWith(EdgeFunction<V> otherFunction) {
if(otherFunction == this || otherFunction.equalTo(this)) return this;
if(otherFunction instanceof AllTop) {
return this;
}
if(otherFunction instanceof EdgeIdentity) {
return this;
}
throw new IllegalStateException("unexpected edge function: "+otherFunction);
return this;
}

@Override
public boolean equalTo(EdgeFunction<V> other) {
if(other instanceof AllBottom) {
@SuppressWarnings("rawtypes")
AllBottom allBottom = (AllBottom) other;
return allBottom.bottomElement.equals(bottomElement);
}
}
return false;
}


@Override
public String toString() {
return "allbottom";
}
Expand Down