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.registry.ServiceReference;
018    
019    import java.util.Objects;
020    
021    /**
022     * @author Iv??n Zaera
023     */
024    public class DisplayContextFactoryReference<T extends DisplayContextFactory>
025            implements Comparable<DisplayContextFactoryReference<?>> {
026    
027            public DisplayContextFactoryReference(
028                    T displayContextFactory, ServiceReference<T> serviceReference) {
029    
030                    _displayContextFactory = displayContextFactory;
031                    _serviceReference = serviceReference;
032            }
033    
034            @Override
035            public int compareTo(
036                    DisplayContextFactoryReference<?> displayContextFactoryReference) {
037    
038                    return _serviceReference.compareTo(
039                            displayContextFactoryReference._serviceReference);
040            }
041    
042            @Override
043            public boolean equals(Object obj) {
044                    if (this == obj) {
045                            return true;
046                    }
047    
048                    if (!(obj instanceof DisplayContextFactoryReference)) {
049                            return false;
050                    }
051    
052                    DisplayContextFactoryReference<?> displayContextFactoryReference =
053                            (DisplayContextFactoryReference<?>)obj;
054    
055                    if (Objects.equals(
056                                    _serviceReference,
057                                    displayContextFactoryReference._serviceReference)) {
058    
059                            return true;
060                    }
061    
062                    return false;
063            }
064    
065            public T getDisplayContextFactory() {
066                    return _displayContextFactory;
067            }
068    
069            public ServiceReference<T> getServiceReference() {
070                    return _serviceReference;
071            }
072    
073            @Override
074            public int hashCode() {
075                    return _serviceReference.hashCode();
076            }
077    
078            private final T _displayContextFactory;
079            private final ServiceReference<T> _serviceReference;
080    
081    }