-->

Tuesday 6 March 2012

Reflection On A Java Project

Fair warning that the code here may only be useful to me.

I wrote the program below when I was trying to regain mastery of code I had written. I had stopped working on my project for about three weeks because of exams. What I wanted was a list of all the methods in the project so that I could test my self on their responsibilities. There are no subtleties about how I achieved this.
The first thing I did was to put the names of the classes in a text file, called 'a.txt'. This was done by navigating to the folder in Dos and executing the command
dir /s /b >> a.txt
I then wrote the following snippet:


/**
  * 10. Check we are not at the start node
  * 20. Check the multiset is not empty
  * 30. Get the current nodes relationships of thype HAS_LETTER and iterator
  * 40. Check the iterator is not empty
  * 50. For each relationship
  * 52. Get character from the node at the other end of the relationship
  * 54. Check how many times the character is in the multiset
  * 56. Does the value on the relationship match the value in the multiset?
  */
 @Override
 public boolean isReturnableNode(TraversalPosition pos) {

  // 10. Check we are not at the start node
  if (pos.isStartNode())
   return false;
  
  // 20. Check the multiset is not empty
  if (multiset.isEmpty())
   return false;

  // 30. Get the current nodes relationships of thype HAS_LETTER and iterator
  Iterable<relationship> rel = pos.currentNode().getRelationships(RelTypes.HAS_LETTER);
  Iterator<relationship> iter = rel.iterator();

  // 40. Check the iterator is not empty
  if (!iter.hasNext()){
   return false;
  }

  // 50. For each relationship
  while (iter.hasNext()){
   
   // 52. Get character from the node at the other end of the relationship
   Relationship relationship = iter.next();
   Node otherNode = relationship.getEndNode();
   Character c = (Character)otherNode.getProperty("letter");

   // 54. Check how many times the character is in the multiset
   Integer characterCount = new Integer(multiset.count(c));

   // 56. Does the value on the relationship match the value in the multiset?
   if (characterCount &gt; 0) {
    if (!relationship.hasProperty("occurrences")){
     return false;
    } else if (!characterCount.equals((Integer)relationship.getProperty("occurrences"))){
     return false;
    }
   } else { 
    return false;
   }

  }

  return true;
 }





g

-------------------------
CHRIS
-------------------------
getHTML
addObserver
updateRaceMeetings
createHomepage
createRaceMeetings

-------------------------
CHRISDatabase
-------------------------
getUsernames
getPasswords

-------------------------
Course
-------------------------
toString
getName
setName
asString
getImageAsLabel

-------------------------
DataModel
-------------------------
getComponent

-------------------------
ETEDatabase
-------------------------
getUsernames
getPasswords

-------------------------
Homepage
-------------------------
main

-------------------------
Horse
-------------------------
compareTo
compareTo
min
getName
compare
contains
getURL
getLinks
setLinks
findLinks
findStuff
findName
getLink

No comments:

Post a Comment

Arrow Key Nav