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