Skip to content

Commit

Permalink
Feature: added the casting feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokk committed Jul 21, 2018
1 parent 72d95a1 commit 2167439
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The library has util tools as below:
6. String
7. Thread
8. Time
9. Casting

# NOTE

Expand Down Expand Up @@ -87,9 +88,9 @@ allprojects {
And add our dependency to your app `bundle.gradle`.

```gradle
implementation 'com.devrapid.jieyi:kotlinknifer:1.5.7'
implementation 'com.devrapid.jieyi:kotlinknifer:2.0.1'
implementation 'com.devrapid.jieyi:kotlinshaver:0.2.2'
implementation 'com.devrapid.jieyi:kotlinshaver:1.0.1'
```

Then you can use it!!!
Expand All @@ -100,14 +101,14 @@ Then you can use it!!!
<dependency>
<groupId>com.devrapid.jieyi</groupId>
<artifactId>kotlinknifer</artifactId>
<version>1.5.7</version>
<version>2.0.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.devrapid.jieyi</groupId>
<artifactId>kotlinshaver</artifactId>
<version>0.2.2</version>
<version>1.0.1</version>
<type>pom</type>
</dependency>
```
Expand All @@ -120,23 +121,15 @@ Then you can use it!!!
2. Glide 4.6.1

## kotlinshaver
### For Androidx

1. RxJava 2.1.10
2. RxKotlin 2.2.0

If you'd not like to use them to your project, you can add the exclude as like below

```gradle
implementation('com.devrapid.jieyi:kotlinknifer:1.5.7', {
exclude group: 'com.google.code.gson', module: 'gson'
exclude group: 'com.github.bumptech.glide', module: 'glide'
})
```

### For Androidx

```gradle
implementation('com.devrapid.jieyi:kotlinknifer:2.0.0', {
implementation('com.devrapid.jieyi:kotlinknifer:2.0.1', {
exclude group: 'com.google.code.gson', module: 'gson'
exclude group: 'com.github.bumptech.glide', module: 'glide'
})
Expand All @@ -159,7 +152,7 @@ Please let me know, thank you!
# License

```
Copyright (C) 2017 Jieyi Wu
Copyright (C) 2018 Jieyi Wu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ proj_name=kotlinknifer
proj_libname=KotlinKnifer
proj_group=com.devrapid.jieyi
proj_artifactid=kotlinknifer
proj_version=2.0.0
proj_version=2.0.1
proj_description=For developing an Android conveniently and rapidly.
proj_websiteurl=https://github.com/pokk/KotlinKnifer
proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues
Expand All @@ -39,4 +39,4 @@ [email protected]
proj_kotlin_name=kotlinshaver
proj_kotlin_libname=KotlinShaver
proj_kotlin_artifactid=kotlinshaver
proj_kotlin_version=1.0.0
proj_kotlin_version=1.0.1
13 changes: 13 additions & 0 deletions kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.devrapid.kotlinshaver

inline fun <reified T> castOrNull(from: Any?) = from as? T
inline fun <reified T> cast(from: Any?): T {
if (null == from) throw NullPointerException("Null object can't cast.")

try {
return T::class.java.cast(from)
}
catch (castExcept: ClassCastException) {
throw ClassCastException("Class casting failed.")
}
}

0 comments on commit 2167439

Please sign in to comment.