Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
   *
   *  Permission is hereby granted, free of charge, to any person obtaining a copy
   *  of this software and associated documentation files (the "Software"), to deal
   *  in the Software without restriction, including without limitation the rights
   *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
  *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
  *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *  THE SOFTWARE.
  */
 package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data;
 
 
 import java.util.List;

This bean contains information to the com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritCause about what other builds were involved in the same event. For backwards compatibility reasons this class is serialized by the help of the XStream converter TriggerContextConverter so any future additions to this class need to be handled in that class as well or it won't be serialized correctly.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public class TriggerContext {
 
     private GerritTriggeredEvent event;
     private TriggeredItemEntity thisBuild;
     private List<TriggeredItemEntityothers;

    
standard constructor.

Parameters:
thisBuild this build.
event the event for this context.
others the other building and untriggered builds.
 
     public TriggerContext(AbstractBuild thisBuild,
                           GerritTriggeredEvent event,
                           List<TriggeredItemEntityothers) {
         this. = new TriggeredItemEntity(thisBuild);
         this. = event;
         this. = others;
     }

    
Standard constructor.

Parameters:
event the event for this context.
 
     public TriggerContext(GerritTriggeredEvent event) {
         this. = event;
     }

    
Default constructor.
 
     public TriggerContext() {
     }

    
A list of builds that were triggered by the same event as "this" build.

Returns:
the builds.
 
     public synchronized List<TriggeredItemEntitygetOthers() {
         return ;
     }

    
A list of builds that were triggered by the same event as "this" build. Could contain non-triggered builds represented by TriggeredItemEntity.getBuild() == null. Do not use this method unless you are a serializer, use addOtherBuild(hudson.model.AbstractBuild) for adding builds.

Parameters:
otherBuilds the builds.
 
    public synchronized void setOthers(List<TriggeredItemEntityotherBuilds) {
        this. = otherBuilds;
    }

    
The build that this context represents.

Returns:
the build.
    public synchronized TriggeredItemEntity getThisBuild() {
        return ;
    }

    
The build that this context represents.

Parameters:
thisBuild the build.
    public synchronized void setThisBuild(TriggeredItemEntity thisBuild) {
        this. = thisBuild;
    }

    
The build that this context represents.

Parameters:
thisBuild the build.
    public synchronized void setThisBuild(AbstractBuild thisBuild) {
        this. = new TriggeredItemEntity(thisBuild);
    }

    
The event for this context.

Returns:
the event.
    public GerritTriggeredEvent getEvent() {
        return ;
    }

    
The event for this context.

Parameters:
event the event.
    void setEvent(GerritTriggeredEvent event) {
        this. = event;
    }

    
Adds a build to the list of other builds if it doesn't exist in the list. Also if the build's project exists in the list of other projects, the project will be removed from that list.

Parameters:
build the build to add.
See also:
getOtherBuilds()
    public synchronized void addOtherBuild(AbstractBuild build) {
        if ( == null) {
             = new LinkedList<TriggeredItemEntity>();
        }
        TriggeredItemEntity other = findOtherBuild(build);
        if (other == null) {
            other = findOtherProject(build.getProject());
            if (other != null) {
                other.setBuild(build);
            } else {
                .add(new TriggeredItemEntity(build));
            }
        }
    }

    
Adds a project to the list of other projects if it doesn't exist in the list.

Parameters:
project the project to add.
See also:
getOtherProjects()
    public synchronized void addOtherProject(AbstractProject project) {
        if ( == null) {
             = new LinkedList<TriggeredItemEntity>();
        }
        if (findOtherProject(project) == null) {
            .add(new TriggeredItemEntity(project));
        }
    }

    
Tells if there are any other builds or projects in this context.

Returns:
true if it is so.
See also:
getOtherBuilds()
getOtherProjects()
    public synchronized boolean hasOthers() {
        return ( != null && !.isEmpty());
    }

    
Finds the other object for the specified build, or null if the build does not exist.

Parameters:
build a build.
Returns:
the other object if there is one, null if there is none.
    private synchronized TriggeredItemEntity findOtherBuild(AbstractBuild build) {
        for (TriggeredItemEntity other : ) {
            if (other.equals(build)) {
                return other;
            }
        }
        return null;
    }

    
Finds the object for the specified project, or null if the project does not exist in the list.

Parameters:
project the project.
Returns:
the other object, or null if none.
    private synchronized TriggeredItemEntity findOtherProject(AbstractProject project) {
        for (TriggeredItemEntity other : ) {
            if (other.equals(project)) {
                return other;
            }
        }
        return null;
    }

    
Gets all the other builds in this context. If some project hasn't started a build yet, that project will be unrepresented in this list.

Returns:
a list of builds from this context.
    public synchronized List<AbstractBuildgetOtherBuilds() {
        List<AbstractBuildlist = new LinkedList<AbstractBuild>();
        if ( != null) {
            for (TriggeredItemEntity entity : ) {
                if (entity.getBuild() != null) {
                    list.add(entity.getBuild());
                }
            }
        }
        return list;
    }

    
Gets all the other projects in this context.

Returns:
a list of projects from this context.
    public synchronized List<AbstractProjectgetOtherProjects() {
        List<AbstractProjectlist = new LinkedList<AbstractProject>();
        if ( != null) {
            for (TriggeredItemEntity entity : ) {
                if (entity.getProject() != null) {
                    list.add(entity.getProject());
                }
            }
        }
        return list;
    }
New to GrepCode? Check out our FAQ X