Skip to content

Commit

Permalink
fix minor problem, but wasn't able to repo in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Apr 21, 2017
1 parent aa9157b commit cbd8f28
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.github.sanity'
version '0.2.5'
version '0.2.6'

buildscript {
ext.kotlin_version = '1.1.1'
Expand Down
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ if [ -n "$JAVA_HOME" ] ; then
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
Please set the JAVA_HOME variable in your environment to render the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
Please set the JAVA_HOME variable in your environment to render the
location of your Java installation."
fi

Expand Down
8 changes: 4 additions & 4 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
@rem Set local scope for the variables from windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
Expand All @@ -26,7 +26,7 @@ if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo Please set the JAVA_HOME variable in your environment to render the
echo location of your Java installation.

goto fail
Expand All @@ -40,7 +40,7 @@ if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo Please set the JAVA_HOME variable in your environment to render the
echo location of your Java installation.

goto fail
Expand Down Expand Up @@ -69,7 +69,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
@rem End local scope for the variables from windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/com/github/sanity/shoebox/OrderedViewSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class OrderedViewSet<T : Any>(val view : View<T>, val viewKey : String, val comp

init {
val ol = ArrayList<KeyValue<T>>()
val kvComparator : Comparator<KeyValue<T>> = Comparator<KeyValue<T>> { o1, o2 -> comparator.compare(o1.value, o2.value) }
val kvComparator : Comparator<KeyValue<T>> = Comparator<KeyValue<T>> { o1, o2 -> comparator.thenBy { o1.key.compareTo(o2.key) }.compare(o1.value, o2.value) }
ol.addAll(view.getKeyValues(viewKey))
ol.sortWith(kvComparator)
orderedList = ol
additionHandle = view.onAdd(viewKey) { keyValue ->
val binarySearchResult = orderedList.betterBinarySearch(keyValue, kvComparator)
val insertionPoint: Int = when (binarySearchResult) {
is BinarySearchResult.Exact -> throw RuntimeException("Listener called for value already in list ($keyValue)")
is BinarySearchResult.Exact -> {
throw RuntimeException("Listener called for key/value already in list ($keyValue)")
}
is BinarySearchResult.Between -> binarySearchResult.highIndex
}
ol.add(insertionPoint, keyValue)
Expand Down
15 changes: 15 additions & 0 deletions src/test/kotlin/com/github/sanity/shoebox/OrderedViewSetSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ class OrderedViewSetSpec : FreeSpec() {
}
}

" when a second value is added that is not distinguishable based on the supplied comparator" {
val userMap = Shoebox<User>(MemoryStore())
userMap["jack"] = User("Jack", Gender.MALE)
userMap["jill"] = User("Jill", Gender.FEMALE)
val viewByGender = View(Shoebox(MemoryStore()), viewOf = userMap, viewBy = { it.gender.toString() })

val maleViewSet = OrderedViewSet<User>(viewByGender, "MALE", compareBy(User::name))

maleViewSet.onInsert { p, kv ->

}

userMap["paul"] = User("Paul", Gender.MALE)
}

"should detect a value reorder" - {
val userMap = Shoebox<User>(MemoryStore())
val jackUser = User("Jack", Gender.MALE)
Expand Down

0 comments on commit cbd8f28

Please sign in to comment.