-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
iuresti
committed
Apr 19, 2017
1 parent
1ebb025
commit 8b947a9
Showing
2 changed files
with
25 additions
and
28 deletions.
There are no files selected for viewing
29 changes: 15 additions & 14 deletions
29
...main/java/devslp/designpatterns/TemplateMethod/SortStrategyExample/DoubleSortHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
package devslp.designpatterns.TemplateMethod.SortStrategyExample; | ||
|
||
public class DoubleSortHandler implements SortHandler { | ||
private double [] array; | ||
private Double[] array; | ||
|
||
public void setArray(Object [] theArray) | ||
{ | ||
array = new double[theArray.length]; | ||
for (int i = 0; i < theArray.length ; i++) { | ||
array[i] = (double)theArray[i]; | ||
} | ||
public void setArray(Object[] theArray) { | ||
array = new Double[theArray.length]; | ||
|
||
System.arraycopy(theArray, 0, array, 0, theArray.length); | ||
} | ||
|
||
@Override | ||
public Object[] getArray() { | ||
return array; | ||
} | ||
|
||
public int getLength() | ||
{ | ||
public int getLength() { | ||
return array.length; | ||
} | ||
|
||
public boolean outOfOrder(int index) { | ||
return (array[index-1] > array[index]); | ||
return (array[index - 1] > array[index]); | ||
} | ||
|
||
public void swap(int index) | ||
{ | ||
double temp = array[index-1]; | ||
array[index-1] = array[index]; | ||
public void swap(int index) { | ||
double temp = array[index - 1]; | ||
array[index - 1] = array[index]; | ||
array[index] = temp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters