Esempio n. 1
0
 @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;
 }
Esempio n. 2
0
  @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);
  }
Esempio n. 3
0
 @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);
 }
Esempio n. 4
0
 /**
  * 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();
 }
Esempio n. 5
0
 @Override
 public Option<Array<T>> initOption() {
   return isEmpty() ? Option.none() : Option.some(init());
 }
Esempio n. 6
0
 @Override
 public Option<Array<T>> tailOption() {
   return isEmpty() ? Option.none() : Option.some(tail());
 }
Esempio n. 7
0
 @Test
 public void shouldGetOptionNonEmpty() {
   assertThat(of(1).getOption()).isEqualTo(Option.of(1));
 }
Esempio n. 8
0
 @Test
 public void shouldGetOptionEmpty() {
   assertThat(empty().getOption()).isEqualTo(Option.none());
 }
Esempio n. 9
0
 @Test
 public void shouldConvertToOption() {
   assertThat(empty().toOption()).isSameAs(Option.none());
   assertThat(of(1).toOption()).isEqualTo(Option.of(1));
 }
Esempio n. 10
0
 public Action with(String title) {
   return new Action(name, href, classes, Option.of(title), method, type, fields);
 }
Esempio n. 11
0
 @Override
 default Option<Seq<T>> initOption() {
   return isEmpty() ? Option.none() : Option.some(init());
 }
Esempio n. 12
0
 public Option<String> format(FieldSerializer serializer) {
   return serializer.serialize(type.getOrElse(MIMEType.URLEncoded), fields);
 }
Esempio n. 13
0
 public Action with(Fields fields) {
   return new Action(name, href, classes, title, method, type, Option.of(fields));
 }
Esempio n. 14
0
 public Action with(MIMEType type) {
   return new Action(name, href, classes, title, method, Option.of(type), fields);
 }
Esempio n. 15
0
 public Action with(Method method) {
   return new Action(name, href, classes, title, Option.of(method), type, fields);
 }
Esempio n. 16
0
 @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));
 }
Esempio n. 17
0
 @Override
 default Option<T> headOption() {
   return isEmpty() ? Option.none() : Option.some(head());
 }
Esempio n. 18
0
 @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))));
 }
Esempio n. 19
0
 @Override
 default Option<Seq<T>> tailOption() {
   return isEmpty() ? Option.none() : Option.some(tail());
 }
Esempio n. 20
0
 public Action with(Classes classes) {
   return new Action(name, href, Option.of(classes), title, method, type, fields);
 }