Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions .idea/$PRODUCT_WORKSPACE_FILE$

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions PlaylistChallenge.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" />
</component>
</module>
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
</dependencies>
</project>
136 changes: 133 additions & 3 deletions src/main/java/io/zipcoder/Music.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,144 @@
package io.zipcoder;
import org.apache.commons.lang3.ArrayUtils;
import java.lang.Math;
import java.lang.reflect.Array;


public class Music {

private String[] playList;

public Music(String[] playList){
public Music(String[] playList) {
this.playList = playList;
}

public Integer selection(Integer startIndex, String selection){
return null;
public Integer selection(Integer startIndex, String selection) {



int fwdCount = 0;
int bwdCount = 0;

int newSongIndex = ArrayUtils.indexOf(playList, selection);

if (newSongIndex > startIndex)
{

}


for (int i = startIndex; i < playList.length; i++) {

if (playList[i].equals(selection))
{break;}

fwdCount++;

if(i == (playList.length-1))
{
i = -1; //because we have to include another click to go from the end to the beginning
}
}

for (int j = startIndex; j >= 0; j--) {
if (playList[j].equals(selection)) {
break;}
bwdCount++;
if (j == 0) {
j = playList.length; //because we have to do another click from the beginning back to the end.
}

}

if (bwdCount < fwdCount) {
return bwdCount;
} else {
return fwdCount;
}
}
}

// for (int j = startIndex; j < startIndex + playList.length - 1; j--) {
// if (!playList[playList.length + i % playList.length].equals(selection)) {
// bwdCount++;
// break;


//
// int newSongIndex = ArrayUtils.indexOf(playList, selection);
// int check = checkPlaylist(playList, startIndex, newSongIndex);
//
// int newSongIndex2 = checkForDuplicateIndex(playList, selection);
// //int newSongIndex2 = ArrayUtils.indexOf(playList, selection, newSongIndex);
// int check2 = checkPlaylist(playList, startIndex, newSongIndex2);
// int result = shorterClicks(check, check2);
//
//
// return result;
// }
//
// public int checkPlaylist (String[] playList, Integer startIndex, int newSongIndex)
// {
//
// int clicksFwd=0;
// int clicksBwd=0;
// int loopsAround=0;
// if (newSongIndex > startIndex)
// {
// clicksFwd = newSongIndex - startIndex;
// loopsAround = (startIndex) + ((playList.length) - newSongIndex+1);
//
// if (clicksFwd < loopsAround)
// {return clicksFwd;}
// else if (loopsAround < clicksFwd)
// {return loopsAround;}
//
// }
// else if (newSongIndex < startIndex)
// {
// clicksBwd = startIndex - newSongIndex;
// loopsAround= (newSongIndex) + ((playList.length)-startIndex);
// if (clicksBwd < loopsAround)
// {return clicksBwd;}
// else if (loopsAround < clicksBwd)
// {return loopsAround;}
// }
// return 0;
// }
// public int checkForDuplicateIndex (String[] playList, String selection)
// {
// int newSongIndex2=0;
//
// for (int i=playList.length-1; i>= 0; i--)
// {
//
// if(playList[i].equals(selection))
// {
// newSongIndex2 = i;
//
// return newSongIndex2;
//
// }
// }
//
//
// return newSongIndex2;
// }
//
// public int shorterClicks (int check, int check2)
// {
// if (check < check2)
// {
// return check;
// }
// else if (check2 < check)
// {
// return check2;
// }
// return check;
// }