Skip to content

nfrancois/papaya

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Papaya

Papaya

Papaya is a commons librairies for Dart inspired a lot by Guava. It provides help to write :

  • hashCode / == / toString methods

Build Status

Papaya is distributed under the Apache 2.0 License.

Getting Started

Create a Dart project and add a pubspec.yaml file to it

dependencies:
  papaya: any

and run

pub install

Samples

hashCode / == / toString methods

import 'package:papaya/papaya.dart';

main() {
  var john = new Person("John", 25);
  var unknown = new Person(null, 37);
  
  // 1495571744
  print(john.hashCode);
  // 998
  print(unknown.hashCode);
 
  // Person{name=John, age=25}
  print(john);
  // Person{name=null, age=37}
  print(unknown);
  // Person{age=37}
  print(unknown.alternativeToString());
  
  // false
  print(john == unknown);
}



class Person {
  
  String name;
  int age;
  
  Person(this.name, this.age);
  
  int get hashCode => hashcode([name, age]);
  
  bool operator==(other) =>
    identical(other, this) 
      || (equal(name, other.name) && equal(age, other.age));
  
  String toString() => 
  	toStringHelper(this.runtimeType).add("name", name)
  	.add("age", age).toString();
  
  String alternativeToString() => 
    toStringHelper(this.runtimeType).omitNullValues()
    .add("name", name).add("age", age).toString();
  
}

About

A dart commons library inspired by Guava

Resources

License

Stars

Watchers

Forks

Packages

No packages published