Skip to content

Instantly share code, notes, and snippets.

package org.geepawhill.contentment.flow;
import static org.geepawhill.contentment.utility.JfxUtility.color;
import java.util.HashMap;
import java.util.Map;
import org.geepawhill.contentment.format.Format;
import org.geepawhill.contentment.style.Frames;
import org.geepawhill.contentment.style.TypeFace;
@GeePawHill
GeePawHill / Box.java
Created April 3, 2018 02:33
A real-world TDD "what to do?"
/* This is the Box. Note that it's extremely similar to the Stroke, essentially only changing Stroke's behavior by making it
four-way instead of one-way. I see no other way to code it without re-factoring the four-level tree.
This is simple. I haven't run it yet, but I bet it runs.
Should I have tested it? The expense of testing it *without* the factoring is dauntingly high. The factoring is on the agenda, and
I know how to do it. But it will take a good deal of work, as Stroke and Box are part of a half-dozen entries at their level of the
tree, with another half-dozen at the third, and a good dozen at the fourth. (The top level isn't shown, and is actually the most
rational and composite-like.)
*/
package org.geepawhill.contentment.fragments;
import static org.assertj.core.api.Assertions.assertThat;
import org.geepawhill.contentment.core.Context;
import org.geepawhill.contentment.rhythm.SimpleRhythm;
import org.junit.*;
public class SyncTest
{
package org.geepawhill.contentment.fragments;
import org.geepawhill.contentment.core.*;
import javafx.scene.Group;
/**
* Makes a group and adds it to the destination, making it available via get for later
* manipulators.
*
longMethod( int y ) {
int x;
x = 0;
// ...
// IRRELEVANCY #0: 87 lines that neither read nor write x
// ...
if( y == 17 ) {
x = 1;
}
// ...
package org.geepawhill.tsd.core
interface TsdWriter {
class IllegalKeyException(key: String, message: String) : RuntimeException("'$key' is not a legal tsd key, (${message}).")
class UnknownKeyException(key: String) : RuntimeException("`$key` not found in TSD")
operator fun set(key: String, value: String)
operator fun <T> set(key: String, value: T)
operator fun set(key: String, value: Tsd)
operator fun <T> set(key: String, collection: Collection<T>)
package org.geepawhill.contentment.jfx
import javafx.beans.property.Property
import javafx.beans.property.ReadOnlyProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue
import javafx.collections.ObservableList
import javafx.scene.transform.Scale
import javafx.scene.transform.Transform
package org.geepawhill.contentment.geometry
import javafx.beans.property.SimpleDoubleProperty
import tornadofx.*
class AspectRatio {
val widthToHeightProperty = SimpleDoubleProperty(16.0 / 9.0)
var widthToHeight by widthToHeightProperty
val hostWidthProperty = SimpleDoubleProperty(0.0)
class ... : View() {
val rollProperty = SimpleStringProperty("My Dynamic String") // This doesn't have to be in the View class, it could be anywhere, like in the Model.
// But it can *not* be a String.
root = hbox {
label(rollProperty)
}
fun changeString(newValue:String)
class SparseGrid<T>(val width: Int, val height: Int, val default: () -> T) {
class IllegalCoordsException(coords: Coords) : RuntimeException("Illegal coordinates in SparseGrid $coords.")
private val coordsToContents = mutableMapOf<Coords, T>()
operator fun get(x: Int, y: Int): T = get(Coords(x, y))
operator fun get(coords: Coords) = coordsToContents.getOrDefault(validate(coords), default())
operator fun set(x: Int, y: Int, value: T) = set(Coords(x, y), value)