SchemaVersion { public static Optional<SchemaVersion> version(Iterable<SchemaVersion> schemas, int version) { return StreamSupport.stream(schemas.spliterator(), false).filter(s -> s.version == version).findFirst(); } @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 version() { SchemaVersion schemaVersion1 = new SchemaVersion(null, 1, false); SchemaVersion schemaVersion2 = new SchemaVersion(null, 2, false); Optional<SchemaVersion> result = SchemaVersion.version(Arrays.asList(schemaVersion1, schemaVersion2), 1); assertThat(result.isPresent(), is(true)); assertThat(result.get().getVersion(), is(1)); }
@Test public void versionNotFound() { SchemaVersion schemaVersion1 = new SchemaVersion(null, 1, false); SchemaVersion schemaVersion2 = new SchemaVersion(null, 2, false); Optional<SchemaVersion> result = SchemaVersion.version(Arrays.asList(schemaVersion1, schemaVersion2), 3); assertThat(result.isPresent(), is(false)); }