001/* 002 * Copyright (c) 2011-2018 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.account; 023 024import com.fasterxml.jackson.annotation.JsonCreator; 025import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 026import com.fasterxml.jackson.annotation.JsonProperty; 027import com.fasterxml.jackson.annotation.JsonValue; 028 029import java.math.BigDecimal; 030import java.util.HashMap; 031import java.util.Map; 032 033@JsonIgnoreProperties(ignoreUnknown = true) 034public class Network { 035 private Type type; 036 private BigDecimal price; 037 private String currency; 038 private String mcc; 039 private String mnc; 040 private String code; 041 private String name; 042 043 public Type getType() { 044 return type; 045 } 046 047 public BigDecimal getPrice() { 048 return price; 049 } 050 051 public String getCurrency() { 052 return currency; 053 } 054 055 public String getMcc() { 056 return mcc; 057 } 058 059 public String getMnc() { 060 return mnc; 061 } 062 063 @JsonProperty("networkCode") 064 public String getCode() { 065 return code; 066 } 067 068 @JsonProperty("networkName") 069 public String getName() { 070 return name; 071 } 072 073 enum Type { 074 MOBILE, LANDLINE, PAGER, LANDLINE_TOLLFREE, UNKNOWN; 075 076 private static final Map<String, Type> typesIndex = new HashMap<>(); 077 078 static { 079 for (Type type : Type.values()) { 080 typesIndex.put(type.toString(), type); 081 } 082 } 083 084 @Override 085 @JsonValue 086 public String toString() { 087 return name().toLowerCase(); 088 } 089 090 @JsonCreator 091 public static Type fromString(String type) { 092 Type foundType = typesIndex.get(type); 093 return (foundType != null) ? foundType : Type.UNKNOWN; 094 } 095 } 096}