OSDN Git Service

PostClass.StatusGeoクラスをImmutableな構造体に変更
authorKimura Youichi <kim.upsilon@bucyou.net>
Sun, 9 Aug 2015 13:16:09 +0000 (22:16 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sun, 9 Aug 2015 15:52:21 +0000 (00:52 +0900)
OpenTween.Tests/PostClassTest.cs
OpenTween.Tests/Thumbnail/Services/FoursquareCheckinTest.cs
OpenTween/StatusDictionary.cs
OpenTween/Thumbnail/ThumbnailGenerator.cs
OpenTween/Twitter.cs

index d26ff6c..2e3c1bc 100644 (file)
@@ -59,7 +59,7 @@ namespace OpenTween
                 bool FilterHit = false,
                 string RetweetedBy = null,
                 long? RetweetedId = null,
-                StatusGeo Geo = null) :
+                StatusGeo? Geo = null) :
                 base(Nickname, textFromApi, text, ImageUrl, screenName, createdAt, statusId, IsFav, IsRead,
                 IsReply, IsExcludeReply, IsProtect, IsOwl, IsMark, InReplyToUser, InReplyToStatusId, Source,
                 SourceUri, ReplyToList, IsMe, IsDm, userId, FilterHit, RetweetedBy, RetweetedId, Geo)
@@ -160,7 +160,7 @@ namespace OpenTween
                 IsProtect = protect,
                 IsMark = mark,
                 InReplyToStatusId = reply ? (long?)100L : null,
-                PostGeo = geo ? new PostClass.StatusGeo { Lat = -47.15, Lng = -126.716667 } : null,
+                PostGeo = geo ? new PostClass.StatusGeo(-126.716667, -47.15) : (PostClass.StatusGeo?)null,
             };
 
             Assert.Equal(expected, post.StateIndex);
index fb84049..537d6e0 100644 (file)
@@ -132,11 +132,7 @@ namespace OpenTween.Thumbnail.Services
                 // 既にジオタグが付いているツイートに対しては何もしない
                 var post = new PostClass
                 {
-                    PostGeo = new PostClass.StatusGeo
-                    {
-                        Lat = 34.35067978344854,
-                        Lng = 134.04693603515625,
-                    },
+                    PostGeo = new PostClass.StatusGeo(134.04693603515625, 34.35067978344854),
                 };
 
                 var thumb = await service.GetThumbnailInfoAsync(
index 87d7fad..ea1524d 100644 (file)
@@ -41,21 +41,31 @@ namespace OpenTween
 {
     public class PostClass : ICloneable
     {
-        public class StatusGeo
+        public struct StatusGeo : IEquatable<StatusGeo>
         {
-            public double Lng { get; set; }
-            public double Lat { get; set; }
+            public double Longitude { get; }
+            public double Latitude { get; }
 
-            public override bool Equals(object obj)
+            public StatusGeo(double longitude, double latitude)
             {
-                var geo = obj as StatusGeo;
-                return geo != null && geo.Lng == this.Lng && geo.Lat == this.Lat;
+                this.Longitude = longitude;
+                this.Latitude = latitude;
             }
 
             public override int GetHashCode()
-            {
-                return this.Lng.GetHashCode() ^ this.Lat.GetHashCode();
-            }
+                => this.Longitude.GetHashCode() ^ this.Latitude.GetHashCode();
+
+            public override bool Equals(object obj)
+                => obj is StatusGeo ? this.Equals((StatusGeo)obj) : false;
+
+            public bool Equals(StatusGeo other)
+                => this.Longitude == other.Longitude && this.Latitude == other.Longitude;
+
+            public static bool operator ==(StatusGeo left, StatusGeo right)
+                => left.Equals(right);
+
+            public static bool operator !=(StatusGeo left, StatusGeo right)
+                => !left.Equals(right);
         }
         public string Nickname { get; set; }
         public string TextFromApi { get; set; }
@@ -83,7 +93,7 @@ namespace OpenTween
         public string RetweetedBy { get; set; }
         public long? RetweetedId { get; set; }
         private bool _IsDeleted = false;
-        private StatusGeo _postGeo = null;
+        private StatusGeo? _postGeo = null;
         public int RetweetedCount { get; set; }
         public long? RetweetedByUserId { get; set; }
         public long? InReplyToUserId { get; set; }
@@ -130,7 +140,7 @@ namespace OpenTween
                 bool FilterHit,
                 string RetweetedBy,
                 long? RetweetedId,
-                StatusGeo Geo)
+                StatusGeo? Geo)
             : this()
         {
             this.Nickname = Nickname;
@@ -294,7 +304,7 @@ namespace OpenTween
             }
         }
 
-        public StatusGeo PostGeo
+        public StatusGeo? PostGeo
         {
             get
             {
@@ -418,7 +428,6 @@ namespace OpenTween
         {
             var clone = (PostClass)this.MemberwiseClone();
             clone.ReplyToList = new List<string>(this.ReplyToList);
-            clone.PostGeo = this.PostGeo != null ? new StatusGeo { Lng = this.PostGeo.Lng, Lat = this.PostGeo.Lat } : null;
             clone.Media = new List<MediaInfo>(this.Media);
             clone.QuoteStatusIds = this.QuoteStatusIds.ToArray();
 
index d48381b..bdab196 100644 (file)
@@ -235,10 +235,11 @@ namespace OpenTween.Thumbnail
             if (post.PostGeo != null)
             {
                 var map = MapThumb.GetDefaultInstance();
+                var point = post.PostGeo.Value;
                 thumbnails.Add(new ThumbnailInfo()
                 {
-                    ImageUrl = map.CreateMapLinkUrl(post.PostGeo.Lat, post.PostGeo.Lng),
-                    ThumbnailUrl = map.CreateStaticMapUrl(post.PostGeo.Lat, post.PostGeo.Lng),
+                    ImageUrl = map.CreateMapLinkUrl(point.Latitude, point.Longitude),
+                    ThumbnailUrl = map.CreateStaticMapUrl(point.Latitude, point.Longitude),
                     TooltipText = null,
                 });
             }
index 8093e2b..21d21cb 100644 (file)
@@ -1632,7 +1632,8 @@ namespace OpenTween
                     post.IsFav = tc.Contains(retweeted.Id);
                 }
 
-                if (retweeted.Coordinates != null) post.PostGeo = new PostClass.StatusGeo { Lng = retweeted.Coordinates.Coordinates[0], Lat = retweeted.Coordinates.Coordinates[1] };
+                if (retweeted.Coordinates != null)
+                    post.PostGeo = new PostClass.StatusGeo(retweeted.Coordinates.Coordinates[0], retweeted.Coordinates.Coordinates[1]);
 
                 //以下、ユーザー情報
                 var user = retweeted.User;
@@ -1672,7 +1673,8 @@ namespace OpenTween
                     post.IsFav = tc.Contains(post.StatusId) && TabInformations.GetInstance()[post.StatusId].IsFav;
                 }
 
-                if (status.Coordinates != null) post.PostGeo = new PostClass.StatusGeo { Lng = status.Coordinates.Coordinates[0], Lat = status.Coordinates.Coordinates[1] };
+                if (status.Coordinates != null)
+                    post.PostGeo = new PostClass.StatusGeo(status.Coordinates.Coordinates[0], status.Coordinates.Coordinates[1]);
 
                 //以下、ユーザー情報
                 var user = status.User;