Class ViewMap<E extends IMapEntry>

  • All Implemented Interfaces:
    java.lang.Iterable<E>
    Direct Known Subclasses:
    ClientView

    public class ViewMap<E extends IMapEntry>
    extends java.lang.Object
    implements java.lang.Iterable<E>
    Defines the common operations to Perforce view maps. View maps are normally used in Perforce clients, labels, branches, etc., to map one type of path (a depot path, for example) to a different type of path (e.g. a client path).

    View maps work in a manner that's described in the main Perforce documentation for the basic client view, but in summary, map entries can be inclusive, exclusive, or overlays, and map entry order is (of course) deeply significant.

    This implementation of view maps does not (yet) include advanced Perforce functionality (such as translation or testing the map to see whether a path is mapped or not), but future versions will; the emphasis here is on setting up a common basis for P4Java view maps.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ViewMap.MapDirection  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<E> entryList  
    • Constructor Summary

      Constructors 
      Constructor Description
      ViewMap()
      Default constructor.
      ViewMap​(java.util.List<E> entryList)
      Constructs a new ViewMap from the passed-in entry list.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEntry​(E entry)
      Add a map new entry at the end of the view map.
      void checkEntryList​(java.util.List<E> entryList)
      Do some sanity checks on the passed-in entry list.
      void deleteEntry​(int position)
      Delete the entry at the specified position.
      E getEntry​(int position)
      Get the map entry at the specified position.
      java.util.List<E> getEntryList()
      Get the entry list associated with this view map.
      int getSize()  
      java.util.Iterator<E> iterator()  
      void setEntry​(int position, E entry)
      Set (replace) a specific map position.
      void setEntryList​(java.util.List<E> entryList)
      Set the entry list associated with this view map.
      java.lang.String translate​(java.lang.String from, ViewMap.MapDirection dir)
      MapApi Translate wrapper
      protected void updateEntryListPositions()
      Update the entry list entry positions after an update by reassigning entry-internal positions as appropriate.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • entryList

        protected java.util.List<E extends IMapEntry> entryList
    • Constructor Detail

      • ViewMap

        public ViewMap()
        Default constructor. Creates a new ViewMap with an empty (but not null) entry list.
      • ViewMap

        public ViewMap​(java.util.List<E> entryList)
        Constructs a new ViewMap from the passed-in entry list. The passed-in list is inspected for consistency before being used.
        Parameters:
        entryList - non-null (but possibly-empty) entry list.
    • Method Detail

      • getSize

        public int getSize()
        Returns:
        the number of elements in the associated entry list.
      • deleteEntry

        public void deleteEntry​(int position)
        Delete the entry at the specified position. Will throw a P4JavaError if order is out of bounds. The order field of the deleted entry will be set to ORDER_UNKNOWN; the order fields of any entries "below" the deletion will be updated with their new order.
        Parameters:
        position - order of entry to be deleted
      • getEntry

        public E getEntry​(int position)
        Get the map entry at the specified position. Will throw a P4JavaError if order is out of bounds.
        Parameters:
        position - list position to use
        Returns:
        map entry
      • getEntryList

        public java.util.List<E> getEntryList()
        Get the entry list associated with this view map.
        Returns:
        non-null entry list
      • addEntry

        public void addEntry​(E entry)
        Add a map new entry at the end of the view map. The value of the entry's order field will be set to the order in the entry list.
        Parameters:
        entry - non-null map entry.
      • setEntry

        public void setEntry​(int position,
                             E entry)
        Set (replace) a specific map position.

        Will throw a P4JavaError if order is out of bounds or if the new entry is null. The value of the entry's order field will be set to the order in the entry list; the value of the replaced entry's order field will be set to ORDER_UNKNOWN.

        Parameters:
        position - list order of replacement
        entry - non-null replacement entry
      • setEntryList

        public void setEntryList​(java.util.List<E> entryList)
        Set the entry list associated with this view map.
        Parameters:
        entryList - non-null entry list
      • checkEntryList

        public void checkEntryList​(java.util.List<E> entryList)
        Do some sanity checks on the passed-in entry list. This includes checking for null list, null entries, and whether each entry's order field matches its actual order in the list. Throws NullPointerError or P4JavaError as appropriate.
        Parameters:
        entryList - list of entries
      • updateEntryListPositions

        protected void updateEntryListPositions()
        Update the entry list entry positions after an update by reassigning entry-internal positions as appropriate.
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<E extends IMapEntry>
        See Also:
        Iterable.iterator()
      • translate

        public java.lang.String translate​(java.lang.String from,
                                          ViewMap.MapDirection dir)
        MapApi Translate wrapper
        Parameters:
        dir - The translation direction
        from - the path to translate
        Returns:
        the translated path or null