-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make Date equalable, clonable and comparable
- Loading branch information
Showing
7 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <bastie@users.noreply.github.com> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
extension ComparableJ { | ||
|
||
public static func <= (lhs: Self, rhs: Self) -> Bool { | ||
if lhs == rhs { | ||
return true | ||
} | ||
return lhs < rhs | ||
} | ||
|
||
public static func >= (lhs: Self, rhs: Self) -> Bool { | ||
if lhs == rhs { | ||
return true | ||
} | ||
return lhs > rhs | ||
} | ||
|
||
public static func > (lhs: Self, rhs: Self) -> Bool { | ||
return try! lhs.compareTo((rhs as! Self.ComparableJ)) > 0 | ||
} | ||
|
||
public static func < (lhs: Self, rhs: Self) -> Bool { | ||
return try! lhs.compareTo((rhs as! Self.ComparableJ)) < 0 | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <bastie@users.noreply.github.com> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
/// `Comparable` type in Java | ||
public protocol ComparableJ : Comparable { | ||
|
||
func compareTo (_ other : ComparableJ?) throws -> Int | ||
|
||
associatedtype ComparableJ : java.lang.Comparable | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <bastie@users.noreply.github.com> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension java.util.Date : Cloneable { | ||
public func clone() throws -> java.util.Date { | ||
let copy = java.util.Date() | ||
copy.delegate = self.delegate | ||
return copy | ||
} | ||
|
||
public typealias Cloneable = java.util.Date | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <bastie@users.noreply.github.com> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension java.util.Date : ComparableJ { | ||
|
||
public func compareTo(_ other: java.util.Date?) throws -> Int { | ||
if let other { | ||
if self.delegate > other.delegate { | ||
return 1 | ||
} | ||
else { | ||
if self.delegate < other.delegate { | ||
return -1 | ||
} | ||
else { | ||
return 0 | ||
} | ||
} | ||
} | ||
else { | ||
throw Throwable.NullPointerException() | ||
} | ||
} | ||
|
||
|
||
public typealias Comparable = java.util.Date | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <bastie@users.noreply.github.com> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension java.util.Date : Equatable { | ||
public static func == (lhs: java.util.Date, rhs: java.util.Date) -> Bool { | ||
return lhs.delegate == rhs.delegate | ||
} | ||
} |
This file contains 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