public static <T> String ToFormatString( final T data, final DataMemberMap<T> dataMemberMap, final String typeName) { checkNotNull(data); checkNotNull(dataMemberMap); checkNotNull(typeName); Iterable<String> formatMemberStrings = Iterables.Map( dataMemberMap.values(), new Func1<IDataMember<T>, String>() { @Override public String DoFunc(IDataMember<T> in1) { return DEFAULT_JOINER.join( in1.GetDataMemberName(), // 首先是DataMember的Name CommonOP.NullCoalescing( in1.GetDataSafely(data), "", NULL_VALUE)); // 然后是用DataMember从data获取的值,为空则设为NULL_VALUE } }); // return DEFAULT_JOINER.join(Iterables.Concat(typeName, formatMemberStrings)); return typeName + DEFAULT_SEPARATOR + DEFAULT_JOINER.join(formatMemberStrings); }
public static <T> void FillDataWithFormatString( final String dataString, final T data, final DataMemberMap<T> dataMemberMap, final String typeName) { checkNotNull(dataString); checkNotNull(data); checkNotNull(dataMemberMap); checkNotNull(typeName); Iterator<String> memberStrings = DEFAULT_SPLITTER.split(dataString).iterator(); checkArgument(memberStrings.hasNext()); checkArgument(memberStrings.next().equalsIgnoreCase(typeName), "Type name is wrong."); while (memberStrings.hasNext()) { String memberName = memberStrings.next(); checkArgument(memberStrings.hasNext(), "The dataString is wrong."); String memberValue = memberStrings.next(); dataMemberMap.SetDataInSourceSafely(memberValue, data, memberName); } }