Permalink
Browse files

Exposing immutable LinkInfo from public API, with only properties ODa…

…ta sets.
  • Loading branch information...
1 parent c1e2126 commit 8cdcb8bdb71152b09c3b9d5ab55cd40f7feb3afb @christav christav committed Dec 13, 2012
@@ -26,6 +26,7 @@
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
import com.microsoft.windowsazure.services.media.implementation.atom.LinkType;
import com.microsoft.windowsazure.services.media.implementation.content.Constants;
+import com.microsoft.windowsazure.services.media.models.LinkInfo;
import com.microsoft.windowsazure.services.media.models.ListResult;
/**
@@ -87,12 +88,12 @@ public boolean hasLink(String rel) {
* rel of link to retrieve
* @return The link if found, null if not.
*/
- public LinkType getLink(String rel) {
+ public LinkInfo getLink(String rel) {
for (Object child : entry.getEntryChildren()) {
LinkType link = LinkFromChild(child);
if (link != null && link.getRel().equals(rel)) {
- return link;
+ return new LinkInfo(link);
}
}
return null;
@@ -103,12 +104,12 @@ public LinkType getLink(String rel) {
*
* @return List of the links.
*/
- public List<LinkType> getLinks() {
- ArrayList<LinkType> links = new ArrayList<LinkType>();
+ public List<LinkInfo> getLinks() {
+ ArrayList<LinkInfo> links = new ArrayList<LinkInfo>();
for (Object child : entry.getEntryChildren()) {
LinkType link = LinkFromChild(child);
if (link != null) {
- links.add(link);
+ links.add(new LinkInfo(link));
}
}
return links;
@@ -0,0 +1,69 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.microsoft.windowsazure.services.media.models;
+
+import com.microsoft.windowsazure.services.media.implementation.atom.LinkType;
+
+/**
+ * Provides access to OData links
+ *
+ */
+public class LinkInfo {
+ private final LinkType rawLink;
+
+ /**
+ * Construct a new {@link LinkInfo} instance
+ */
+ public LinkInfo(LinkType rawLink) {
+ this.rawLink = rawLink;
+ }
+
+ /**
+ * Get link rel
+ *
+ * @return the rel
+ */
+ public String getRel() {
+ return rawLink.getRel();
+ }
+
+ /**
+ * Get link type
+ *
+ * @return the type
+ */
+ public String getType() {
+ return rawLink.getType();
+ }
+
+ /**
+ * Get link href
+ *
+ * @return the href
+ */
+ public String getHref() {
+ return rawLink.getHref();
+ }
+
+ /**
+ * Get link title
+ *
+ * @return the title
+ */
+ public String getTitle() {
+ return rawLink.getTitle();
+ }
+}
@@ -30,6 +30,7 @@
import com.microsoft.windowsazure.services.media.implementation.atom.LinkType;
import com.microsoft.windowsazure.services.media.implementation.content.Constants;
import com.microsoft.windowsazure.services.media.implementation.content.MediaProcessorType;
+import com.microsoft.windowsazure.services.media.models.LinkInfo;
import com.microsoft.windowsazure.services.media.models.MediaProcessorInfo;
/**
@@ -85,7 +86,7 @@ public void getFalseWhenLinkIsntThere() {
@Test
public void canRetrieveEntireLinkByRel() {
- LinkType link = info.getLink(link2.getRel());
+ LinkInfo link = info.getLink(link2.getRel());
assertLinksEqual(link2, link);
}
@@ -97,16 +98,17 @@ public void getNullWhenLinkIsntThere() {
@Test
public void getLinksReturnsTwoExpectedLinksInOrder() {
- List<LinkType> links = info.getLinks();
+ List<LinkInfo> links = info.getLinks();
assertEquals(2, links.size());
assertLinksEqual(link1, links.get(0));
assertLinksEqual(link2, links.get(1));
}
- private static void assertLinksEqual(LinkType expected, LinkType actual) {
+ private static void assertLinksEqual(LinkType expected, LinkInfo actual) {
assertEquals(expected.getTitle(), actual.getTitle());
assertEquals(expected.getRel(), actual.getRel());
assertEquals(expected.getHref(), actual.getHref());
+ assertEquals(expected.getType(), actual.getType());
}
}

0 comments on commit 8cdcb8b

Please sign in to comment.