Skip to content

Using bijection from java

johnynek edited this page Jan 12, 2013 · 3 revisions

Here's an example of implementing a bijection in Java:

    // This is not a mathematically correct bijection for all strings,
    // since only the subset of canonical representations of Long as valid inputs.
    // It is here only as a convenient example implementation
    public class StringToLong extends AbstractBijection<String,Long> {
        @Override
        public Long apply(String a) {
            return Long.parseLong(a);
        }

        @Override
        public String invert(Long b) {
            return b.toString();
        }
    }
Clone this wiki locally