Commit 45b28658 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Better formatter and clean-up profiles (see the folder eclipse/ in this repo)

Import using: Window -> Preferences -> Java -> Code Style -> "Clean Up" or "Formatter" -> Click on the button "Import"
parent 77460bbd
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="2">
<profile kind="CleanUpProfile" name="Eclipse [Custom]" version="2">
<setting id="cleanup.qualify_static_method_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.always_use_this_for_non_static_method_access" value="false"/>
<setting id="cleanup.organize_imports" value="false"/>
<setting id="cleanup.remove_trailing_whitespaces_ignore_empty" value="false"/>
<setting id="cleanup.use_type_arguments" value="false"/>
<setting id="cleanup.format_source_code_changes_only" value="false"/>
<setting id="cleanup.qualify_static_field_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.add_generated_serial_version_id" value="false"/>
<setting id="cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class" value="true"/>
<setting id="cleanup.remove_redundant_type_arguments" value="true"/>
<setting id="cleanup.remove_unused_imports" value="true"/>
<setting id="cleanup.insert_inferred_type_arguments" value="false"/>
<setting id="cleanup.make_private_fields_final" value="true"/>
<setting id="cleanup.use_lambda" value="true"/>
<setting id="cleanup.always_use_blocks" value="true"/>
<setting id="cleanup.use_this_for_non_static_field_access_only_if_necessary" value="true"/>
<setting id="cleanup.sort_members_all" value="false"/>
<setting id="cleanup.remove_trailing_whitespaces_all" value="true"/>
<setting id="cleanup.add_missing_annotations" value="true"/>
<setting id="cleanup.always_use_this_for_non_static_field_access" value="false"/>
<setting id="cleanup.make_parameters_final" value="false"/>
<setting id="cleanup.sort_members" value="false"/>
<setting id="cleanup.remove_private_constructors" value="true"/>
<setting id="cleanup.always_use_parentheses_in_expressions" value="false"/>
<setting id="cleanup.remove_unused_local_variables" value="false"/>
<setting id="cleanup.convert_to_enhanced_for_loop" value="false"/>
<setting id="cleanup.remove_unused_private_fields" value="true"/>
<setting id="cleanup.never_use_blocks" value="false"/>
<setting id="cleanup.add_missing_deprecated_annotations" value="true"/>
<setting id="cleanup.use_this_for_non_static_field_access" value="false"/>
<setting id="cleanup.remove_unnecessary_nls_tags" value="true"/>
<setting id="cleanup.qualify_static_member_accesses_through_instances_with_declaring_class" value="true"/>
<setting id="cleanup.add_missing_nls_tags" value="false"/>
<setting id="cleanup.remove_unnecessary_casts" value="true"/>
<setting id="cleanup.use_blocks_only_for_return_and_throw" value="false"/>
<setting id="cleanup.format_source_code" value="true"/>
<setting id="cleanup.convert_functional_interfaces" value="false"/>
<setting id="cleanup.add_default_serial_version_id" value="true"/>
<setting id="cleanup.remove_unused_private_methods" value="true"/>
<setting id="cleanup.remove_trailing_whitespaces" value="false"/>
<setting id="cleanup.make_type_abstract_if_missing_method" value="false"/>
<setting id="cleanup.add_serial_version_id" value="false"/>
<setting id="cleanup.use_this_for_non_static_method_access" value="false"/>
<setting id="cleanup.use_this_for_non_static_method_access_only_if_necessary" value="true"/>
<setting id="cleanup.use_anonymous_class_creation" value="false"/>
<setting id="cleanup.add_missing_override_annotations_interface_methods" value="true"/>
<setting id="cleanup.remove_unused_private_members" value="false"/>
<setting id="cleanup.make_local_variable_final" value="true"/>
<setting id="cleanup.add_missing_methods" value="false"/>
<setting id="cleanup.never_use_parentheses_in_expressions" value="true"/>
<setting id="cleanup.qualify_static_member_accesses_with_declaring_class" value="true"/>
<setting id="cleanup.use_parentheses_in_expressions" value="false"/>
<setting id="cleanup.add_missing_override_annotations" value="true"/>
<setting id="cleanup.use_blocks" value="false"/>
<setting id="cleanup.make_variable_declarations_final" value="false"/>
<setting id="cleanup.correct_indentation" value="true"/>
<setting id="cleanup.remove_unused_private_types" value="true"/>
</profile>
</profiles>
This diff is collapsed.
Please direct all logs to go into this folder so that they do not accidently get added into the repo.
\ No newline at end of file
......@@ -2,10 +2,10 @@ package mohawk;
public class Mohawk {
public static void main(String[] args) {
MohawkInstance mohawk = new MohawkInstance();
public static void main(String[] args) {
MohawkInstance mohawk = new MohawkInstance();
mohawk.run(args);
}
mohawk.run(args);
}
}
......@@ -9,142 +9,132 @@ import java.util.Map;
/**
* @author Karthick Jayaram
*
* This binary tree is meant for maintaining the parse tree for preconditions.
* All the leaf nodes represent an operand. All intermediate nodes represent an operation - AND / OR.
* This binary tree is meant for maintaining the parse tree for preconditions. All the leaf nodes represent an
* operand. All intermediate nodes represent an operation - AND / OR.
*/
public class BTree {
Node nHead;
Node nTail;
Map<Integer, String> mapRoleIndex;
BitVector bvRoleVec;
int uiSize;
public BTree(Map<Integer, String> inRoleIndex) {
nHead = null;
uiSize = 0;
mapRoleIndex = inRoleIndex;
// Initialize bit vector
if(!mapRoleIndex.isEmpty()) {
int iBVSize = mapRoleIndex.size();
bvRoleVec = new BitVector(iBVSize,false);
}
}
public Node add2Left(Node inNode) {
if(nHead == null) {
// Adding the first element to the binary tree
nHead = inNode;
nTail = inNode;
uiSize++;
}
else {
nTail.nLeft = inNode;
nTail = inNode;
uiSize++;
}
return inNode;
}
public Node add2Right(Node inNode) {
if(nHead == null) {
// Adding the first element to the binary tree
nHead = inNode;
nTail = inNode;
nHead.nLeft = null;
nHead.nRight = null;
uiSize++;
}
else {
nTail.nRight = inNode;
nTail = inNode;
uiSize++;
}
return inNode;
}
public void printTree() {
printNode(nHead);
}
// Recursive print.
public void printNode(Node inNode) {
if(inNode.iType == 1) {
System.out.println(inNode.iOperation);
}
else if(inNode.iType ==2) {
System.out.println(inNode.sOperand);
}
else {
System.out.println("NULL");
}
if(inNode.nLeft != null) {
printNode(inNode.nLeft);
}
if(inNode.nRight != null) {
printNode(inNode.nRight);
}
}
private int getMapIndex(String inRole) throws Exception {
for(int i=0; i<mapRoleIndex.size(); i++) {
if(mapRoleIndex.get(i).equals(inRole)) {
return i;
}
}
throw new Exception("Error - BTree::getMapIndex - Role not found in map");
}
public BitVector getBV() throws Exception {
if(this.nHead != null) {
return getBV(this.nHead);
}
else {
throw new Exception("Error - BTree::getBV - nHead is null");
}
}
public BitVector getBV(Node inNode) throws Exception {
BitVector result = new BitVector(uiSize,false);
if(inNode.iType == 2) {
result.putAt( getMapIndex(inNode.sOperand) , true);
return result;
}
else if (inNode.iType == 1){
BitVector result1 = getBV(inNode.nLeft);
BitVector result2 = getBV(inNode.nRight);
if(inNode.iOperation == 0) {
result = result1.andBV(result2);
return result;
}
else {
result = result1.orBV(result2);
return result;
}
}
else {
throw new Exception("Error - BitVector::getBV - The control is not expected to come here");
}
}
Node nHead;
Node nTail;
Map<Integer, String> mapRoleIndex;
BitVector bvRoleVec;
int uiSize;
public BTree(Map<Integer, String> inRoleIndex) {
nHead = null;
uiSize = 0;
mapRoleIndex = inRoleIndex;
// Initialize bit vector
if (!mapRoleIndex.isEmpty()) {
int iBVSize = mapRoleIndex.size();
bvRoleVec = new BitVector(iBVSize, false);
}
}
public Node add2Left(Node inNode) {
if (nHead == null) {
// Adding the first element to the binary tree
nHead = inNode;
nTail = inNode;
uiSize++;
} else {
nTail.nLeft = inNode;
nTail = inNode;
uiSize++;
}
return inNode;
}
public Node add2Right(Node inNode) {
if (nHead == null) {
// Adding the first element to the binary tree
nHead = inNode;
nTail = inNode;
nHead.nLeft = null;
nHead.nRight = null;
uiSize++;
} else {
nTail.nRight = inNode;
nTail = inNode;
uiSize++;
}
return inNode;
}
public void printTree() {
printNode(nHead);
}
// Recursive print.
public void printNode(Node inNode) {
if (inNode.iType == 1) {
System.out.println(inNode.iOperation);
} else if (inNode.iType == 2) {
System.out.println(inNode.sOperand);
} else {
System.out.println("NULL");
}
if (inNode.nLeft != null) {
printNode(inNode.nLeft);
}
if (inNode.nRight != null) {
printNode(inNode.nRight);
}
}
private int getMapIndex(String inRole) throws Exception {
for (int i = 0; i < mapRoleIndex.size(); i++) {
if (mapRoleIndex.get(i).equals(inRole)) { return i; }
}
throw new Exception("Error - BTree::getMapIndex - Role not found in map");
}
public BitVector getBV() throws Exception {
if (this.nHead != null) {
return getBV(this.nHead);
} else {
throw new Exception("Error - BTree::getBV - nHead is null");
}
}
public BitVector getBV(Node inNode) throws Exception {
BitVector result = new BitVector(uiSize, false);
if (inNode.iType == 2) {
result.putAt(getMapIndex(inNode.sOperand), true);
return result;
} else if (inNode.iType == 1) {
BitVector result1 = getBV(inNode.nLeft);
BitVector result2 = getBV(inNode.nRight);
if (inNode.iOperation == 0) {
result = result1.andBV(result2);
return result;
} else {
result = result1.orBV(result2);
return result;
}
} else {
throw new Exception("Error - BitVector::getBV - The control is not expected to come here");
}
}
}
......@@ -14,50 +14,49 @@ import java.util.Vector;
*/
public class BTreeDriver {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Vector<BitVector> vecUA;
Map<Integer, String> map = new HashMap<Integer,String>();
map.put(0, "Hello");
map.put(1, "World");
//BTree btree = new BTree(map);
Node node1 = new Node(null, null, 1, 1);
Node node2 = new Node(null, null, 2, "Hello");
Node node3 = new Node(null, null, 2, "World");
//Node node4 = new Node(null, null, 1, 2);
//btree.add2Right(node1);
//btree.add2Right(node2);
//btree.add2Right(node4);
//btree.add2Left(node3);
//btree.printTree();
PreCondProcessor proc = new PreCondProcessor(map);
proc.add(0);
proc.add("Hello");
proc.add(1);
proc.add("World");
proc.add(3);
proc.add(2);
proc.add(0);
proc.add("Hello");
proc.add(2);
proc.add("World");
proc.add(3);
proc.result().printBV();
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Vector<BitVector> vecUA;
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(0, "Hello");
map.put(1, "World");
// BTree btree = new BTree(map);
Node node1 = new Node(null, null, 1, 1);
Node node2 = new Node(null, null, 2, "Hello");
Node node3 = new Node(null, null, 2, "World");
// Node node4 = new Node(null, null, 1, 2);
// btree.add2Right(node1);
// btree.add2Right(node2);
// btree.add2Right(node4);
// btree.add2Left(node3);
// btree.printTree();
PreCondProcessor proc = new PreCondProcessor(map);
proc.add(0);
proc.add("Hello");
proc.add(1);
proc.add("World");
proc.add(3);
proc.add(2);
proc.add(0);
proc.add("Hello");
proc.add(2);
proc.add("World");
proc.add(3);
proc.result().printBV();
}
}
......@@ -12,13 +12,13 @@ package mohawk.collections;
*/
public class BVException extends Exception {
/**
/**
*
*/
private static final long serialVersionUID = 1L;
public BVException() {
}
private static final long serialVersionUID = 1L;
public BVException() {
}
}
......@@ -15,79 +15,75 @@ import java.util.Vector;
*/
public class BitVector {
private Vector<Boolean> vecBV;
private int size;
public BitVector(int inSize, Boolean inValue) {
size = inSize;
vecBV = new Vector<Boolean>(size);
for(int i=0; i<size; i++) {
vecBV.addElement(inValue);
}
}
public int size() {
return size;
}
public void printBV() {
int size = vecBV.size();
System.out.println("Size of the bit vector: "+size);
for(int i=0; i<size; i++) {
System.out.print(vecBV.get(i).toString()+" ");
}
System.out.println();
}
// Get the value at a specified index
public boolean atIndex(int inIndex) {
return vecBV.get(inIndex);
}
// Set the value at a specified index
public void putAt(int inIndex, boolean inValue) {
vecBV.set(inIndex, inValue);
}
// logical AND operation
public BitVector andBV(BitVector inOperand2) throws Exception {
if(size != inOperand2.size) {
throw new Exception("Error - BitVector::andBV - Operand sizes do not match");
}
BitVector result = new BitVector(size,false);
for(int i=0; i<size; i++) {
result.putAt(i, atIndex(i)&inOperand2.atIndex(i));
}
return result;
}
// logical OR operation
public BitVector orBV(BitVector inOperand2) throws Exception {
if(size != inOperand2.size) {
throw new Exception("Error - BitVector::orBV - Operand sizes do not match");
}
BitVector result = new BitVector(size,false);
for(int i=0; i<size; i++) {
result.putAt(i, atIndex(i)|inOperand2.atIndex(i));
}
return result;
}
private Vector<Boolean> vecBV;
private int size;
public BitVector(int inSize, Boolean inValue) {
size = inSize;
vecBV = new Vector<Boolean>(size);
for (int i = 0; i < size; i++) {
vecBV.addElement(inValue);
}
}
public int size() {
return size;
}
public void printBV() {
int size = vecBV.size();
System.out.println("Size of the bit vector: " + size);
for (int i = 0; i < size; i++) {
System.out.print(vecBV.get(i).toString() + " ");
}
System.out.println();
}
// Get the value at a specified index
public boolean atIndex(int inIndex) {
return vecBV.get(inIndex);
}
// Set the value at a specified index
public void putAt(int inIndex, boolean inValue) {
vecBV.set(inIndex, inValue);
}
// logical AND operation
public BitVector andBV(BitVector inOperand2) throws Exception {
if (size != inOperand2.size) { throw new Exception("Error - BitVector::andBV - Operand sizes do not match"); }