Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D2181200CCF for ; Mon, 10 Jul 2017 02:10:21 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D0695167DFE; Mon, 10 Jul 2017 00:10:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 88805167DE7 for ; Mon, 10 Jul 2017 02:10:19 +0200 (CEST) Received: (qmail 87724 invoked by uid 500); 10 Jul 2017 00:10:18 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 87715 invoked by uid 99); 10 Jul 2017 00:10:18 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2017 00:10:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2AFE61812D2 for ; Mon, 10 Jul 2017 00:10:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.022 X-Spam-Level: X-Spam-Status: No, score=-5.022 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id gAIo56LtUfzG for ; Mon, 10 Jul 2017 00:09:56 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id D8F62623EB for ; Mon, 10 Jul 2017 00:09:15 +0000 (UTC) Received: (qmail 87153 invoked by uid 99); 10 Jul 2017 00:09:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2017 00:09:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E421AF32B5; Mon, 10 Jul 2017 00:09:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Mon, 10 Jul 2017 00:09:27 -0000 Message-Id: In-Reply-To: <08221ca5342b46a28c50a50a900a508b@git.apache.org> References: <08221ca5342b46a28c50a50a900a508b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [15/23] incubator-juneau-website git commit: Update javadocs. archived-at: Mon, 10 Jul 2017 00:10:22 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/03d6af50/content/site/apidocs/src-html/org/apache/juneau/ObjectMap.html ---------------------------------------------------------------------- diff --git a/content/site/apidocs/src-html/org/apache/juneau/ObjectMap.html b/content/site/apidocs/src-html/org/apache/juneau/ObjectMap.html index f02d7d8..301f0de 100644 --- a/content/site/apidocs/src-html/org/apache/juneau/ObjectMap.html +++ b/content/site/apidocs/src-html/org/apache/juneau/ObjectMap.html @@ -662,740 +662,746 @@ 654 Object s = get(Object.class, key); 655 if (s == null) 656 return def; -657 if (s instanceof Collection) -658 return ArrayUtils.toStringArray((Collection<?>)s); -659 String[] r = split(StringUtils.toString(s)); -660 return (r.length == 0 ? def : r); -661 } -662 -663 /** -664 * Returns the specified entry value converted to a {@link String}. -665 * -666 * <p> -667 * Shortcut for <code>get(String.<jk>class</jk>, key, defVal)</code>. -668 * -669 * @param key The key. -670 * @param defVal The default value if the map doesn't contain the specified mapping. -671 * @return The converted value, or the default value if the map contains no mapping for this key. -672 */ -673 public String getString(String key, String defVal) { -674 return get(String.class, key, defVal); -675 } -676 -677 /** -678 * Returns the specified entry value converted to an {@link Integer}. -679 * -680 * <p> -681 * Shortcut for <code>get(Integer.<jk>class</jk>, key)</code>. -682 * -683 * @param key The key. -684 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -685 * @throws InvalidDataConversionException If value cannot be converted. -686 */ -687 public Integer getInt(String key) { -688 return get(Integer.class, key); -689 } -690 -691 /** -692 * Returns the specified entry value converted to an {@link Integer}. -693 * -694 * <p> -695 * Shortcut for <code>get(Integer.<jk>class</jk>, key, defVal)</code>. -696 * -697 * @param key The key. -698 * @param defVal The default value if the map doesn't contain the specified mapping. -699 * @return The converted value, or the default value if the map contains no mapping for this key. -700 * @throws InvalidDataConversionException If value cannot be converted. -701 */ -702 public Integer getInt(String key, Integer defVal) { -703 return get(Integer.class, key, defVal); -704 } -705 -706 /** -707 * Returns the specified entry value converted to a {@link Long}. -708 * -709 * <p> -710 * Shortcut for <code>get(Long.<jk>class</jk>, key)</code>. -711 * -712 * @param key The key. -713 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -714 * @throws InvalidDataConversionException If value cannot be converted. -715 */ -716 public Long getLong(String key) { -717 return get(Long.class, key); -718 } -719 -720 /** -721 * Returns the specified entry value converted to a {@link Long}. -722 * -723 * <p> -724 * Shortcut for <code>get(Long.<jk>class</jk>, key, defVal)</code>. -725 * -726 * @param key The key. -727 * @param defVal The default value if the map doesn't contain the specified mapping. -728 * @return The converted value, or the default value if the map contains no mapping for this key. -729 * @throws InvalidDataConversionException If value cannot be converted. -730 */ -731 public Long getLong(String key, Long defVal) { -732 return get(Long.class, key, defVal); -733 } -734 -735 /** -736 * Returns the specified entry value converted to a {@link Boolean}. -737 * -738 * <p> -739 * Shortcut for <code>get(Boolean.<jk>class</jk>, key)</code>. -740 * -741 * @param key The key. -742 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -743 * @throws InvalidDataConversionException If value cannot be converted. -744 */ -745 public Boolean getBoolean(String key) { -746 return get(Boolean.class, key); -747 } -748 -749 /** -750 * Returns the specified entry value converted to a {@link Boolean}. -751 * -752 * <p> -753 * Shortcut for <code>get(Boolean.<jk>class</jk>, key, defVal)</code>. -754 * -755 * @param key The key. -756 * @param defVal The default value if the map doesn't contain the specified mapping. -757 * @return The converted value, or the default value if the map contains no mapping for this key. -758 * @throws InvalidDataConversionException If value cannot be converted. -759 */ -760 public Boolean getBoolean(String key, Boolean defVal) { -761 return get(Boolean.class, key, defVal); -762 } -763 -764 /** -765 * Returns the specified entry value converted to a {@link Map}. -766 * -767 * <p> -768 * Shortcut for <code>get(Map.<jk>class</jk>, key)</code>. -769 * -770 * @param key The key. -771 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -772 * @throws InvalidDataConversionException If value cannot be converted. -773 */ -774 public Map<?,?> getMap(String key) { -775 return get(Map.class, key); -776 } -777 -778 /** -779 * Returns the specified entry value converted to a {@link Map}. -780 * -781 * <p> -782 * Shortcut for <code>get(Map.<jk>class</jk>, key, defVal)</code>. -783 * -784 * @param key The key. -785 * @param defVal The default value if the map doesn't contain the specified mapping. -786 * @return The converted value, or the default value if the map contains no mapping for this key. -787 * @throws InvalidDataConversionException If value cannot be converted. -788 */ -789 public Map<?,?> getMap(String key, Map<?,?> defVal) { -790 return get(Map.class, key, defVal); -791 } -792 -793 /** -794 * Returns the specified entry value converted to a {@link List}. -795 * -796 * <p> -797 * Shortcut for <code>get(List.<jk>class</jk>, key)</code>. -798 * -799 * @param key The key. -800 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -801 * @throws InvalidDataConversionException If value cannot be converted. -802 */ -803 public List<?> getList(String key) { -804 return get(List.class, key); -805 } -806 -807 /** -808 * Returns the specified entry value converted to a {@link List}. -809 * -810 * <p> -811 * Shortcut for <code>get(List.<jk>class</jk>, key, defVal)</code>. -812 * -813 * @param key The key. -814 * @param defVal The default value if the map doesn't contain the specified mapping. -815 * @return The converted value, or the default value if the map contains no mapping for this key. -816 * @throws InvalidDataConversionException If value cannot be converted. -817 */ -818 public List<?> getList(String key, List<?> defVal) { -819 return get(List.class, key, defVal); -820 } -821 -822 /** -823 * Returns the specified entry value converted to a {@link Map}. -824 * -825 * <p> -826 * Shortcut for <code>get(ObjectMap.<jk>class</jk>, key)</code>. -827 * -828 * @param key The key. -829 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -830 * @throws InvalidDataConversionException If value cannot be converted. -831 */ -832 public ObjectMap getObjectMap(String key) { -833 return get(ObjectMap.class, key); -834 } -835 -836 /** -837 * Returns the specified entry value converted to a {@link ObjectMap}. -838 * -839 * <p> -840 * Shortcut for <code>get(ObjectMap.<jk>class</jk>, key, defVal)</code>. -841 * -842 * @param key The key. -843 * @param defVal The default value if the map doesn't contain the specified mapping. -844 * @return The converted value, or the default value if the map contains no mapping for this key. -845 * @throws InvalidDataConversionException If value cannot be converted. -846 */ -847 public ObjectMap getObjectMap(String key, ObjectMap defVal) { -848 return get(ObjectMap.class, key, defVal); -849 } -850 -851 /** -852 * Returns the specified entry value converted to a {@link ObjectList}. -853 * -854 * <p> -855 * Shortcut for <code>get(ObjectList.<jk>class</jk>, key)</code>. -856 * -857 * @param key The key. -858 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. -859 * @throws InvalidDataConversionException If value cannot be converted. -860 */ -861 public ObjectList getObjectList(String key) { -862 return get(ObjectList.class, key); -863 } -864 -865 /** -866 * Returns the specified entry value converted to a {@link ObjectList}. -867 * -868 * <p> -869 * Shortcut for <code>get(ObjectList.<jk>class</jk>, key, defVal)</code>. -870 * -871 * @param key The key. -872 * @param defVal The default value if the map doesn't contain the specified mapping. -873 * @return The converted value, or the default value if the map contains no mapping for this key. -874 * @throws InvalidDataConversionException If value cannot be converted. -875 */ -876 public ObjectList getObjectList(String key, ObjectList defVal) { -877 return get(ObjectList.class, key, defVal); -878 } -879 -880 /** -881 * Returns the first entry that exists converted to a {@link String}. -882 * -883 * <p> -884 * Shortcut for <code>find(String.<jk>class</jk>, keys)</code>. -885 * -886 * @param keys The list of keys to look for. -887 * @return -888 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -889 * contains no mapping for any of the keys. -890 */ -891 public String findString(String... keys) { -892 return find(String.class, keys); -893 } -894 -895 /** -896 * Returns the first entry that exists converted to an {@link Integer}. -897 * -898 * <p> -899 * Shortcut for <code>find(Integer.<jk>class</jk>, keys)</code>. -900 * -901 * @param keys The list of keys to look for. -902 * @return -903 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -904 * contains no mapping for any of the keys. -905 * @throws InvalidDataConversionException If value cannot be converted. -906 */ -907 public Integer findInt(String... keys) { -908 return find(Integer.class, keys); -909 } -910 -911 /** -912 * Returns the first entry that exists converted to a {@link Long}. -913 * -914 * <p> -915 * Shortcut for <code>find(Long.<jk>class</jk>, keys)</code>. -916 * -917 * @param keys The list of keys to look for. -918 * @return -919 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -920 * contains no mapping for any of the keys. -921 * @throws InvalidDataConversionException If value cannot be converted. -922 */ -923 public Long findLong(String... keys) { -924 return find(Long.class, keys); -925 } -926 -927 /** -928 * Returns the first entry that exists converted to a {@link Boolean}. -929 * -930 * <p> -931 * Shortcut for <code>find(Boolean.<jk>class</jk>, keys)</code>. -932 * -933 * @param keys The list of keys to look for. -934 * @return -935 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -936 * contains no mapping for any of the keys. -937 * @throws InvalidDataConversionException If value cannot be converted. -938 */ -939 public Boolean findBoolean(String... keys) { -940 return find(Boolean.class, keys); -941 } -942 -943 /** -944 * Returns the first entry that exists converted to a {@link Map}. -945 * -946 * <p> -947 * Shortcut for <code>find(Map.<jk>class</jk>, keys)</code>. -948 * -949 * @param keys The list of keys to look for. -950 * @return -951 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -952 * contains no mapping for any of the keys. -953 * @throws InvalidDataConversionException If value cannot be converted. -954 */ -955 public Map<?,?> findMap(String... keys) { -956 return find(Map.class, keys); -957 } -958 -959 /** -960 * Returns the first entry that exists converted to a {@link List}. -961 * -962 * <p> -963 * Shortcut for <code>find(List.<jk>class</jk>, keys)</code>. -964 * -965 * @param keys The list of keys to look for. -966 * @return -967 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -968 * contains no mapping for any of the keys. -969 * @throws InvalidDataConversionException If value cannot be converted. -970 */ -971 public List<?> findList(String... keys) { -972 return find(List.class, keys); -973 } -974 -975 /** -976 * Returns the first entry that exists converted to a {@link ObjectMap}. -977 * -978 * <p> -979 * Shortcut for <code>find(ObjectMap.<jk>class</jk>, keys)</code>. -980 * -981 * @param keys The list of keys to look for. -982 * @return -983 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -984 * contains no mapping for any of the keys. -985 * @throws InvalidDataConversionException If value cannot be converted. -986 */ -987 public ObjectMap findObjectMap(String... keys) { -988 return find(ObjectMap.class, keys); -989 } -990 -991 /** -992 * Returns the first entry that exists converted to a {@link ObjectList}. -993 * -994 * <p> -995 * Shortcut for <code>find(ObjectList.<jk>class</jk>, keys)</code>. -996 * -997 * @param keys The list of keys to look for. -998 * @return -999 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map -1000 * contains no mapping for any of the keys. -1001 * @throws InvalidDataConversionException If value cannot be converted. -1002 */ -1003 public ObjectList findObjectList(String... keys) { -1004 return find(ObjectList.class, keys); -1005 } -1006 -1007 /** -1008 * Returns the first key in the map. -1009 * -1010 * @return The first key in the map, or <jk>null</jk> if the map is empty. -1011 */ -1012 public String getFirstKey() { -1013 return isEmpty() ? null : keySet().iterator().next(); -1014 } -1015 -1016 /** -1017 * Returns the class type of the object at the specified index. -1018 * -1019 * @param key The key into this map. -1020 * @return -1021 * The data type of the object at the specified key, or <jk>null</jk> if the value is null or does not exist. -1022 */ -1023 public ClassMeta<?> getClassMeta(String key) { -1024 return session.getClassMetaForObject(get(key)); -1025 } -1026 -1027 /** -1028 * Equivalent to calling <code>get(class,key,def)</code> followed by <code>remove(key);</code> -1029 * -1030 * @param <T> The class type. -1031 * @param type The class type. -1032 * @param key The key. -1033 * @param defVal The default value if the map doesn't contain the specified mapping. -1034 * @return The converted value, or the default value if the map contains no mapping for this key. -1035 * @throws InvalidDataConversionException If value cannot be converted. -1036 */ -1037 public <T> T remove(Class<T> type, String key, T defVal) { -1038 T t = get(type, key, defVal); -1039 remove(key); -1040 return t; -1041 } -1042 -1043 -1044 /** -1045 * Convenience method for removing several keys at once. -1046 * -1047 * @param keys The list of keys to remove. -1048 */ -1049 public void removeAll(Collection<String> keys) { -1050 for (String k : keys) -1051 remove(k); -1052 } -1053 -1054 /** -1055 * Convenience method for removing several keys at once. -1056 * -1057 * @param keys The list of keys to remove. -1058 */ -1059 public void removeAll(String... keys) { -1060 for (String k : keys) -1061 remove(k); -1062 } -1063 -1064 @Override /* Map */ -1065 public boolean containsKey(Object key) { -1066 if (super.containsKey(key)) -1067 return true; -1068 if (inner != null) -1069 return inner.containsKey(key); -1070 return false; -1071 } -1072 -1073 /** -1074 * Returns <jk>true</jk> if this map contains the specified key, ignoring the inner map if it exists. -1075 * -1076 * @param key The key to look up. -1077 * @return <jk>true</jk> if this map contains the specified key. -1078 */ -1079 public boolean containsOuterKey(Object key) { -1080 return super.containsKey(key); -1081 } -1082 -1083 /** -1084 * Returns a copy of this <code>ObjectMap</code> with only the specified keys. -1085 * -1086 * @param keys The keys of the entries to copy. -1087 * @return A new map with just the keys and values from this map. -1088 */ -1089 public ObjectMap include(String...keys) { -1090 ObjectMap m2 = new ObjectMap(); -1091 for (Map.Entry<String,Object> e : this.entrySet()) -1092 for (String k : keys) -1093 if (k.equals(e.getKey())) -1094 m2.put(k, e.getValue()); -1095 return m2; -1096 } -1097 -1098 /** -1099 * Returns a copy of this <code>ObjectMap</code> without the specified keys. -1100 * -1101 * @param keys The keys of the entries not to copy. -1102 * @return A new map without the keys and values from this map. -1103 */ -1104 public ObjectMap exclude(String...keys) { -1105 ObjectMap m2 = new ObjectMap(); -1106 for (Map.Entry<String,Object> e : this.entrySet()) { -1107 boolean exclude = false; -1108 for (String k : keys) -1109 if (k.equals(e.getKey())) -1110 exclude = true; -1111 if (! exclude) -1112 m2.put(e.getKey(), e.getValue()); -1113 } -1114 return m2; -1115 } -1116 -1117 /** -1118 * Sets a value in this map if the entry does not exist or the value is <jk>null</jk>. -1119 * -1120 * @param key The map key. -1121 * @param val The value to set if the current value does not exist or is <jk>null</jk>. -1122 * @return This object (for method chaining). -1123 */ -1124 public ObjectMap putIfNull(String key, Object val) { -1125 Object o = get(key); -1126 if (o == null) -1127 put(key, val); -1128 return this; -1129 } -1130 -1131 /** -1132 * Sets a value in this map if the entry does not exist or the value is <jk>null</jk> or an empty string. -1133 * -1134 * @param key The map key. -1135 * @param val The value to set if the current value does not exist or is <jk>null</jk> or an empty string. -1136 * @return This object (for method chaining). -1137 */ -1138 public ObjectMap putIfEmpty(String key, Object val) { -1139 Object o = get(key); -1140 if (o == null || o.toString().isEmpty()) -1141 put(key, val); -1142 return this; -1143 } -1144 -1145 /** -1146 * Converts this map into an object of the specified type. -1147 * -1148 * <p> -1149 * If this map contains a <js>"_type"</js> entry, it must be the same as or a subclass of the <code>type</code>. -1150 * -1151 * @param <T> The class type to convert this map object to. -1152 * @param type The class type to convert this map object to. -1153 * @return The new object. -1154 * @throws ClassCastException -1155 * If the <js>"_type"</js> entry is present and not assignable from <code>type</code> -1156 */ -1157 @SuppressWarnings("unchecked") -1158 public <T> T cast(Class<T> type) { -1159 ClassMeta<?> c2 = session.getClassMeta(type); -1160 String typePropertyName = session.getBeanTypePropertyName(c2); -1161 ClassMeta<?> c1 = session.getBeanRegistry().getClassMeta((String)get(typePropertyName)); -1162 ClassMeta<?> c = c1 == null ? c2 : narrowClassMeta(c1, c2); -1163 if (c.isObject()) -1164 return (T)this; -1165 return (T)cast2(c); -1166 } -1167 -1168 /** -1169 * Same as {@link #cast(Class)}, except allows you to specify a {@link ClassMeta} parameter. -1170 * -1171 * @param <T> The class type to convert this map object to. -1172 * @param cm The class type to convert this map object to. -1173 * @return The new object. -1174 * @throws ClassCastException -1175 * If the <js>"_type"</js> entry is present and not assignable from <code>type</code> -1176 */ -1177 @SuppressWarnings({"unchecked"}) -1178 public <T> T cast(ClassMeta<T> cm) { -1179 ClassMeta<?> c1 = session.getBeanRegistry().getClassMeta((String)get(session.getBeanTypePropertyName(cm))); -1180 ClassMeta<?> c = narrowClassMeta(c1, cm); -1181 return (T)cast2(c); -1182 } -1183 -1184 /* -1185 * Combines the class specified by a "_type" attribute with the ClassMeta -1186 * passed in through the cast(ClassMeta) method. -1187 * The rule is that child classes supersede parent classes, and c2 supersedes c1 -1188 * if one isn't the parent of another. -1189 */ -1190 private ClassMeta<?> narrowClassMeta(ClassMeta<?> c1, ClassMeta<?> c2) { -1191 if (c1 == null) -1192 return c2; -1193 ClassMeta<?> c = getNarrowedClassMeta(c1, c2); -1194 if (c1.isMap()) { -1195 ClassMeta<?> k = getNarrowedClassMeta(c1.getKeyType(), c2.getKeyType()); -1196 ClassMeta<?> v = getNarrowedClassMeta(c1.getValueType(), c2.getValueType()); -1197 return session.getClassMeta(c.getInnerClass(), k, v); -1198 } -1199 if (c1.isCollection()) { -1200 ClassMeta<?> e = getNarrowedClassMeta(c1.getElementType(), c2.getElementType()); -1201 return session.getClassMeta(c.getInnerClass(), e); -1202 } -1203 return c; -1204 } -1205 -1206 /* -1207 * If c1 is a child of c2 or the same as c2, returns c1. -1208 * Otherwise, returns c2. -1209 */ -1210 private static ClassMeta<?> getNarrowedClassMeta(ClassMeta<?> c1, ClassMeta<?> c2) { -1211 if (c2 == null || isParentClass(c2.getInnerClass(), c1.getInnerClass())) -1212 return c1; -1213 return c2; -1214 } -1215 -1216 /* -1217 * Converts this map to the specified class type. -1218 */ -1219 @SuppressWarnings({"unchecked","rawtypes"}) -1220 private <T> T cast2(ClassMeta<T> cm) { +657 String[] r = null; +658 if (s instanceof Collection) +659 r = ArrayUtils.toStringArray((Collection<?>)s); +660 else if (s instanceof String[]) +661 r = (String[])s; +662 else if (s instanceof Object[]) +663 r = ArrayUtils.toStringArray(Arrays.asList((Object[])s)); +664 else +665 r = split(StringUtils.toString(s)); +666 return (r.length == 0 ? def : r); +667 } +668 +669 /** +670 * Returns the specified entry value converted to a {@link String}. +671 * +672 * <p> +673 * Shortcut for <code>get(String.<jk>class</jk>, key, defVal)</code>. +674 * +675 * @param key The key. +676 * @param defVal The default value if the map doesn't contain the specified mapping. +677 * @return The converted value, or the default value if the map contains no mapping for this key. +678 */ +679 public String getString(String key, String defVal) { +680 return get(String.class, key, defVal); +681 } +682 +683 /** +684 * Returns the specified entry value converted to an {@link Integer}. +685 * +686 * <p> +687 * Shortcut for <code>get(Integer.<jk>class</jk>, key)</code>. +688 * +689 * @param key The key. +690 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +691 * @throws InvalidDataConversionException If value cannot be converted. +692 */ +693 public Integer getInt(String key) { +694 return get(Integer.class, key); +695 } +696 +697 /** +698 * Returns the specified entry value converted to an {@link Integer}. +699 * +700 * <p> +701 * Shortcut for <code>get(Integer.<jk>class</jk>, key, defVal)</code>. +702 * +703 * @param key The key. +704 * @param defVal The default value if the map doesn't contain the specified mapping. +705 * @return The converted value, or the default value if the map contains no mapping for this key. +706 * @throws InvalidDataConversionException If value cannot be converted. +707 */ +708 public Integer getInt(String key, Integer defVal) { +709 return get(Integer.class, key, defVal); +710 } +711 +712 /** +713 * Returns the specified entry value converted to a {@link Long}. +714 * +715 * <p> +716 * Shortcut for <code>get(Long.<jk>class</jk>, key)</code>. +717 * +718 * @param key The key. +719 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +720 * @throws InvalidDataConversionException If value cannot be converted. +721 */ +722 public Long getLong(String key) { +723 return get(Long.class, key); +724 } +725 +726 /** +727 * Returns the specified entry value converted to a {@link Long}. +728 * +729 * <p> +730 * Shortcut for <code>get(Long.<jk>class</jk>, key, defVal)</code>. +731 * +732 * @param key The key. +733 * @param defVal The default value if the map doesn't contain the specified mapping. +734 * @return The converted value, or the default value if the map contains no mapping for this key. +735 * @throws InvalidDataConversionException If value cannot be converted. +736 */ +737 public Long getLong(String key, Long defVal) { +738 return get(Long.class, key, defVal); +739 } +740 +741 /** +742 * Returns the specified entry value converted to a {@link Boolean}. +743 * +744 * <p> +745 * Shortcut for <code>get(Boolean.<jk>class</jk>, key)</code>. +746 * +747 * @param key The key. +748 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +749 * @throws InvalidDataConversionException If value cannot be converted. +750 */ +751 public Boolean getBoolean(String key) { +752 return get(Boolean.class, key); +753 } +754 +755 /** +756 * Returns the specified entry value converted to a {@link Boolean}. +757 * +758 * <p> +759 * Shortcut for <code>get(Boolean.<jk>class</jk>, key, defVal)</code>. +760 * +761 * @param key The key. +762 * @param defVal The default value if the map doesn't contain the specified mapping. +763 * @return The converted value, or the default value if the map contains no mapping for this key. +764 * @throws InvalidDataConversionException If value cannot be converted. +765 */ +766 public Boolean getBoolean(String key, Boolean defVal) { +767 return get(Boolean.class, key, defVal); +768 } +769 +770 /** +771 * Returns the specified entry value converted to a {@link Map}. +772 * +773 * <p> +774 * Shortcut for <code>get(Map.<jk>class</jk>, key)</code>. +775 * +776 * @param key The key. +777 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +778 * @throws InvalidDataConversionException If value cannot be converted. +779 */ +780 public Map<?,?> getMap(String key) { +781 return get(Map.class, key); +782 } +783 +784 /** +785 * Returns the specified entry value converted to a {@link Map}. +786 * +787 * <p> +788 * Shortcut for <code>get(Map.<jk>class</jk>, key, defVal)</code>. +789 * +790 * @param key The key. +791 * @param defVal The default value if the map doesn't contain the specified mapping. +792 * @return The converted value, or the default value if the map contains no mapping for this key. +793 * @throws InvalidDataConversionException If value cannot be converted. +794 */ +795 public Map<?,?> getMap(String key, Map<?,?> defVal) { +796 return get(Map.class, key, defVal); +797 } +798 +799 /** +800 * Returns the specified entry value converted to a {@link List}. +801 * +802 * <p> +803 * Shortcut for <code>get(List.<jk>class</jk>, key)</code>. +804 * +805 * @param key The key. +806 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +807 * @throws InvalidDataConversionException If value cannot be converted. +808 */ +809 public List<?> getList(String key) { +810 return get(List.class, key); +811 } +812 +813 /** +814 * Returns the specified entry value converted to a {@link List}. +815 * +816 * <p> +817 * Shortcut for <code>get(List.<jk>class</jk>, key, defVal)</code>. +818 * +819 * @param key The key. +820 * @param defVal The default value if the map doesn't contain the specified mapping. +821 * @return The converted value, or the default value if the map contains no mapping for this key. +822 * @throws InvalidDataConversionException If value cannot be converted. +823 */ +824 public List<?> getList(String key, List<?> defVal) { +825 return get(List.class, key, defVal); +826 } +827 +828 /** +829 * Returns the specified entry value converted to a {@link Map}. +830 * +831 * <p> +832 * Shortcut for <code>get(ObjectMap.<jk>class</jk>, key)</code>. +833 * +834 * @param key The key. +835 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +836 * @throws InvalidDataConversionException If value cannot be converted. +837 */ +838 public ObjectMap getObjectMap(String key) { +839 return get(ObjectMap.class, key); +840 } +841 +842 /** +843 * Returns the specified entry value converted to a {@link ObjectMap}. +844 * +845 * <p> +846 * Shortcut for <code>get(ObjectMap.<jk>class</jk>, key, defVal)</code>. +847 * +848 * @param key The key. +849 * @param defVal The default value if the map doesn't contain the specified mapping. +850 * @return The converted value, or the default value if the map contains no mapping for this key. +851 * @throws InvalidDataConversionException If value cannot be converted. +852 */ +853 public ObjectMap getObjectMap(String key, ObjectMap defVal) { +854 return get(ObjectMap.class, key, defVal); +855 } +856 +857 /** +858 * Returns the specified entry value converted to a {@link ObjectList}. +859 * +860 * <p> +861 * Shortcut for <code>get(ObjectList.<jk>class</jk>, key)</code>. +862 * +863 * @param key The key. +864 * @return The converted value, or <jk>null</jk> if the map contains no mapping for this key. +865 * @throws InvalidDataConversionException If value cannot be converted. +866 */ +867 public ObjectList getObjectList(String key) { +868 return get(ObjectList.class, key); +869 } +870 +871 /** +872 * Returns the specified entry value converted to a {@link ObjectList}. +873 * +874 * <p> +875 * Shortcut for <code>get(ObjectList.<jk>class</jk>, key, defVal)</code>. +876 * +877 * @param key The key. +878 * @param defVal The default value if the map doesn't contain the specified mapping. +879 * @return The converted value, or the default value if the map contains no mapping for this key. +880 * @throws InvalidDataConversionException If value cannot be converted. +881 */ +882 public ObjectList getObjectList(String key, ObjectList defVal) { +883 return get(ObjectList.class, key, defVal); +884 } +885 +886 /** +887 * Returns the first entry that exists converted to a {@link String}. +888 * +889 * <p> +890 * Shortcut for <code>find(String.<jk>class</jk>, keys)</code>. +891 * +892 * @param keys The list of keys to look for. +893 * @return +894 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map +895 * contains no mapping for any of the keys. +896 */ +897 public String findString(String... keys) { +898 return find(String.class, keys); +899 } +900 +901 /** +902 * Returns the first entry that exists converted to an {@link Integer}. +903 * +904 * <p> +905 * Shortcut for <code>find(Integer.<jk>class</jk>, keys)</code>. +906 * +907 * @param keys The list of keys to look for. +908 * @return +909 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map +910 * contains no mapping for any of the keys. +911 * @throws InvalidDataConversionException If value cannot be converted. +912 */ +913 public Integer findInt(String... keys) { +914 return find(Integer.class, keys); +915 } +916 +917 /** +918 * Returns the first entry that exists converted to a {@link Long}. +919 * +920 * <p> +921 * Shortcut for <code>find(Long.<jk>class</jk>, keys)</code>. +922 * +923 * @param keys The list of keys to look for. +924 * @return +925 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map +926 * contains no mapping for any of the keys. +927 * @throws InvalidDataConversionException If value cannot be converted. +928 */ +929 public Long findLong(String... keys) { +930 return find(Long.class, keys); +931 } +932 +933 /** +934 * Returns the first entry that exists converted to a {@link Boolean}. +935 * +936 * <p> +937 * Shortcut for <code>find(Boolean.<jk>class</jk>, keys)</code>. +938 * +939 * @param keys The list of keys to look for. +940 * @return +941 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map +942 * contains no mapping for any of the keys. +943 * @throws InvalidDataConversionException If value cannot be converted. +944 */ +945 public Boolean findBoolean(String... keys) { +946 return find(Boolean.class, keys); +947 } +948 +949 /** +950 * Returns the first entry that exists converted to a {@link Map}. +951 * +952 * <p> +953 * Shortcut for <code>find(Map.<jk>class</jk>, keys)</code>. +954 * +955 * @param keys The list of keys to look for. +956 * @return +957 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map +958 * contains no mapping for any of the keys. +959 * @throws InvalidDataConversionException If value cannot be converted. +960 */ +961 public Map<?,?> findMap(String... keys) { +962 return find(Map.class, keys); +963 } +964 +965 /** +966 * Returns the first entry that exists converted to a {@link List}. +967 * +968 * <p> +969 * Shortcut for <code>find(List.<jk>class</jk>, keys)</code>. +970 * +971 * @param keys The list of keys to look for. +972 * @return +973 * The converted value of the first key in the list that has an entry in this map, or <jk>null</jk> if the map +974 * contains no mapping for any of the keys. +975 * @throws InvalidDataConversionException If value cannot be converted. +976 */ +977 public List<?> findList(String... keys) { +978 return find(List.class, keys); +979 } +980 +981 /** +982 * Returns the first entry that exists converted to a {@link ObjectMap}. +983 * +984 * <p> +985 * Shortcut for <code>find(ObjectMap.<jk>class</jk>, keys)</code>. +986 * +987 * @param keys The list of keys to look for. +988 * @return +