Merge pull request #296 from mhshams/master

KT-3715 make Collection.notEmpty a property
This commit is contained in:
Alexander Udalov
2013-08-20 02:05:19 -07:00
10 changed files with 18 additions and 14 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ public inline fun String.matches(regex : String) : Boolean {
* @includeFunctionBody ../../test/StringTest.kt capitalize
*/
public inline fun String.capitalize(): String {
return if (notEmpty()) substring(0, 1).toUpperCase() + substring(1) else this
return if (isNotEmpty()) substring(0, 1).toUpperCase() + substring(1) else this
}
/**
@@ -26,5 +26,5 @@ public inline fun String.capitalize(): String {
* @includeFunctionBody ../../test/StringTest.kt decapitalize
*/
public inline fun String.decapitalize(): String {
return if (notEmpty()) substring(0, 1).toLowerCase() + substring(1) else this
return if (isNotEmpty()) substring(0, 1).toLowerCase() + substring(1) else this
}
+1 -1
View File
@@ -1,7 +1,7 @@
package kotlin
/** Returns true if the array is not empty */
public inline fun <T> Array<T>.notEmpty() : Boolean = !this.isEmpty()
public inline fun <T> Array<T>.isNotEmpty() : Boolean = !this.isEmpty()
/** Returns true if the array is empty */
public inline fun <T> Array<T>.isEmpty() : Boolean = this.size == 0
+5 -1
View File
@@ -17,7 +17,11 @@ val Int.indices: IntRange
get() = 0..this-1
/** Returns true if the collection is not empty */
public inline fun <T> Collection<T>.notEmpty() : Boolean = !this.isEmpty()
public inline fun <T> Collection<T>.isNotEmpty() : Boolean = !this.isEmpty()
/** Returns true if this collection is not empty */
val Collection<*>.notEmpty : Boolean
get() = isNotEmpty()
/** Returns the Collection if its not null otherwise it returns the empty list */
public inline fun <T> Collection<T>?.orEmpty() : Collection<T>
+1 -1
View File
@@ -30,7 +30,7 @@ public inline fun String.trimTrailing(postfix: String): String {
}
/** Returns true if the string is not null and not empty */
public inline fun String?.notEmpty() : Boolean = this != null && this.length() > 0
public inline fun String?.isNotEmpty() : Boolean = this != null && this.length() > 0
/**
Iterator for characters of given CharSequence
+2 -2
View File
@@ -179,7 +179,7 @@ get() = length()
* @includeFunctionBody ../../test/StringTest.kt capitalize
*/
public inline fun String.capitalize(): String {
return if (notEmpty() && charAt(0).isLowerCase()) substring(0, 1).toUpperCase() + substring(1) else this
return if (isNotEmpty() && charAt(0).isLowerCase()) substring(0, 1).toUpperCase() + substring(1) else this
}
/**
@@ -188,7 +188,7 @@ public inline fun String.capitalize(): String {
* @includeFunctionBody ../../test/StringTest.kt decapitalize
*/
public inline fun String.decapitalize(): String {
return if (notEmpty() && charAt(0).isUpperCase()) substring(0, 1).toLowerCase() + substring(1) else this
return if (isNotEmpty() && charAt(0).isUpperCase()) substring(0, 1).toLowerCase() + substring(1) else this
}
/**
@@ -298,7 +298,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs
val scope = descriptor.getMemberScope()
addFunctions(pkg, scope)
pkg.local = isLocal(descriptor)
pkg.useExternalLink = pkg.model.config.resolveLink(pkg.name, false).notEmpty()
pkg.useExternalLink = pkg.model.config.resolveLink(pkg.name, false).isNotEmpty()
if (pkg.wikiDescription.isEmpty()) {
// lets try find a custom doc
@@ -134,7 +134,7 @@ abstract class KDocTemplate() : TextTemplate() {
return if (c != null) {
val prefix = if (c.isAnnotation()) "@" else ""
val cname = c.name
if ((cname.startsWith("jet.Function") || cname.startsWith("jet.ExtensionFunction")) && arguments.notEmpty()) {
if ((cname.startsWith("jet.Function") || cname.startsWith("jet.ExtensionFunction")) && arguments.isNotEmpty()) {
val rt = arguments.last()
// TODO use drop()
val rest = arguments.subList(0, arguments.size - 1).orEmpty()
@@ -103,7 +103,7 @@ ${stylesheets()}
}
protected fun printPackageProperties(): Unit {
val list = pkg.packageProperties()
if (list.notEmpty()) {
if (list.isNotEmpty()) {
println("""<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
<TR>
<TD NOWRAP><FONT size="+1" CLASS="FrameHeadingFont">Properties</FONT>&nbsp;
@@ -17,7 +17,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
protected fun keyword(name: String): String = "<B>$name</B>"
fun printFunctionSummary(functions: Collection<KFunction>): Unit {
if (functions.notEmpty()) {
if (functions.isNotEmpty()) {
println("""<!-- ========== FUNCTION SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
@@ -90,7 +90,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
}
fun printFunctionDetail(functions: Collection<KFunction>): Unit {
if (functions.notEmpty()) {
if (functions.isNotEmpty()) {
println("""
<!-- ============ FUNCTION DETAIL ========== -->
@@ -159,7 +159,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
}
fun printPropertySummary(properties: Collection<KProperty>): Unit {
if (properties.notEmpty()) {
if (properties.isNotEmpty()) {
println("""<!-- ========== PROPERTY SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
@@ -150,7 +150,7 @@ import js.noImpl
}
val fields = klass.getDeclaredFields()
if (fields != null) {
if (fields.notEmpty()) {
if (fields.isNotEmpty()) {
println("")
println(" public class object {")
for (field in fields) {