ChordCreatorUtil.java

Index Score
org.herac.tuxguitar.gui.editors.chord
TuxGuitar

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
LOOPSNumber of loops
JAVA0034JAVA0034 Missing braces in if statement
COMPARISONSNumber of comparison operators
DECL_COMMENTSComments in declarations
CYCLOMATICCyclomatic complexity
LINESNumber of lines in the source file
SIZESize of the file in bytes
COMMENTSComment lines
WHITESPACENumber of whitespace lines
OPERATORSNumber of operators
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
PROGRAM_LENGTHHalstead program length
JAVA0035JAVA0035 Missing braces in for statement
LOGICAL_LINESNumber of statements
OPERANDSNumber of operands
ELOCEffective lines of code
LOCLines of code
JAVA0145JAVA0145 Tab character used in source file
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
BLOCKSNumber of blocks
JAVA0076JAVA0076 Use of magic number
PARAMSNumber of formal parameter declarations
INTERFACE_COMPLEXITYInterface complexity
DOC_COMMENTNumber of javadoc comment lines
EXITSProcedure exits
JAVA0075JAVA0075 Method parameter hides field
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
RETURNSNumber of return points from functions
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0043JAVA0043 Inner class does not use outer class
JAVA0013JAVA0013 Non-blank final field is not static
JAVA0177JAVA0177 Variable declaration missing initializer
UNIQUE_OPERATORSNumber of unique operators
FUNCTIONSNumber of function declarations
BLOCK_COMMENTNumber of block comment lines
JAVA0036JAVA0036 Missing braces in while statement
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0111JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0128JAVA0128 Public constructor in non-public class
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0174JAVA0174 Assigned local variable never used
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0109JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
/* * Created on 31-dic-2005 * Redesigned on 05-March-2007 * */ package org.herac.tuxguitar.gui.editors.chord; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import org.herac.tuxguitar.gui.TuxGuitar; import org.herac.tuxguitar.song.models.TGChord; /** * * Class that helps to create a chord from information put in ChordSelector * dialog. * * Also contains ChordDatabase static field. * * @author Nikola Kolarovic * * @author julian * */ public class ChordCreatorUtil { /** * Maximum number of strings variable - has twin in TrackPropertiesAction * class */ public static final int MAX_STRINGS = 7; /** Maximum fret distance for a chord */ public static final int MAX_FRET_SPAN = 5; /** mark for bass note type **/ private final int BASS_INDEX = -1; /** mark for essential note in a chord - MUST be in */ private final int ESSENTIAL_INDEX = -2; /** mark for essential note in a chord - PENALTY if not in */ private final int NOT_ESSENTIAL_INDEX = -3; /** Keep the Thread control */ private static long runningProcess; // ------ attributes ------ //protected ChordInfo info; private long processId; private ChordCreatorListener listener; /** the alteration List selectionIndex */ private int alteration; private int chordIndex; /** essential notes for the chord (from ChordInfo) */ private int[] requiredNotes; /** notes that expand the chord (add+-) */ private int[] expandingNotes; /** is the fifth altered */ private int add5 = 0; /** name of a chord */ private String chordName = null; private int bassTonic; private int chordTonic; /** current tunning */ private int[] tuning; // this var keep a control to running threads. //private long runningProcess; // ------------------------------------------------------ // ------------------------------------------------------ // ------------------------------------------------------ private ChordCreatorUtil(long processId,ChordCreatorListener listener){ this.processId = processId; this.listener = listener; } public boolean isValidProcess(){ return (this.processId == runningProcess); } public static long getNewProcess(){ return (++ runningProcess); } public static void getChords(final ChordCreatorListener listener, final int[] tuning, final int chordIndex, final int alteration, final int plusMinus, final boolean add, final int add5, final int add9, final int add11, final int bassTonic, final int chordTonic, final boolean sharp){ final ChordCreatorUtil chordCreator = new ChordCreatorUtil(getNewProcess(), listener ); new Thread(new Runnable() { public void run() { chordCreator.getChords( tuning, chordIndex, alteration, plusMinus, add, add5, add9, add11, bassTonic, chordTonic, sharp); } }).start(); } protected void getChords(int[] tuning, int chordIndex, int alteration, int plusMinus, boolean add, int add5, int add9, int add11, int bassTonic, int chordTonic, boolean sharp) { if(!isValidProcess()){ return; } this.add5 = add5; this.tuning = tuning; this.chordIndex = chordIndex; this.chordTonic = chordTonic; this.bassTonic = bassTonic; this.alteration = alteration; //this.info = (ChordInfo) getChordData().getChords().get(chordIndex); // Generate the chord name this.chordName = new ChordNamingConvention().createChordName(this.chordTonic, this.chordIndex, this.alteration, plusMinus, add, add5, add9, add11, this.bassTonic, sharp); // find the notes that expand the chord if (this.alteration!=0) { if (add) { this.expandingNotes = new int[1]; this.expandingNotes[0]= getAddNote(this.alteration-1,plusMinus); } else { // not just add... // 9+- = 7b !9(+-) (index=1) // 11+- = 7b !11(+-) 9(+-) (index=2) // 13+- = 7b !13(+-) 9(+-) 11(+-) (index=3) this.expandingNotes = new int[1+this.alteration]; this.expandingNotes[0] = 11; //7b this.expandingNotes[1] = getAddNote(this.alteration-1,plusMinus); //this.alteration+- // rest for (int i=2; i<=this.alteration; i++) this.expandingNotes[i]=getAddNote(i-2, i==2 ? add9 : add11); // @2=add9+-, @3=add11+- tone } } else this.expandingNotes=new int[0]; // Required notes //this.requiredNotes = ((ChordDatabase.ChordInfo)new ChordDatabase().getChords().get(chordIndex)).cloneRequireds(); this.requiredNotes = ChordDatabase.get(chordIndex).cloneRequireds(); //IT DON'T BUILD UNDER JRE1.4 //this.requiredNotes = ((ChordDatabase.ChordInfo) ChordCreatorUtil.getChordData().getChords().get(chordIndex)).getRequiredNotes().clone(); // adjust the subdominant if needed if (add5!=0) { for (int i=0; i<this.requiredNotes.length; i++) if (this.requiredNotes[i]==8) // alternate the subdominant this.requiredNotes[i]+=(add5==1 ? 1 : -1); } // first count different from -1 int count = 0; for (int i=0; i<this.requiredNotes.length; i++) { this.requiredNotes[i]=checkForOverlapping(this.requiredNotes[i]); if (this.requiredNotes[i]!=-1) count++; } // then fill in the new array int[] tempNotes = new int[count]; count = 0; for (int i=0; i<this.requiredNotes.length; i++) if (this.requiredNotes[i]!=-1) { tempNotes[count]=this.requiredNotes[i]; count++; } // and substitute them this.requiredNotes = tempNotes; //return getChords(); if(isValidProcess()){ List chords = getChords(); if(chords != null && isValidProcess()){ this.listener.notifyChords(this, chords); } } } // ------------------------------------------------------ /** We have to make sure that if required note is already inside * expanding notes array so we don't put it twice... */ protected int checkForOverlapping(int checkIt) { for (int i=0; i<this.expandingNotes.length; i++) if (this.expandingNotes[i]==checkIt) return -1; return checkIt; } // ------------------------------------------------------ /** * * Creates the chord combinations out of given data and then uses some kind * of * * heuristics to check the most suitable formations. * * @return the list of TGChord structures that are most suitable * */ private java.util.List getChords() { // MOVED TO A NEW METHOD: makePotentialNotes(); // create the space for potential notes, for each string /* ArrayList potentialNotes = new ArrayList(this.tuning.length); for (int string = 0; string < this.tuning.length; string++) { ArrayList currentStringList = new ArrayList(10); // search all the frets for (int fret = 0; fret < this.MAX_NOTES; fret++) { find(this.tuning[string], string, fret, currentStringList); // put // in // all // the // needed // notes } potentialNotes.add(currentStringList); } */ // make the combinations and order them by priority /* ArrayList theBestOnes = takeBest( determinePriority( makeCombinations(potentialNotes))); // take the best rated and create TGChord list out of them return createChords(theBestOnes); */ if(!isValidProcess()){ return null; } ArrayList potentialNotes = makePotentialNotes(); ArrayList combinations = makeCombinations( potentialNotes); ArrayList priorities = determinePriority( combinations); ArrayList theBestOnes = takeBest( priorities); return createChords( theBestOnes); } /** * Creates the TGChord ArrayList out of StringValue's ArrayLists * * @param Highest rated StringValues * @return TGChord collection */ private ArrayList createChords(ArrayList top) { if(!isValidProcess()){ return null; } ArrayList chords = new ArrayList(top.size()); Iterator it = top.iterator(); while (it.hasNext()) { TGChord chord = TuxGuitar.instance().getSongManager().getFactory() .newChord(this.tuning.length); Iterator it2 = ((ArrayList) it.next()).iterator(); while (it2.hasNext()) { StringValue stringValue = (StringValue) it2.next(); int string = ((chord.getStrings().length - 1) - (stringValue.getString())); int fret = stringValue.getFret(); chord.addFretValue(string, fret); chord.setName(this.chordName); } chords.add(chord); } return chords; } // ------------------------------------------------------ // ------------------------------------------------------ /** * * If string/fret combination is needed for the chord formation, add it into * List * * @return true if the note is needed for chord formation * */ private void find(int stringTone, int stringIndex, int fret,List stringList){ if(!isValidProcess()){ return; } boolean bassAlreadyIn=false; // chord base notes for (int i = 0; i < this.requiredNotes.length; i++) if ((stringTone + fret) % 12 == (this.chordTonic+this.requiredNotes[i] - 1) % 12) { if (!bassAlreadyIn && (stringTone + fret) % 12 == this.bassTonic) bassAlreadyIn=true; stringList.add(new StringValue(stringIndex, fret, i)); return; } // alterations if (this.expandingNotes.length!=0) { for (int i=0; i<this.expandingNotes.length; i++) { if ((stringTone+fret)%12==(this.chordTonic+this.expandingNotes[i]-1)%12) { if (!bassAlreadyIn && (stringTone + fret) % 12 == this.bassTonic) bassAlreadyIn=true; stringList.add(new StringValue(stringIndex,fret,(i<2 ? this.ESSENTIAL_INDEX : this.NOT_ESSENTIAL_INDEX))); } } } // bass tone if (!bassAlreadyIn) if ((stringTone + fret) % 12 == this.bassTonic) { stringList.add(new StringValue(stringIndex, fret, this.BASS_INDEX)); return; } } // ------------------------------------------------------ // ------------------------------------------------------ /** * Returns the wanted note for ADD chord * * @param type * 0==add9; 1==add11; 2==add13; * @param selectionIndex * index of selected item in the List combo * @return wanted note, or -1 if nothing was selected * */ private int getAddNote(int type, int selectionIndex) { int wantedNote = 0; switch (type) { case 0: wantedNote = 3; // add9 break; case 1: wantedNote = 6; // add11 break; case 2: wantedNote = 10; // add13 break; } switch (selectionIndex) { case 1: wantedNote++; break; case 2: wantedNote--; break; default: break; } return wantedNote; } // ------------------------------------------------------ // ------------------------------------------------------ private ArrayList makePotentialNotes(){ if(!isValidProcess()){ return null; } ArrayList potentialNotes = new ArrayList(this.tuning.length); for (int string = 0; string < this.tuning.length; string++) { ArrayList currentStringList = new ArrayList(10); // search all the frets if (ChordSettings.instance().getFindChordsMin()>0 && ChordSettings.instance().isEmptyStringChords()) find(this.tuning[string], string, 0, currentStringList); // if it's open chord but wanted to search from different minimal fret for (int fret = ChordSettings.instance().getFindChordsMin(); fret <= ChordSettings.instance().getFindChordsMax(); fret++) { find(this.tuning[string], string, fret, currentStringList); // put // in // all // the // needed // notes } potentialNotes.add(currentStringList); } return potentialNotes; } /** * * Makes the all-possible combinations of found notes that can be reached by * fingers * * @param potentialNotes * list consisted of found notes for each string * * @return list of list of StringValues, with tones that can form a chord * */ private ArrayList makeCombinations(ArrayList potentialNotes) { if(!isValidProcess()){ return null; } // COMBINATIONS of strings used in a chord ArrayList stringCombination = new ArrayList(60); ArrayList lastLevelCombination = null; for (int i = 0; i < this.tuning.length - 1; i++) { lastLevelCombination = makeStringCombination(lastLevelCombination); // lastLevelCombination after 3rd round: [[0, 1, 2, 3], [0, 1, 2, // 4], [0, 1, 3, 4], [0, 2, 3, 4], [1, 2, 3, 4], [0, 1, 2, 5], [0, // 1, 3, 5], [0, 2, 3, 5], [1, 2, 3, 5], [0, 1, 4, 5], [0, 2, 4, 5], // [1, 2, 4, 5], [0, 3, 4, 5], [1, 3, 4, 5], [2, 3, 4, 5]] stringCombination.addAll(lastLevelCombination); } ArrayList combinations = new ArrayList(800); // --- combine the StringValues according to strings combination // ----------------------======= Iterator iterator = stringCombination.iterator(); while (iterator.hasNext()) { // go through all string combinations // list ArrayList currentStringCombination = (ArrayList) iterator.next(); // take // a // string // combinations lastLevelCombination = null; for (int level = 0; level < currentStringCombination.size(); level++) { // go // through // all // the // strings // in // one // combination int currentString = ((Integer) currentStringCombination .get(level)).intValue(); // take the string index // take all the potential notes from currentString and combine // them with potential notes from other strings lastLevelCombination = makeStringValueCombination(lastLevelCombination,(ArrayList)potentialNotes.get(currentString)); // the structure of combinations is AL { AL(StringValue,SV,SV), // AL(SV), AL(SV,SV),AL(SV,SV,SV,SV,SV,SV) } } if(lastLevelCombination != null){ combinations.addAll(lastLevelCombination); } } return combinations; } // ------------------------------------------------------ /** * Makes a combination of string indices * * @param lastLevelCombination * structure to be expanded by current level * * @return structure of stringCombination is AL { AL(0), AL(0,1), * AL(0,2),AL(0,1,3,4),AL(0,1,2,3,4,5) } */ private ArrayList makeStringCombination(ArrayList lastLevelCombinationRef){ if(!isValidProcess()){ return null; } List lastLevelCombination = lastLevelCombinationRef; if (lastLevelCombination == null) { // first combination is AL { AL(0), AL(1), AL(2), AL(3), AL(4), // ...AL(tuning.length) } lastLevelCombination = new ArrayList(); for (int i = 0; i < this.tuning.length; i++) { lastLevelCombination.add(new ArrayList()); ((ArrayList) lastLevelCombination.get(i)).add(new Integer(i)); } } ArrayList thisLevelCombination = new ArrayList(); for (int current = 1; current < this.tuning.length; current++) { Iterator it = lastLevelCombination.iterator(); while (it.hasNext()) { ArrayList combination = (ArrayList) it.next(); Integer currentInteger = new Integer(current); if (((Integer) combination.get(combination.size() - 1)) .intValue() < current && !combination.contains(currentInteger)) { // check if the string is already in combination ArrayList newCombination = (ArrayList) combination.clone(); newCombination.add(currentInteger); thisLevelCombination.add(newCombination); } } } return thisLevelCombination; } // ------------------------------------------------------ /** * Makes a combination of notes by multiplying last combination and current * note arrays * * * * @param lastLevelCombination * structure to be expanded by current level * * @param notes * notes that can be considered into making a chord * * @return structure of StringValue combinations : AL { * AL(StringValue,SV,SV), AL(SV), AL(SV,SV),AL(SV,SV,SV,SV,SV,SV) } * */ private ArrayList makeStringValueCombination(ArrayList lastLevelCombination, ArrayList notes) { if(!isValidProcess()){ return null; } ArrayList thisLevelCombination = null; if (lastLevelCombination == null) { // initial combination thisLevelCombination = new ArrayList(notes.size()); for (int i = 0; i < notes.size(); i++) { thisLevelCombination.add(new ArrayList(6)); ((ArrayList) thisLevelCombination.get(i)).add(notes.get(i)); } // first combination is AL { AL(firstOne), AL(anotherFret) } } else { thisLevelCombination = new ArrayList(); for (int i = 0; i < notes.size(); i++) for (int j = 0; j < lastLevelCombination.size(); j++) { // cartesian // multiplication ArrayList currentCombination = (ArrayList) ((ArrayList) lastLevelCombination .get(j)).clone(); currentCombination.add(notes.get(i)); // if the distance maximum between the existing frets // is less than wanted, add it into potential list if (checkCombination(currentCombination)) thisLevelCombination.add(currentCombination); } } return thisLevelCombination; } // ------------------------------------------------------ /** * Checks if the combination can be reached by fingers. It is reachable * * if the distance between lowest and highest fret is less than * * <i>ChordCreatorUtil.MAX_FRET_SPAN</i>. * * Also note that this method eliminates or includes the chords with empty * strings, * * which is controlled with <i>boolean ChordCreatorUtil.EMPTY_STRING_CHORDS</i> * * @param combination * current combination to be examined * * @return true if it can be reached * */ private boolean checkCombination(ArrayList combination) { Iterator it = combination.iterator(); int maxLeft, maxRight; maxLeft = maxRight = ((StringValue) combination.get(0)).getFret(); while (it.hasNext()) { int fret = ((StringValue) it.next()).getFret(); if (fret != 0 || !ChordSettings.instance().isEmptyStringChords()) { // chords // with // empty-string // are // welcome if (fret < maxLeft) maxLeft = fret; if (fret > maxRight) maxRight = fret; } } if (Math.abs(maxLeft - maxRight) >= MAX_FRET_SPAN) return false; return true; } // ------------------------------------------------------ // ------------------------------------------------------ /** * orders the StringValue ArrayList by their priority, calculated here * * for every single chord combination.<br> * * Priority is higher if:<br> * - tone combination has all notes required for the chord basis<br> * - has good chord semantics uses many basic tones, and all necessary * tones in their place<br> * - tone combination has all subsequent strings (no string skipping)<br> * - has a chord bass tone as lowest tone<br> * - uses more strings<br> * - uses good fingering positions<br> * * @param allCombinations * all the StringValue combinations that make some sense * * @return Treemap of the StringValue ArrayLists, in which the key is * * <i>float priority</i>. * */ private ArrayList determinePriority(ArrayList allCombinations) { if(!isValidProcess()){ return null; } ArrayList ordered = new ArrayList(); Iterator it = allCombinations.iterator(); while (it.hasNext() && isValidProcess()) { float priority = 0; ArrayList stringValueCombination = (ArrayList) it.next(); // tone combination has all notes required for the chord basis priority += combinationHasAllRequiredNotes(stringValueCombination); // uses good chord semantics priority += combinationChordSemantics(stringValueCombination); // tone combination has all subsequent strings (no string skipping) priority += combinationHasSubsequentStrings(stringValueCombination); // has a chord bass tone as lowest tone priority += combinationBassInBass(stringValueCombination); // uses many strings // 4 and less strings will be more praised in case of negative grade // 4 and more strings will be more praised in case of positive grade priority += ChordSettings.instance().getManyStringsGrade() / 3 * (stringValueCombination.size()-this.tuning.length / (ChordSettings.instance().getManyStringsGrade()>0 ? 2 : 1.2) ); /* OLD : priority += ChordCreatorUtil.MANY_STRINGS_GRADE / this.tuning.length * stringValueCombination.size(); */ // uses good fingering positions priority += combinationHasGoodFingering(stringValueCombination); // System.out.println("OVERALL: // "+priority+"----------------------------"); PriorityItem item = new PriorityItem(); item.priority = priority; item.stringValues = stringValueCombination; ordered.add(item); } return ordered; } // -------------------------------------------------------------- /** * * Takes the StringValue ArrayLists that has the best priority rating * */ private ArrayList takeBest(ArrayList priorityItems) { if(!isValidProcess()){ return null; } int maximum = ChordSettings.instance().getChordsToDisplay(); ArrayList bestOnes = new ArrayList(maximum); Collections.sort(priorityItems, new PriorityComparator()); for(int i = 0; i < priorityItems.size() && isValidProcess(); i ++){ PriorityItem item = (PriorityItem)priorityItems.get(i); if (!checkIfSubset(item.stringValues, bestOnes) ){ bestOnes.add(item.stringValues); if( bestOnes.size() >= maximum ){ break; } } } /* Object[] array = priorityItems.toArray(); java.util.Arrays.sort(array, new PriorityComparator()); ArrayList bestOnes = new ArrayList(settings.getChordsToDisplay()); int boundary = (array.length > settings.getChordsToDisplay() ? settings.getChordsToDisplay() : array.length - 1); for (int i = 0; i <= boundary; i++) { // Check if the item is a subset or superset of a BETTER CHORD if (!checkIfSubset(((PriorityItem) array[i]).stringValues, bestOnes) ) bestOnes.add(((PriorityItem) array[i]).stringValues); } */ return bestOnes; } // -------------------------------------------------------------- /** adds points if the combination has all the notes in the basis of chord */ private float combinationHasAllRequiredNotes(ArrayList stringValueCombination) { if(!isValidProcess()){ return 0; } Iterator it = stringValueCombination.iterator(); int[] values = new int[this.requiredNotes.length]; int currentIndex = 0; while (it.hasNext()) { StringValue sv = (StringValue) it.next(); if (sv.requiredNoteIndex >= 0) { // only basis tones boolean insert = true; for (int i = 0; i < currentIndex; i++) if (values[i] == sv.requiredNoteIndex + 1) insert = false; // sv.requiredNoteIndex+1, because we have index 0 and we don't // want it inside if (insert) { values[currentIndex] = sv.requiredNoteIndex + 1; currentIndex++; } } } if (currentIndex == this.requiredNotes.length) { return ChordSettings.instance().getRequiredBasicsGrade(); } // else { if (currentIndex == this.requiredNotes.length - 1) { boolean existsSubdominant = false; Iterator it2 = stringValueCombination.iterator(); while (it2.hasNext()) { StringValue current = (StringValue)it2.next(); if ((this.tuning[current.string] + current.fret) % 12 == (this.chordTonic + 7) %12) existsSubdominant = true; } if (!existsSubdominant && currentIndex == this.requiredNotes.length-1) { // if not riff. "sus" chord, or chord with altered fifth allow chord without JUST subdominant (fifth) with small penalty //if ( !((ChordInfo)new ChordDatabase().getChords().get(this.chordIndex)).getName().contains("sus") && this.requiredNotes.length!=2 && this.add5==0) { //String.contains(String) is not available at JRE1.4 //Replaced by "String.indexOf(String) >= 0" if ( ChordDatabase.get(this.chordIndex).getName().indexOf("sus") >= 0 && this.requiredNotes.length != 2 && this.add5 == 0) { return ( ChordSettings.instance().getRequiredBasicsGrade() * 4 / 5 ); } } } // required notes count should decrease the penalty int noteCount = (this.alteration == 0 ? 0 : 1+ this.alteration)+currentIndex+ (this.bassTonic == this.chordTonic ? 0 : 1); // sometimes, when noteCount is bigger then tunning length, this pennalty will become positive, which may help return -ChordSettings.instance().getRequiredBasicsGrade() * (this.tuning.length - noteCount) / this.tuning.length * 2; } // -------------------------------------------------------------- /** adds points if the combination has strings in a row */ private float combinationHasSubsequentStrings(ArrayList stringValueCombination) { if(!isValidProcess()){ return 0; } boolean stumbled = false, noMore = false, penalty = false; for (int i = 0; i < this.tuning.length; i++) { boolean found = false; Iterator it = stringValueCombination.iterator(); while (it.hasNext()) if (((StringValue) it.next()).string == i) found = true; if (found) { if (!stumbled) stumbled = true; if (noMore) penalty = true; if (penalty) // penalty for skipped strings return -ChordSettings.instance().getSubsequentGrade(); } else if (stumbled) noMore = true; } if (penalty) return 0.0f; return ChordSettings.instance().getSubsequentGrade(); } // -------------------------------------------------------------- /** checks if the bass tone is the lowest tone in chord */ private float combinationBassInBass(ArrayList stringValueCombination) { if(!isValidProcess()){ return 0; } for (int i = 0; i < this.tuning.length; i++) { Iterator it = stringValueCombination.iterator(); while (it.hasNext()) { StringValue sv = (StringValue) it.next(); if (sv.string == i) { // stumbled upon lowest tone if ( (this.tuning[sv.string]+sv.fret) % 12 == this.bassTonic ) return ChordSettings.instance().getBassGrade(); // else return -ChordSettings.instance().getBassGrade(); } } } return 0; } // -------------------------------------------------------------- /** * grades the fingering in a chord. * * fingering is good if:<br> * - uses as little as possible fret positions<br> * - uses less than 3 fret positions<br> * - distributes good among fingers<br> * - can be placed capo <br> * */ private float combinationHasGoodFingering(ArrayList stringValueCombination) { if(!isValidProcess()){ return 0; } // init: copy into simple array float finalGrade = 0; int[] positions = new int[this.tuning.length]; for (int i = 0; i < this.tuning.length; i++) positions[i] = -1; { Iterator it = stringValueCombination.iterator(); while (it.hasNext()) { StringValue sv = (StringValue) it.next(); positions[sv.string] = sv.fret; } } // algorithm // distance between fingers int min = ChordSettings.instance().getFindChordsMax()+2, max = 0, maxCount=0; boolean openChord = false, zeroString = false; for (int i = 0; i < this.tuning.length; i++) { openChord|= ChordSettings.instance().isEmptyStringChords() && positions[i] == 0; zeroString |= positions[i]==0; if (positions[i] < min && positions[i] != 0 && positions[i]!=-1) min = positions[i]; if (positions[i] > max) { max = positions[i]; maxCount=1; } else if (positions[i]==max) maxCount++; } // finger as capo int count = 0; for (int i = 0; i < this.tuning.length; i++) if (positions[i] == min) count++; if (!openChord) { if (zeroString) finalGrade += ChordSettings.instance().getFingeringGrade()/8; else if (count >= 2) finalGrade += ChordSettings.instance().getFingeringGrade()/8; } else if (openChord) finalGrade += ChordSettings.instance().getFingeringGrade()/8; // position distance: 1-2 nice 3 good 4 bad 5 disaster float distanceGrade; switch(Math.abs(max-min)) { case 0 : distanceGrade=ChordSettings.instance().getFingeringGrade()/5; break; case 1 : distanceGrade=ChordSettings.instance().getFingeringGrade()/(5+maxCount); break; case 2 : distanceGrade=ChordSettings.instance().getFingeringGrade()/(6+maxCount); if (min<5) distanceGrade*=0.9; break; case 3 : distanceGrade=-ChordSettings.instance().getFingeringGrade()/10*maxCount; // I emphasize the penalty if big difference is on some // lower frets (it is greater distance then) if (min<5) distanceGrade*=1.3; break; case 4 : distanceGrade=-ChordSettings.instance().getFingeringGrade()/4*maxCount; if (min<=5) distanceGrade*=1.8; break; default : distanceGrade=-ChordSettings.instance().getFingeringGrade()*maxCount; break; } finalGrade += distanceGrade; // ============== finger position abstraction ================== // TODO: what to do with e.g. chord -35556 (C7) // ... it can be held with capo on 5th fret, but very hard :) // ... This is the same as with "capo after", I didn't consider that (e.g. chord -35555) ArrayList[] fingers={new ArrayList(2),new ArrayList(2),new ArrayList(2),new ArrayList(2)}; // TODO: still no thumb, sorry :) // STRUCTURE: ArrayList consists of Integers - first is fret // - others are strings /* for (int i=0; i<this.tuning.length; i++) System.out.print(" "+positions[i]); System.out.println(""); */ // if chord is open, then we can have capo only in strings before open string int lastZeroIndex = 0; if (zeroString) for (int i=0; i<positions.length; i++) if (positions[i]==0) lastZeroIndex=i; // open or not not open chord, // index finger is always on lowest fret possible fingers[0].add(new Integer(min)); for (int i=lastZeroIndex; i<positions.length; i++) if (positions[i]==min) { fingers[0].add(new Integer(i)); positions[i]=-1; } // other fingers // if not zero-fret, occupy fingers respectivly int finger=1; for (int i=0; i<positions.length; i++) { if (positions[i]!=0 && positions[i]!=-1) { if (finger<4) { fingers[finger].add(new Integer(positions[i])); fingers[finger].add(new Integer(i)); positions[i]=-1; } finger++; } } /* System.out.println("Positions:"); for (int i=0; i<4; i++) { if (fingers[i].size()>1) System.out.print("G"+(i+1)+"R"+((Integer)fingers[i].get(0)).intValue()+"S"+((Integer)fingers[i].get(1)).intValue()+" "); } */ if (finger>4) finalGrade-=ChordSettings.instance().getFingeringGrade(); else finalGrade+=ChordSettings.instance().getFingeringGrade()*0.1*(15-2*finger); // TODO: maybe to put each finger's distance from the minimum return finalGrade; } // ------------------------------------------------------ /** * grades the chord semantics, based on theory. * * Tone semantics is good if:<br> * - there appear tones from chord basis or bass tone<br> * - there appear alteration tones on their specific places<br><br> * * Algorithm:<br> * - search for chord tonic. If some note is found before (and it's not bass) do penalty<br> * - make penalty if the bass tone is not in bass<br> * - check if all the expanding notes are here. If some are not, do penalty<br> * - if expanding note isn't higher than tonic octave, then priority should be less<br> * - If there are not some with NON_ESSENTIAL_INDEX are not here, penalty should be less<br> */ private float combinationChordSemantics(ArrayList stringValueCombination) { if(!isValidProcess()){ return 0; } float finalGrade = 0; int foundTonic = -1; int[] foundExpanding = new int[this.expandingNotes.length]; int stringDepth=0; for (int string = 0; string < this.tuning.length; string++) { // we have to go string-by-string because of the octave Iterator it = stringValueCombination.iterator(); StringValue current = null; boolean found=false; while (it.hasNext() && !found) { StringValue sv = (StringValue) it.next(); if (sv.string == string &&!found && sv.fret!=-1) { // stumbled upon next string current = sv; found=true; stringDepth++; } } // grade algorithms---- if (current != null) { // search for tonic if (foundTonic==-1 && current.requiredNoteIndex==0) foundTonic=this.tuning[current.string]+current.fret; // specific bass not in bass? if (stringDepth>1) { if (current.requiredNoteIndex==this.BASS_INDEX) finalGrade -= ChordSettings.instance().getGoodChordSemanticsGrade(); if (current.requiredNoteIndex<0) { // expanding tones // expanding tone found before the tonic if (foundTonic==-1) finalGrade -= ChordSettings.instance().getGoodChordSemanticsGrade()/2; else { // if expanding note isn't higher than tonic's octave if (foundTonic+11 > this.tuning[current.string]+current.fret) finalGrade -= ChordSettings.instance().getGoodChordSemanticsGrade()/3; } // search for distinct expanding notes for (int i=0; i<this.expandingNotes.length; i++) if ((this.tuning[string]+current.fret)%12==(this.chordTonic+this.expandingNotes[i]-1)%12) if (foundExpanding[i]==0) foundExpanding[i]=current.requiredNoteIndex; } } } } // penalties for not founding an expanding note if (this.alteration!=0) { int essentials=0, nonEssentials=0; for (int i=0; i<foundExpanding.length; i++) { if (foundExpanding[i]==this.ESSENTIAL_INDEX) essentials++; else if (foundExpanding[i]!=0) nonEssentials++; } if (essentials+nonEssentials==this.expandingNotes.length) finalGrade+=ChordSettings.instance().getGoodChordSemanticsGrade(); else { if (essentials==2) // if all essentials are there, it's good enough finalGrade+=ChordSettings.instance().getGoodChordSemanticsGrade()/2; // but if some are missing, that's BAD: else { finalGrade+= (essentials+nonEssentials-this.expandingNotes.length)*ChordSettings.instance().getGoodChordSemanticsGrade(); // half of the penalty for non-essential notes finalGrade+= nonEssentials*ChordSettings.instance().getGoodChordSemanticsGrade()/2; } } } return finalGrade; } // ------------------------------------------------------ /** * If current StringValue is a subset or superset of already better ranked * chords, it shouldn't be put inside, because it is duplicate. * @param stringValues current StringValue to be examined * @param betterOnes ArrayList of already stored StringList chords * @return true if it is duplicate, false if it is unique */ private boolean checkIfSubset(List stringValues, List betterOnes) { if(!isValidProcess()){ return false; } Iterator it = betterOnes.iterator(); while (it.hasNext()) { List currentStringValue = (List)it.next(); boolean foundDifferentFret = false; // repeat until gone through all strings, or found something different for (int i=0; i<currentStringValue.size(); i++) { int currentString = ((ChordCreatorUtil.StringValue)currentStringValue.get(i)).string ; // search for the same string - if not found do nothing for (int j=0; j<stringValues.size(); j++) if ( ((ChordCreatorUtil.StringValue)stringValues.get(j)).string == currentString) { // if the frets on the same string differ, then chords are not subset/superset of each other if (((ChordCreatorUtil.StringValue)stringValues.get(j)).fret != ((ChordCreatorUtil.StringValue)currentStringValue.get(i)).fret) foundDifferentFret=true; } } if (!foundDifferentFret)// nothing is different return true; } return false; } // ------------------------------------------------------ /** Calculates approximation of finger positions <br> * It is important to decide the position of the index finger * and then see what we can do with the rest of the fingers * * @param positions Simple integer array which consists of fret value for each string. Value -1 is for empty string * @param returnList Defined empty list where return data will be stored * @return Grade of fingering used in combinationHasGoodFingering */ //Commented only to fix the warning: "never used locally" /* private float whatToDoWithFingers(int[] positions, List returnList) { if(!isValidProcess()){ return 0; } // TODO I should have an algorithm in combinationHasGoodFingering, but it is more // ... elegant to define it there, I would use a lot of code already executed // This can be later used to display fingering on the ChordEditor return 0; } */ // -------------------------------------------------------------- // -------------------------------------------------------------- // -------------------------------------------------------------- /** * contains information about the note: string, fret and tone function in a * chord * * @author julian * */ private class StringValue { protected int string; protected int fret; protected int requiredNoteIndex; public StringValue(int string, int fret, int requiredNoteIndex) { this.string = string; this.fret = fret; this.requiredNoteIndex = requiredNoteIndex; } public int getString() { return this.string; } public void setString(int string) { this.string = string; } public int getFret() { return this.fret; } public void setFret(int fret) { this.fret = fret; } public int getRequiredNoteIndex() { return this.requiredNoteIndex; } public void setRequiredNoteIndex(int requiredNoteIndex) { this.requiredNoteIndex = requiredNoteIndex; } } // -------------------------------------------------------------- /** used just to sort StringValue ArrayLists by priorities */ protected class PriorityItem { ArrayList stringValues; float priority; } // -------------------------------------------------------------- /** used to sort the array */ protected class PriorityComparator implements Comparator { public int compare(Object o1, Object o2) { return Math.round(((PriorityItem) o2).priority - ((PriorityItem) o1).priority); } } }

The table below shows all metrics for ChordCreatorUtil.java.

MetricValueDescription
BLOCKS120.00Number of blocks
BLOCK_COMMENT82.00Number of block comment lines
COMMENTS427.00Comment lines
COMMENT_DENSITY 0.79Comment density
COMPARISONS167.00Number of comparison operators
CYCLOMATIC209.00Cyclomatic complexity
DECL_COMMENTS62.00Comments in declarations
DOC_COMMENT197.00Number of javadoc comment lines
ELOC541.00Effective lines of code
EXEC_COMMENTS79.00Comments in executable code
EXITS74.00Procedure exits
FUNCTIONS32.00Number of function declarations
HALSTEAD_DIFFICULTY140.59Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY114.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 3.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003446.00JAVA0034 Missing braces in if statement
JAVA003513.00JAVA0035 Missing braces in for statement
JAVA0036 1.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 3.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 6.00JAVA0075 Method parameter hides field
JAVA007625.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 2.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010813.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 2.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 7.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 1.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011711.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 1.00JAVA0128 Public constructor in non-public class
JAVA0130 2.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 1.00JAVA0137 Non-abstract class missing constructor
JAVA0138 2.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA014411.00JAVA0144 Line exceeds maximum M characters
JAVA01453097.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 1.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 3.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA025413.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 1.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1419.00Number of lines in the source file
LINE_COMMENT148.00Number of line comments
LOC670.00Lines of code
LOGICAL_LINES371.00Number of statements
LOOPS44.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1584.00Number of operands
OPERATORS3468.00Number of operators
PARAMS55.00Number of formal parameter declarations
PROGRAM_LENGTH5052.00Halstead program length
PROGRAM_VOCAB398.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS59.00Number of return points from functions
SIZE39884.00Size of the file in bytes
UNIQUE_OPERANDS338.00Number of unique operands
UNIQUE_OPERATORS60.00Number of unique operators
WHITESPACE322.00Number of whitespace lines