Class UserBook

java.lang.Object
io.github.jbastgen.stemma.app.avatar.UserBook

public final class UserBook extends Object
The user mapping (feature 26): which identities (e-mail addresses and names) are one person. It changes only the display, never a commit. The file is plain text, one line per fact, kind TAB user-id TAB value: name (display name), short, bot, email, alias (a name used when no e-mail matches). Later lines win over earlier ones, so people who add to a shared file need no merge; lines that cannot be read are skipped and reported.
  • Field Details

    • EMPTY

      public static final UserBook EMPTY
  • Constructor Details

    • UserBook

      public UserBook()
  • Method Details

    • users

      public List<UserBook.User> users()
      A copy of the list of users.
    • problems

      public List<String> problems()
      The lines of the file that could not be read, with the reason.
    • add

      public UserBook.User add(String name)
      Adds a user with a new identifier.
    • remove

      public void remove(UserBook.User u)
      Removes a user.
    • assign

      public void assign(UserBook.User u, String email, String name)
      Adds an e-mail address or a name to a user, taking it away from any other user (an identity belongs to one user).
    • merge

      public void merge(UserBook.User from, UserBook.User into)
      Moves everything of from to into.
    • reindex

      public void reindex()
      Rebuilds the lookup after the users were changed.
    • resolve

      public Optional<UserBook.User> resolve(Author a)
      The user an author is: by e-mail address first, then by name.
    • displayName

      public String displayName(Author a)
      The name to show for an author: the user's display name, else the name as written.
    • searchText

      public String searchText(Author a)
      The text the filter searches: every name and address of the user, or the author as written.
    • identity

      public String identity(Author a)
      The key that makes two authors one person: the user id, else the e-mail address.
    • parse

      public static UserBook parse(String text)
      Reads the file: lines kind TAB user TAB value. Lines that cannot be used are skipped and listed in problems.
    • load

      public static UserBook load(Path file)
      Reads the file; a missing file is an empty book.
    • save

      public void save(Path file) throws IOException
      Writes the file completely and replaces the old one in one step.
      Throws:
      IOException
    • importMailmap

      public int importMailmap(String text)
      Takes the lines of a .mailmap over: the proper identity becomes a user, the old ones its identities. @return lines read
    • toMailmap

      public String toMailmap()
      The mapping as a .mailmap: the first address of a user is the proper one.