Last active
August 29, 2015 14:02
-
-
Save yogurtearl/894050af6fbbdf3c6b0e to your computer and use it in GitHub Desktop.
Readable method invocation
This file contains hidden or 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
// Good idea or Bad idea? | |
// Lets say you have to call some API with lots of parameters that you don't control | |
// Like this http://developer.android.com/reference/android/text/StaticLayout.html#StaticLayout(java.lang.CharSequence, int, int, android.text.TextPaint, int, android.text.Layout.Alignment, float, float, boolean, android.text.TextUtils.TruncateAt, int) | |
// Do you prefer Option #1 or Option #2? Is Option #2 a terrible idea? | |
// I suppose Option #3 could be to wrap it in a Builder | |
class Foo { | |
void draw() { | |
new StaticLayout( | |
"text", | |
2, | |
4, | |
new TextPaint(), | |
450, | |
Layout.Alignment.ALIGN_CENTER, | |
4.5f, | |
2, | |
false, | |
TextUtils.TruncateAt.END, | |
34 | |
); | |
// option #1 | |
final String source = "text"; | |
final int bufstart = 2; | |
final int bufend = 4; | |
final int outerwidth = 450; | |
final float spacingmult = 4.5f; | |
final int spacingadd = 2; | |
final boolean includepad = false; | |
final int ellipsizedWidth = 34; | |
new StaticLayout( | |
source, | |
bufstart, | |
bufend, | |
new TextPaint(), | |
outerwidth, | |
Layout.Alignment.ALIGN_CENTER, | |
spacingmult, | |
spacingadd, | |
includepad, | |
TextUtils.TruncateAt.END, | |
ellipsizedWidth | |
); | |
// option #2 | |
new StaticLayout( | |
source("text"), | |
bufferStart(2), | |
bufferStop(4), | |
new TextPaint(), | |
outerWidth(450), | |
Layout.Alignment.ALIGN_CENTER, | |
spacingMultplier(4.5f), | |
spacingAdding(2), | |
dontIncludePadding(), | |
TextUtils.TruncateAt.END, | |
ellipsizedWidth(34) | |
); | |
} | |
private int ellipsizedWidth(final int i) { | |
return i; | |
} | |
private boolean dontIncludePadding() { | |
return false; | |
} | |
private float spacingAdding(final int i) { | |
return 0; | |
} | |
private float spacingMultplier(final float v) { | |
return v; | |
} | |
private int outerWidth(final int i) { | |
return i; | |
} | |
private int bufferStop(final int i) { | |
return i; | |
} | |
private int bufferStart(final int i) { | |
return i; | |
} | |
private String source(final String text) { | |
return text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment