Coverage Report - org.apache.shindig.social.opensocial.spi.GroupId
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupId
72%
13/18
50%
5/10
0
GroupId$Type
100%
7/7
N/A
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements. See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License. You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied. See the License for the
 16  
  * specific language governing permissions and limitations under the License.
 17  
  */
 18  
 package org.apache.shindig.social.opensocial.spi;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 
 22  
 import com.google.common.collect.Maps;
 23  
 
 24  
 import java.util.Map;
 25  
 
 26  
 public class GroupId {
 27  8
   public enum Type {
 28  1
     all, friends, self, deleted, groupId;
 29  
 
 30  
     /** A map of JSON strings to Type objects */
 31  1
     private static final Map<String, Type> jsonTypeMap = Maps.newHashMap();
 32  
 
 33  
     static {
 34  6
       for (Type type : Type.values()) {
 35  5
         jsonTypeMap.put("@" + type.name(), type);
 36  
       }
 37  1
     }
 38  
     /** Return the Type enum value given a specific jsonType **/
 39  
     public static Type jsonValueOf(String jsonType) {
 40  70
        return jsonTypeMap.get(jsonType);
 41  
     }
 42  
   }
 43  
 
 44  
   private Type type;
 45  
   private String groupId;
 46  
 
 47  93
   public GroupId(Type type, String groupId) {
 48  93
     this.groupId = groupId;
 49  93
     this.type = type;
 50  93
   }
 51  
 
 52  
   public Type getType() {
 53  59
     return type;
 54  
   }
 55  
 
 56  
   public String getGroupId() {
 57  
     // Only valid for objects with type=groupId
 58  1
     return groupId;
 59  
   }
 60  
 
 61  
   public static GroupId fromJson(String jsonId) {
 62  70
     Type idSpecEnum = Type.jsonValueOf(jsonId);
 63  70
     if (idSpecEnum != null) {
 64  69
       return new GroupId(idSpecEnum, null);
 65  
     }
 66  
 
 67  1
     return new GroupId(Type.groupId, jsonId);
 68  
   }
 69  
 
 70  
   // These are overriden so that EasyMock doesn't throw a fit
 71  
   @Override
 72  
   public boolean equals(Object o) {
 73  20
     if (!(o instanceof GroupId)) {
 74  0
       return false;
 75  
     }
 76  
 
 77  20
     GroupId actual = (GroupId) o;
 78  20
     return this.type == actual.type
 79  
         && StringUtils.equals(this.groupId, actual.groupId);
 80  
   }
 81  
 
 82  
   @Override
 83  
   public int hashCode() {
 84  0
     int groupHashCode = 0;
 85  0
     if (this.groupId != null) {
 86  0
       groupHashCode = this.groupId.hashCode();
 87  
     }
 88  0
     return this.type.hashCode() + groupHashCode;
 89  
   }
 90  
 }