class Ed25519GroupElement implements Serializable {

  public Ed25519EncodedGroupElement encode() {
    switch (this.coordinateSystem) {
      case P2:
      case P3:
        final Ed25519FieldElement inverse = this.z.invert();
        final Ed25519FieldElement xElement = this.x.multiply(inverse);
        final Ed25519FieldElement yElement = this.y.multiply(inverse);
        final byte[] s = yElement.encode().getRaw();
        s[s.length - 1] |= (xElement.isNegative() ? (byte) 0x80 : 0);

        return new Ed25519EncodedGroupElement(s);
      default:
        return this.toP2().encode();
    }
  }

  public  Ed25519GroupElement(
      final CoordinateSystem coordinateSystem,
      final Ed25519FieldElement x,
      final Ed25519FieldElement y,
      final Ed25519FieldElement z,
      final Ed25519FieldElement t);

}