001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package service.tut.pori.users;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlElement;
024import javax.xml.bind.annotation.XmlRootElement;
025
026import org.apache.log4j.Logger;
027
028import core.tut.pori.http.ResponseData;
029import core.tut.pori.users.ExternalAccountConnection;
030
031/**
032 * List of external account connections usable with Response.
033 * 
034 */
035@XmlRootElement(name=Definitions.ELEMENT_EXTERNAL_ACCOUNT_CONNECTION_LIST)
036@XmlAccessorType(XmlAccessType.NONE)
037public class ExternalAccountConnectionList extends ResponseData {
038  private static final Logger LOGGER = Logger.getLogger(ExternalAccountConnectionList.class);
039  @XmlElement(name=core.tut.pori.users.Definitions.ELEMENT_EXTERNAL_ACCOUNT_CONNECTION)
040  private List<ExternalAccountConnection> _connections = null;
041
042  /**
043   * @return the connections
044   */
045  public List<ExternalAccountConnection> getConnections() {
046    return _connections;
047  }
048
049  /**
050   * @param connections the connections to set
051   */
052  public void setConnections(List<ExternalAccountConnection> connections) {
053    _connections = connections;
054  }
055  
056  /**
057   * 
058   * @param connection null connection will be ignored
059   */
060  public void addConnection(ExternalAccountConnection connection) {
061    if(connection == null){
062      LOGGER.debug("Ignored null connection.");
063      return;
064    }
065    
066    if(_connections == null){
067      _connections = new ArrayList<>();
068    }
069    _connections.add(connection);
070  }
071  
072  /**
073   * for sub-classing, use the static
074   * @return true if this list has no connections
075   */
076  protected boolean isEmpty(){
077    return (_connections == null ? true : _connections.isEmpty());
078  }
079  
080  /**
081   * 
082   * @param list
083   * @return true if list is null or empty
084   */
085  public static boolean isEmpty(ExternalAccountConnectionList list){
086    return (list == null ? true : list.isEmpty());
087  }
088}