This library is used to control an attribute if it comes to null

Overview

SAVE NULL EXTENSION

Download API Build Status Language ktlint Open Source Love License

ko-fi

This library is used to control an attribute if it comes to null, what it will do is remove that null and give it a default value. Ideal for dealing with business models where attributes can be nullable.

💥 Installation

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency:

dependencies {
	implementation "com.github.xavijimenezmulet:SaveNullExtensionKotlin:$last_version"
}

💻 Usage

If you have a class where null attributes can come. The library helps prevent them in a single line without having to check them. Let's add an example class:

data class Example(
    val byte: Byte?,
    val short: Short?,
    val int: Int?,
    val long: Long?,
    val float: Float?,
    val double: Double?,
    val char: Char?,
    val string: String?,
    val boolean: Boolean?,
    val list: List<String>?,
    val mutableList: MutableList<String>?,
    val array: Array<String>?
)

Now we are going to show an example of an extension, for example of string:

fun String?.saveNull(defaultValue: String = ""): String {
    return this ?: defaultValue
}

If we look at the extension it controls that a string can be nullable. If the string is not nullable, it returns the attribute itself. But on the contrary, if it is nullable, it will return the default value (By default it will be empty string). All extensions have a default value that we can modify to our liking if we want.

Now let's show an example with the "Example" class:

private fun initExample() {
  val example = Example()
  val text: String = example.string.saveNull("No available")
  textView.text = text
}

The value of "text" will always have a value. It can be the string attribute of the Example class if it is not null. If it is, we have added a default value that says "not available" so the textView will always show a result.

✔️ Changelog

Version: 1.0

  • Initial Build

License

APACHE LICENSE 2.0

You might also like...
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt

Motion An Android library allowing images to exhibit a parallax effect. By replacing static pictures and backgrounds with a fluid images that reacts t

Android library to easily serialize and cache your objects to disk using key/value pairs.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Form Validator Library for Android

Android-Validator Form Validator Library for Android [](https://flattr.com/submit/auto?user_id=throrin19&url=https://github.com/throrin19/Android-Vali

A simple library for validating user input in forms using annotations.
A simple library for validating user input in forms using annotations.

ValidationKomensky for Android A simple library for validating user input in forms using annotations. Features: Validate all views at once and show fe

Very easy to use wrapper library for Android SharePreferences

Treasure English document Treasure是一个Android平台上基于SharePreferences的偏好存储库,只需要定义接口,无需编写实现,默认支持Serializable和Parcelable。运行时0反射,不仅使用方便而且性能和原生写法几乎无差别。 使用方法 1

A small library which will save you from writing the same intent creation code again and again for the most simple tasks

Android Intents A small library which will save you from writing the same intent creation code again and again for the most simple tasks. I found myse

Error handling library for Android and Java

ErrorHandler Error handling library for Android and Java Encapsulate error handling logic into objects that adhere to configurable defaults. Then pass

Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app
Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app

DroidMVP About DroidMVP is a small Android library to help you incorporate the MVP pattern along with Passive View and Presentation Model (yes, those

A library to quickly and easily enable multiple monitoring & support platforms for your mobile apps

You have a small team. Setting up crash reporting tools, event tracking tools, and log management services is not what you want to spend your hours do

Releases(1.0.9)
Owner
Xavi
Xavi
Small utility used to add Homewizard Energy Socket tiles to Android Quick Settings

TileWizard [Alpha! Unstable!] Settings Result Functionality: Add up to 5 Wi-Fi Energy Sockets to Android Quick Settings. What do you need: Android dev

Niels Masdorp 2 Oct 19, 2021
Criminal-Intent - An android app used to record office crimes

What is Criminal Intent? CriminalIntent records the details of “office crimes” –

Mohammad Rashid 1 Feb 11, 2022
UE Capability parser used by smartphonecombo.it and cacombos.com

UE Capability Parser Warning Work In progress UE Capability parser used by smartphonecombo.it and cacombos.com $ java -jar uecapabilityparser.jar --he

Andrea Mennillo 4 Oct 16, 2022
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

Keepsafe 2.9k Dec 27, 2022
Joda-Time library with Android specialization

joda-time-android This library is a version of Joda-Time built with Android in mind. Why Joda-Time? Android has built-in date and time handling - why

Daniel Lew 2.6k Dec 9, 2022
UPnP/DLNA library for Java and Android

Cling EOL: This project is no longer actively maintained, code may be outdated. If you are interested in maintaining and developing this project, comm

4th Line 1.6k Jan 4, 2023
:iphone: [Android Library] Get device information in a super easy way.

EasyDeviceInfo Android library to get device information in a super easy way. The library is built for simplicity and approachability. It not only eli

Nishant Srivastava 1.7k Dec 22, 2022
A support library for VectorDrawable and AnimatedVectorDrawable classes introduced in Lollipop

vector-compat A support library for VectorDrawable and AnimatedVectorDrawable introduced in Lollipop with fully backwards compatible tint support (api

Wael N 1.2k Nov 29, 2022
Android library for viewing, editing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

Infinum 924 Jan 4, 2023
Android Market In-app Billing Library

Update In-app Billing v2 API is deprecated and will be shut down in January 2015. This library was developed for v2 a long time ago. If your app is st

Robot Media 533 Nov 25, 2022