001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.display.context;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.registry.ServiceReference;
019    
020    /**
021     * @author Iv??n Zaera
022     */
023    public class DisplayContextFactoryReference<T extends DisplayContextFactory>
024            implements Comparable<DisplayContextFactoryReference<?>> {
025    
026            public DisplayContextFactoryReference(
027                    T displayContextFactory, ServiceReference<T> serviceReference) {
028    
029                    _displayContextFactory = displayContextFactory;
030                    _serviceReference = serviceReference;
031            }
032    
033            @Override
034            public int compareTo(
035                    DisplayContextFactoryReference<?> displayContextFactoryReference) {
036    
037                    return _serviceReference.compareTo(
038                            displayContextFactoryReference._serviceReference);
039            }
040    
041            @Override
042            public boolean equals(Object obj) {
043                    if (this == obj) {
044                            return true;
045                    }
046    
047                    if (!(obj instanceof DisplayContextFactoryReference)) {
048                            return false;
049                    }
050    
051                    DisplayContextFactoryReference<?> displayContextFactoryReference =
052                            (DisplayContextFactoryReference<?>)obj;
053    
054                    if (Validator.equals(
055                                    _serviceReference,
056                                    displayContextFactoryReference._serviceReference)) {
057    
058                            return true;
059                    }
060    
061                    return false;
062            }
063    
064            public T getDisplayContextFactory() {
065                    return _displayContextFactory;
066            }
067    
068            public ServiceReference<T> getServiceReference() {
069                    return _serviceReference;
070            }
071    
072            @Override
073            public int hashCode() {
074                    return _serviceReference.hashCode();
075            }
076    
077            private final T _displayContextFactory;
078            private final ServiceReference<T> _serviceReference;
079    
080    }