Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013 GraphAware
   *
   * This file is part of GraphAware.
   *
   * GraphAware is free software: you can redistribute it and/or modify it under the terms of
   * the GNU General Public License as published by the Free Software Foundation, either
   * version 3 of the License, or (at your option) any later version.
   *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details. You should have received a copy of
  * the GNU General Public License along with this program.  If not, see
  * <http://www.gnu.org/licenses/>.
  */
 
 package com.graphaware.tx.event.improved.api;
 
 
 import java.util.Map;
 
 import static com.graphaware.common.util.PropertyContainerUtils.id;

Change in the state of an object, encapsulating the old (previous) and the new (current).
 
 public class Change<T> {
 
     private final T previous;
     private final T current;

    
Construct a change representation.

Parameters:
previous state of the object.
current state of the object.
 
     public Change(T previous, T current) {
         this. = previous;
         this. = current;
     }

    
Get the previous (old) state of the object.

Returns:
previous state
 
     public T getPrevious() {
         return ;
     }

    
Get the current (new) state of the object.

Returns:
current state
 
     public T getCurrent() {
         return ;
     }

    
 
     @SuppressWarnings("RedundantIfStatement")
     @Override
     public boolean equals(Object o) {
         if (this == oreturn true;
         if (o == null || getClass() != o.getClass()) return false;
 
         Change change = (Changeo;
 
         if (!.equals(change.current)) return false;
         if (!.equals(change.previous)) return false;
 
         return true;
     }

    
 
     @Override
     public int hashCode() {
         int result = .hashCode();
         result = 31 * result + .hashCode();
         return result;
     }

    
Convert a collection of Changes of org.neo4j.graphdb.PropertyContainer to a map of Changes keyed by the org.neo4j.graphdb.PropertyContainer ID.

Parameters:
changes to convert.
<T> type of the org.neo4j.graphdb.PropertyContainer.
Returns:
map keyed by org.neo4j.graphdb.PropertyContainer ID with the actual Changes as values.
Throws:
java.lang.IllegalArgumentException in case the two org.neo4j.graphdb.PropertyContainers contained in a Change do not have the same IDs.
    public static <T extends PropertyContainerMap<LongChange<T>> changesToMap(Collection<Change<T>> changes) {
        Map<LongChange<T>> result = new HashMap<>();
        for (Change<T> change : changes) {
            long id = id(change.getPrevious());
            if (id != id(change.getCurrent())) {
                throw new IllegalArgumentException("IDs of the Property Containers in Change do not match!");
            }
            result.put(idchange);
        }
        return result;
    }
New to GrepCode? Check out our FAQ X