Beispiel #1
1
  @Test
  public void splitLookup() {
    // do the split
    int pivot = 4;
    int max = 5;
    List<Integer> l = List.range(1, max + 1);
    TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
    P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>> p3 =
        m2.splitLookup(pivot);

    // create expected output
    List<Integer> leftList = List.range(1, pivot);
    TreeMap<Integer, String> leftMap =
        TreeMap.treeMap(Ord.intOrd, leftList.zip(leftList.map(i -> i.toString())));
    List<Integer> rightList = List.range(pivot + 1, max + 1);
    TreeMap<Integer, String> rightMap =
        TreeMap.treeMap(Ord.intOrd, rightList.zip(rightList.map(i -> i.toString())));

    // debug info
    if (true) {
      Show<TreeMap<Integer, String>> st = Show.treeMapShow(Show.intShow, Show.stringShow);
      Show<P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>>> sp3 =
          Show.p3Show(st, Show.optionShow(Show.stringShow), st);
      sp3.println(p3);
    }

    // do the assert
    Equal<TreeMap<Integer, String>> tme = Equal.treeMapEqual(Equal.intEqual, Equal.stringEqual);
    Equal<P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>>> eq =
        Equal.p3Equal(tme, Equal.optionEqual(Equal.stringEqual), tme);
    assertTrue(eq.eq(p3, p(leftMap, some(Integer.toString(pivot)), rightMap)));
  }
Beispiel #2
1
  @Test
  public void split() {
    // do the split
    int pivot = 4;
    int max = 5;
    List<Integer> l = List.range(1, max + 1);
    TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
    P3<Set<String>, Option<String>, Set<String>> p = m2.split(Ord.stringOrd, pivot);

    // print debug info
    Show<TreeMap<Integer, String>> st = Show.treeMapShow(Show.intShow, Show.stringShow);
    Show<Set<String>> ss = Show.setShow(Show.stringShow);
    Show<Option<String>> so = Show.optionShow(Show.stringShow);
    Show<P3<Set<String>, Option<String>, Set<String>>> sp3 = Show.p3Show(ss, so, ss);
    if (true) {
      st.println(m2);
      sp3.println(p);
    }

    // assert equals
    Equal<Set<String>> seq = Equal.setEqual(Equal.stringEqual);
    Set<String> left = toSetString(List.range(1, pivot));
    Set<String> right = toSetString(List.range(pivot + 1, max + 1));
    P3<Set<String>, Option<String>, Set<String>> expected =
        p(left, some(Integer.toString(pivot)), right);
    assertTrue(Equal.p3Equal(seq, Equal.optionEqual(Equal.stringEqual), seq).eq(p, expected));
  }
/** @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a> */
public class FileAttributes {
  public final Option<String> user;

  public final Option<String> group;

  public final Option<UnixFileMode> mode;

  public final List<String> tags;

  public static final Show<FileAttributes> singleLineShow = Show.anyShow();

  /** A file object with all none fields. Use this when creating template objects. */
  public static final FileAttributes EMPTY =
      new FileAttributes(
          Option.<String>none(),
          Option.<String>none(),
          Option.<UnixFileMode>none(),
          List.<String>nil());

  public FileAttributes(Option<String> user, Option<String> group, Option<UnixFileMode> mode) {
    this(user, group, mode, List.<String>nil());
  }

  public FileAttributes(
      Option<String> user, Option<String> group, Option<UnixFileMode> mode, List<String> tags) {
    validateNotNull(user, group, mode, tags);
    this.user = user;
    this.group = group;
    this.mode = mode;
    this.tags = tags;
  }

  public FileAttributes user(String user) {
    return new FileAttributes(fromNull(user), group, mode, tags);
  }

  public FileAttributes user(Option<String> user) {
    return new FileAttributes(user, group, mode, tags);
  }

  public FileAttributes group(String group) {
    return new FileAttributes(user, fromNull(group), mode, tags);
  }

  public FileAttributes group(Option<String> group) {
    return new FileAttributes(user, group, mode, tags);
  }

  public FileAttributes mode(UnixFileMode mode) {
    return new FileAttributes(user, group, fromNull(mode), tags);
  }

  public FileAttributes mode(Option<UnixFileMode> mode) {
    return new FileAttributes(user, group, mode, tags);
  }

  public FileAttributes addTag(String tag) {
    return new FileAttributes(user, group, mode, tags.append(single(tag)));
  }

  public FileAttributes tags(List<String> tags) {
    return new FileAttributes(user, group, mode, this.tags.append(tags));
  }

  // -----------------------------------------------------------------------
  //
  // -----------------------------------------------------------------------

  public FileAttributes useAsDefaultsFor(FileAttributes other) {
    return new FileAttributes(
        other.user.orElse(user), other.group.orElse(group), other.mode.orElse(mode), other.tags);
  }

  // -----------------------------------------------------------------------
  //
  // -----------------------------------------------------------------------

  public static final F2<FileAttributes, FileAttributes, FileAttributes> useAsDefaultsFor =
      new F2<FileAttributes, FileAttributes, FileAttributes>() {
        public FileAttributes f(FileAttributes defaults, FileAttributes other) {
          return defaults.useAsDefaultsFor(other);
        }
      };

  public static final F<FileAttributes, Option<String>> userF =
      new F<FileAttributes, Option<String>>() {
        public Option<String> f(FileAttributes attributes) {
          return attributes.user;
        }
      };

  public static final F<FileAttributes, Option<String>> groupF =
      new F<FileAttributes, Option<String>>() {
        public Option<String> f(FileAttributes attributes) {
          return attributes.group;
        }
      };

  public static final F<FileAttributes, Option<UnixFileMode>> modeF =
      new F<FileAttributes, Option<UnixFileMode>>() {
        public Option<UnixFileMode> f(FileAttributes attributes) {
          return attributes.mode;
        }
      };

  public static final F<FileAttributes, List<String>> tagsF =
      new F<FileAttributes, List<String>>() {
        public List<String> f(FileAttributes attributes) {
          return attributes.tags;
        }
      };

  // -----------------------------------------------------------------------
  // Object Overrides
  // -----------------------------------------------------------------------

  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }

    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    FileAttributes that = (FileAttributes) o;

    return optionEquals(user, that.user)
        && optionEquals(group, that.group)
        && optionEquals(mode, that.mode);
  }

  public String toString() {
    return "user="******"<not set>")
        + ", "
        + "group="
        + group.orSome("<not set>")
        + ", "
        + "mode="
        + mode.map(showLong).orSome("<not set>");
  }
}
Beispiel #4
0
 /**
  * Provides a show instance that draws a 2-dimensional representation of a tree.
  *
  * @param s A show instance for the elements of the tree.
  * @return a show instance that draws a 2-dimensional representation of a tree.
  */
 public static <A> Show<Tree<A>> show2D(final Show<A> s) {
   return Show.showS(
       new F<Tree<A>, String>() {
         public String f(final Tree<A> tree) {
           return tree.draw(s);
         }
       });
 }
Beispiel #5
0
 /**
  * Provides a show instance that draws a 2-dimensional representation of a tree.
  *
  * @param s A show instance for the elements of the tree.
  * @return a show instance that draws a 2-dimensional representation of a tree.
  */
 public static <A> Show<Tree<A>> show2D(final Show<A> s) {
   return Show.showS(tree -> tree.draw(s));
 }
Beispiel #6
0
 @Override
 public String toString() {
   return Show.treeShow(Show.<A>anyShow()).showS(this);
 }
Beispiel #7
0
 private Stream<String> drawTree(final Show<A> s) {
   return drawSubTrees(s, subForest._1()).cons(s.showS(root));
 }
 @Override
 public String toString() {
   return Show.nonEmptyListShow(Show.<A>anyShow()).showS(this);
 }