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.model.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.util.HashUtil;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.model.CacheModel;
023    import com.liferay.portal.model.Image;
024    import com.liferay.portal.model.MVCCModel;
025    
026    import java.io.Externalizable;
027    import java.io.IOException;
028    import java.io.ObjectInput;
029    import java.io.ObjectOutput;
030    
031    import java.util.Date;
032    
033    /**
034     * The cache model class for representing Image in entity cache.
035     *
036     * @author Brian Wing Shun Chan
037     * @see Image
038     * @generated
039     */
040    @ProviderType
041    public class ImageCacheModel implements CacheModel<Image>, Externalizable,
042            MVCCModel {
043            @Override
044            public boolean equals(Object obj) {
045                    if (this == obj) {
046                            return true;
047                    }
048    
049                    if (!(obj instanceof ImageCacheModel)) {
050                            return false;
051                    }
052    
053                    ImageCacheModel imageCacheModel = (ImageCacheModel)obj;
054    
055                    if ((imageId == imageCacheModel.imageId) &&
056                                    (mvccVersion == imageCacheModel.mvccVersion)) {
057                            return true;
058                    }
059    
060                    return false;
061            }
062    
063            @Override
064            public int hashCode() {
065                    int hashCode = HashUtil.hash(0, imageId);
066    
067                    return HashUtil.hash(hashCode, mvccVersion);
068            }
069    
070            @Override
071            public long getMvccVersion() {
072                    return mvccVersion;
073            }
074    
075            @Override
076            public void setMvccVersion(long mvccVersion) {
077                    this.mvccVersion = mvccVersion;
078            }
079    
080            @Override
081            public String toString() {
082                    StringBundler sb = new StringBundler(15);
083    
084                    sb.append("{mvccVersion=");
085                    sb.append(mvccVersion);
086                    sb.append(", imageId=");
087                    sb.append(imageId);
088                    sb.append(", modifiedDate=");
089                    sb.append(modifiedDate);
090                    sb.append(", type=");
091                    sb.append(type);
092                    sb.append(", height=");
093                    sb.append(height);
094                    sb.append(", width=");
095                    sb.append(width);
096                    sb.append(", size=");
097                    sb.append(size);
098                    sb.append("}");
099    
100                    return sb.toString();
101            }
102    
103            @Override
104            public Image toEntityModel() {
105                    ImageImpl imageImpl = new ImageImpl();
106    
107                    imageImpl.setMvccVersion(mvccVersion);
108                    imageImpl.setImageId(imageId);
109    
110                    if (modifiedDate == Long.MIN_VALUE) {
111                            imageImpl.setModifiedDate(null);
112                    }
113                    else {
114                            imageImpl.setModifiedDate(new Date(modifiedDate));
115                    }
116    
117                    if (type == null) {
118                            imageImpl.setType(StringPool.BLANK);
119                    }
120                    else {
121                            imageImpl.setType(type);
122                    }
123    
124                    imageImpl.setHeight(height);
125                    imageImpl.setWidth(width);
126                    imageImpl.setSize(size);
127    
128                    imageImpl.resetOriginalValues();
129    
130                    return imageImpl;
131            }
132    
133            @Override
134            public void readExternal(ObjectInput objectInput) throws IOException {
135                    mvccVersion = objectInput.readLong();
136                    imageId = objectInput.readLong();
137                    modifiedDate = objectInput.readLong();
138                    type = objectInput.readUTF();
139                    height = objectInput.readInt();
140                    width = objectInput.readInt();
141                    size = objectInput.readInt();
142            }
143    
144            @Override
145            public void writeExternal(ObjectOutput objectOutput)
146                    throws IOException {
147                    objectOutput.writeLong(mvccVersion);
148                    objectOutput.writeLong(imageId);
149                    objectOutput.writeLong(modifiedDate);
150    
151                    if (type == null) {
152                            objectOutput.writeUTF(StringPool.BLANK);
153                    }
154                    else {
155                            objectOutput.writeUTF(type);
156                    }
157    
158                    objectOutput.writeInt(height);
159                    objectOutput.writeInt(width);
160                    objectOutput.writeInt(size);
161            }
162    
163            public long mvccVersion;
164            public long imageId;
165            public long modifiedDate;
166            public String type;
167            public int height;
168            public int width;
169            public int size;
170    }