SchemaVersion { public static Optional<SchemaVersion> latest(Iterable<SchemaVersion> schemas) { return StreamSupport.stream(schemas.spliterator(), false).filter(s -> !s.isDeleted()).max( (s1, s2) -> s1.version - s2.version); } @JsonCreator  SchemaVersion(
      @JsonProperty("schema") Schema schema,
      @JsonProperty("version") int version,
      @JsonProperty("deleted") boolean deleted); static Optional<SchemaVersion> latest(Iterable<SchemaVersion> schemas); static Optional<SchemaVersion> version(Iterable<SchemaVersion> schemas, int version);  }
@Test public void latest() { SchemaVersion schemaVersion1 = new SchemaVersion(null, 1, false); SchemaVersion schemaVersion2 = new SchemaVersion(null, 2, false); Optional<SchemaVersion> result = SchemaVersion.latest(Arrays.asList(schemaVersion1, schemaVersion2)); assertThat(result.isPresent(), is(true)); assertThat(result.get().getVersion(), is(2)); }
@Test public void latestDeleted() { SchemaVersion schemaVersion1 = new SchemaVersion(null, 1, false); SchemaVersion schemaVersion2 = new SchemaVersion(null, 2, true); Optional<SchemaVersion> result = SchemaVersion.latest(Arrays.asList(schemaVersion1, schemaVersion2)); assertThat(result.isPresent(), is(true)); assertThat(result.get().getVersion(), is(1)); }
@Test public void latestAllDeleted() { SchemaVersion schemaVersion1 = new SchemaVersion(null, 1, true); SchemaVersion schemaVersion2 = new SchemaVersion(null, 2, true); Optional<SchemaVersion> result = SchemaVersion.latest(Arrays.asList(schemaVersion1, schemaVersion2)); assertThat(result.isPresent(), is(false)); }