@Override public int hashCode() { int result = name.hashCode(); result = 31 * result + classes.hashCode(); result = 31 * result + href.hashCode(); result = 31 * result + title.hashCode(); result = 31 * result + method.hashCode(); result = 31 * result + type.hashCode(); result = 31 * result + fields.hashCode(); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Action action = (Action) o; if (!name.equals(action.name)) return false; if (!classes.equals(action.classes)) return false; if (!href.equals(action.href)) return false; if (!title.equals(action.title)) return false; if (!method.equals(action.method)) return false; if (!type.equals(action.type)) return false; return fields.equals(action.fields); }
@Test public void construct() { Field field = Field.of("foo").with(Json.jString("bar")); assertEquals(field.name, "foo"); assertEquals(field.value, Option.of(Json.jString("bar"))); assertEquals(field.classes, none()); assertEquals(field.title, none()); assertEquals(field.type, Type.TEXT); }
/** * Returns the first element of this which satisfies the given predicate. * * @param predicate A predicate. * @return Some(element) or None, where element may be null (i.e. {@code List.of(null).findFirst(e * -> e == null)}). * @throws NullPointerException if {@code predicate} is null */ default Option<T> findFirst(Predicate<? super T> predicate) { Objects.requireNonNull(predicate, "predicate is null"); for (T a : this) { if (predicate.test(a)) { return new Some<>(a); // may be Some(null) } } return Option.none(); }
@Override public Option<Array<T>> initOption() { return isEmpty() ? Option.none() : Option.some(init()); }
@Override public Option<Array<T>> tailOption() { return isEmpty() ? Option.none() : Option.some(tail()); }
@Test public void shouldGetOptionNonEmpty() { assertThat(of(1).getOption()).isEqualTo(Option.of(1)); }
@Test public void shouldGetOptionEmpty() { assertThat(empty().getOption()).isEqualTo(Option.none()); }
@Test public void shouldConvertToOption() { assertThat(empty().toOption()).isSameAs(Option.none()); assertThat(of(1).toOption()).isEqualTo(Option.of(1)); }
public Action with(String title) { return new Action(name, href, classes, Option.of(title), method, type, fields); }
@Override default Option<Seq<T>> initOption() { return isEmpty() ? Option.none() : Option.some(init()); }
public Option<String> format(FieldSerializer serializer) { return serializer.serialize(type.getOrElse(MIMEType.URLEncoded), fields); }
public Action with(Fields fields) { return new Action(name, href, classes, title, method, type, Option.of(fields)); }
public Action with(MIMEType type) { return new Action(name, href, classes, title, method, Option.of(type), fields); }
public Action with(Method method) { return new Action(name, href, classes, title, Option.of(method), type, fields); }
@Test public void shouldPeekOption() { assertThat(empty().peekOption()).isSameAs(Option.none()); assertThat(of(1).peekOption()).isEqualTo(Option.of(1)); assertThat(of(1, 2).peekOption()).isEqualTo(Option.of(1)); }
@Override default Option<T> headOption() { return isEmpty() ? Option.none() : Option.some(head()); }
@Test public void shouldPop2Option() { assertThat(empty().pop2Option()).isSameAs(Option.none()); assertThat(of(1).pop2Option()).isEqualTo(Option.of(Tuple.of(1, empty()))); assertThat(of(1, 2).pop2Option()).isEqualTo(Option.of(Tuple.of(1, of(2)))); }
@Override default Option<Seq<T>> tailOption() { return isEmpty() ? Option.none() : Option.some(tail()); }
public Action with(Classes classes) { return new Action(name, href, Option.of(classes), title, method, type, fields); }