yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Usability of new @Implement annotation #66

Closed dotWee closed 9 years ago

dotWee commented 9 years ago

Is there any example available for the new @Implement annotation? I'm searching for a way to implement a custom comparator into model specs.

sbosley commented 9 years ago

There's an example in the javadoc for @Implements. I've been meaning to add one to the wiki, just haven't gotten around to it yet. For implementing Comparable though:

@TableModelSpec(className = "Person", tableName = "people")
@Implements(interfaceDefinitions = {
    @Implements.InterfaceSpec(interfaceClass=Comparable.class,
        interfaceTypeArgNames="com.mypackage.Person")})
// This should generate class Person implements Comparable<Person>
public class PersonSpec {
    ...

    @ModelMethod // For implementing the interface method
    public static int compareTo(Person instance, Person other) {
        // Implement the comparison here
    }
}

Hope that helps!

dotWee commented 9 years ago

That helps a lot! Thank you very much!

sbosley commented 9 years ago

Sure thing! Maybe I'll just use that example for the wiki, it's a good one :)