001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2011 Richard "Shred" Körber 005 * http://flattr4j.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License / GNU Lesser 009 * General Public License as published by the Free Software Foundation, 010 * either version 3 of the License, or (at your option) any later version. 011 * 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 018 */ 019package org.shredzone.flattr4j.model; 020 021import org.shredzone.flattr4j.connector.FlattrObject; 022 023/** 024 * A single Language that is available for Things. Two {@link Language} are considered 025 * equal if they contain the same id. 026 * 027 * @author Richard "Shred" Körber 028 */ 029public class Language extends Resource implements LanguageId { 030 private static final long serialVersionUID = -2166187856968632922L; 031 032 /** 033 * Returns a {@link LanguageId} for the given Language id. 034 * 035 * @param id 036 * Language id 037 * @return A {@link LanguageId} object for this id 038 */ 039 public static LanguageId withId(final String id) { 040 return new LanguageId() { 041 @Override 042 public String getLanguageId() { 043 return id; 044 } 045 }; 046 } 047 048 public Language(FlattrObject data) { 049 super(data); 050 } 051 052 /** 053 * Language id to be used with Flattr. 054 */ 055 @Override 056 public String getLanguageId() { 057 return data.get("id"); 058 } 059 060 /** 061 * Language name to be used for humans. 062 */ 063 public String getName() { 064 return data.get("text"); 065 } 066 067 @Override 068 public boolean equals(Object obj) { 069 String pk = getLanguageId(); 070 071 if (pk == null || obj == null || !(obj instanceof Language)) { 072 return false; 073 } 074 075 return pk.equals(((Language) obj).getLanguageId()); 076 } 077 078 @Override 079 public int hashCode() { 080 String pk = getLanguageId(); 081 return (pk != null ? pk.hashCode() : 0); 082 } 083 084}