Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.jbpm.services.task.utils;
 
 import java.util.List;
 
 import  org.kie.api.task.model.Attachment;
 import  org.kie.api.task.model.Comment;
 import  org.kie.api.task.model.Group;
 import  org.kie.api.task.model.I18NText;
 import  org.kie.api.task.model.OrganizationalEntity;
 import  org.kie.api.task.model.User;
 import  org.kie.internal.task.api.model.BooleanExpression;
 import  org.kie.internal.task.api.model.Deadline;
 import  org.kie.internal.task.api.model.Escalation;
 import  org.kie.internal.task.api.model.Notification;
 import  org.kie.internal.task.api.model.NotificationType;
 import  org.kie.internal.task.api.model.Reassignment;
 
 public class CollectionUtils {
     
     public static boolean equals(List list1List list2) {
         if ( list1 == null && list2 == null ) {
             // both are null
             return true;
         }
         
         if ( list1 == null || list2 == null ) {
             // we know both aren't null, so if one is null them obviously false
             return false;
         }        
         
         if ( list1.size() != list2.size() ) {
             return false;
         } 
         
         if ( list1.isEmpty() && list2.isEmpty() ) {
             return true;
         }
         
        
         for ( Object item1 : list1) {
             boolean exists = false;
             for ( Object item2 : list2 ) {
                 if ( item1.equalsitem2 )) {
                     exists = true;
                     break;
                 }
             }  
             if ( !exists ) {
                 return false;
             }
         }
         
         return true;
     }
     
     public static int hashCode(List list) {
         if ( list == null ) {
             return 0;
         }
         
         final int prime = 31;
         int result = 1;        
         for ( Iterator it = list.iterator(); it.hasNext(); ) {
             Object next = it.next();
             result = prime * result + ((next == null)? 0 : next.hashCode());
         }        
         return result;
    }       
    
    public static void writeCommentList(List<Comment> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( Comment item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<Comment> readCommentList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<Comment> list = new ArrayList<Comment>(size);
        for ( int i = 0; i < sizei++ ) {
            Comment item = new CommentImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }     
    
    
    public static void writeAttachmentList(List<Attachment> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( Attachment item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<Attachment> readAttachmentList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<Attachment> list = new ArrayList<Attachment>(size);
        for ( int i = 0; i < sizei++ ) {
            Attachment item = new AttachmentImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }      
    
    public static void writeBooleanExpressionList(List<BooleanExpression> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( BooleanExpression item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<BooleanExpression> readBooleanExpressionList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<BooleanExpression> list = new ArrayList<BooleanExpression>(size);
        for ( int i = 0; i < sizei++ ) {
            BooleanExpression item = new BooleanExpressionImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }     
    
    public static void writeNotificationList(List<Notification> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( Notification item : list ) {
            // item.getNotificationType().toString() is never null
            out.writeUTFitem.getNotificationType().toString() );
            item.writeExternal( out );
        }
    }    
    
    public static List<Notification> readNotificationList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<Notification> list = new ArrayList<Notification>(size);
        for ( int i = 0; i < sizei++ ) {
            Notification item = null;
            switch( NotificationType.valueOf(  in.readUTF() ) ) {
                case Default : {
                    item = new NotificationImpl();
                    break;
                }
                case Email : {
                    item = new EmailNotificationImpl();
                    break;
                }
            }
             
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }     
    
    
    public static void writeReassignmentList(List<Reassignment> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( Reassignment item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<Reassignment> readReassignmentList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<Reassignment> list = new ArrayList<Reassignment>(size);
        for ( int i = 0; i < sizei++ ) {
            Reassignment item = new ReassignmentImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }       
    
    public static void writeDeadlineList(List<Deadline> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( Deadline item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<Deadline> readDeadlinesList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<Deadline> list = new ArrayList<Deadline>(size);
        for ( int i = 0; i < sizei++ ) {
            Deadline item = new DeadlineImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }    
    
    public static void writeEscalationList(List<Escalation> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( Escalation item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<Escalation> readEscalationList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<Escalation> list = new ArrayList<Escalation>(size);
        for ( int i = 0; i < sizei++ ) {
            Escalation item = new EscalationImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }    
    
    public static void writeI18NTextList(List<I18NText> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( I18NText item : list ) {
            item.writeExternal( out );
        }
    }    
    
    public static List<I18NText> readI18NTextList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<I18NText> list = new ArrayList<I18NText>(size);
        for ( int i = 0; i < sizei++ ) {
            I18NText item = new I18NTextImpl();
            item.readExternal( in );
            list.add( item );
        }
        return list;
    }
    
    public static void writeOrganizationalEntityList(List<OrganizationalEntity> listObjectOutput outthrows IOException {
        out.writeIntlist.size() );
        for( OrganizationalEntity item : list ) {
            if ( item instanceof User ) {
                out.writeShort( 0 );
            } else {
                out.writeShort( 1 );
            }
            item.writeExternal( out );
        }
    }
    
    public static List<OrganizationalEntity> readOrganizationalEntityList(ObjectInput inthrows IOExceptionClassNotFoundException  {
        int size = in.readInt();
        List<OrganizationalEntity> list = new ArrayList<OrganizationalEntity>(size);
        for ( int i = 0; i < sizei++ ) {
            short type = in.readShort();
            if ( type == 0 ) {
                User user = new UserImpl();
                user.readExternal( in );
                list.add( user ); 
            } else {
                Group group = new GroupImpl();
                group.readExternal( in );
                list.add( group );
            }
        }
        return list;
    }    
New to GrepCode? Check out our FAQ X