From 36dd874c27c241e20615079d1757b78a6761926a Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 19 Nov 2013 15:21:01 +0400 Subject: [PATCH] coreLib and Java collections utilities --- .../src/org/jetbrains/jet/utils/coreLib.kt | 24 +++++++++++++++++++ .../jetbrains/jet/utils/javaCollections.kt | 10 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 core/util.runtime/src/org/jetbrains/jet/utils/coreLib.kt create mode 100644 core/util.runtime/src/org/jetbrains/jet/utils/javaCollections.kt diff --git a/core/util.runtime/src/org/jetbrains/jet/utils/coreLib.kt b/core/util.runtime/src/org/jetbrains/jet/utils/coreLib.kt new file mode 100644 index 00000000000..5a4922cabc3 --- /dev/null +++ b/core/util.runtime/src/org/jetbrains/jet/utils/coreLib.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.util + +fun Boolean.iif(then: T, _else: T): T = if (this) then else _else + +// These two functions are needed in conjunction with iif: +// foo.eq(bar).iif(a, b) +fun T.eq(eq: T): Boolean = this == eq +fun T.neq(eq: T): Boolean = this != eq \ No newline at end of file diff --git a/core/util.runtime/src/org/jetbrains/jet/utils/javaCollections.kt b/core/util.runtime/src/org/jetbrains/jet/utils/javaCollections.kt new file mode 100644 index 00000000000..8d0f37b6eb6 --- /dev/null +++ b/core/util.runtime/src/org/jetbrains/jet/utils/javaCollections.kt @@ -0,0 +1,10 @@ +package org.jetbrains.jet.utils + +import java.util.Collections + +public fun emptyList(): MutableList = Collections.emptyList() as MutableList +public fun emptyOrSingletonList(item: T?): MutableList = if (item == null) emptyList() else Collections.singletonList(item) as MutableList + +public fun emptySet(): MutableSet = Collections.emptySet() as MutableSet +public fun emptyMap(): MutableMap = Collections.emptyMap() as MutableMap +