papaya 0.0.1+2 copy "papaya: ^0.0.1+2" to clipboard
papaya: ^0.0.1+2 copied to clipboard

Dart 1 only

Commons library inspired by Guava

#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();
  
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Commons library inspired by Guava

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on papaya