java mono是什么,讓我們一起了解一下?
Mono是包含0或者1個元素的異步序列。該序列中同樣可以包含與Flux相同的三種類型的消息通知,Flux和Mono之間可以進行轉換,對一個Flux序列進行計數操作,得到的結果是一個 Mono
如何通過Mono靜態方法創建?
1、empty():創建一個不包含任何元素,只發布結束消息的序列。
2、just():可以指定序列中包含的全部元素。創建出來的 Mono序列在發布這些元素之后會自動結束。
3、justOrEmpty():從一個 Optional 對象或可能為 null 的對象中創建 Mono。只有 Optional 對象中包含值或對象不為 null 時,Mono 序列才產生對應的元素。
4、error(Throwable error):創建一個只包含錯誤消息的序列。
5、never():創建一個不包含任何消息通知的序列。
6、fromCallable()、fromCompletionStage()、fromFuture()、fromRunnable()和 fromSupplier():分別從 Callable、CompletionStage、CompletableFuture、Runnable 和 Supplier 中創建 Mono。
7、delay(Duration duration)和 delayMillis(long duration):創建一個 Mono 序列,在指定的延遲時間之后,產生數字 0 作為唯一值。
實戰操作,示例代碼如下:
using?System; using?System.Collections.Generic; using?System.Linq; using?System.Text; using?Android.App; using?Android.Content; using?Android.OS; using?Android.Runtime; using?Android.Views; using?Android.Widget; using?Java.Util; namespace?AndroidHotelServiceTest { [Activity(Label?=?"My?Activity")] public?class?ActivityCalendar?:?Activity { protected?override?Dialog?OnCreateDialog(int?id) { if?(id?==?1) { return?new?DatePickerDialog(this,?new?DDialogLisetener(this),?2013,?11,?11); } return?base.OnCreateDialog(0); } protected?override?void?OnCreate(Bundle?bundle) { base.OnCreate(bundle); //?Create?your?application?here SetContentView(Resource.Layout.CalendarView); Button?button?=?FindViewById(Resource.Id.btClose); button.Click?+=?delegate { Intent?intent?=?new?Intent(); intent.SetClass(this,?typeof(ActivityHotel)); StartActivity(intent); }; ShowDialog(1); } } public?class?DDialogLisetener?:?DatePickerDialog.IOnDateSetListener { private?Context?_context; public?DDialogLisetener(Context?context) { _context?=?context; } public?void?OnDateSet(DatePicker?view,?int?year,?int?monthOfYear,?int?dayOfMonth) { String?sDayOfWeek?=?getDayOfWeek(year,?monthOfYear,?dayOfMonth); //Toast.makeText(CreateParty.this,?"sdf",?Toast.LENGTH_LONG).show(); int?m_nYear?=?year; int?m_nMonth?=?monthOfYear?+?1; int?m_nDay?=?dayOfMonth; Toast.MakeText(_context,?"ddd",?ToastLength.Long).Show(); Toast.MakeText(_context,?m_nYear?+?"年"?+?m_nMonth?+?"月"?+?m_nDay?+?"日?",?ToastLength.Long).Show(); } private?string?getDayOfWeek(int?tmpYear,?int?tmpMonth,?int?tmpDay) { String?myWeek?=?null; String?sYear?=?tmpYear.ToString(); //?取年的后兩位 String?sYearTwo?=?sYear.Substring(sYear.Length?-?2); int?y?=?tmpYear; int?m?=?tmpMonth?+?1; int?c?=?20; int?d?=?tmpDay; int?w?=?(y?+?(y?/?4)?+?(c?/?4)?-?2?*?c +?(26?*?(m?+?1)?/?10)?+?d?-?1)?%?7; switch?(w) { case?0: myWeek?=?"日"; break; case?1: myWeek?=?"一"; break; case?2: myWeek?=?"二"; break; case?3: myWeek?=?"三"; break; case?4: myWeek?=?"四"; break; case?5: myWeek?=?"五"; break; case?6: myWeek?=?"六"; break; default: break; } return?myWeek; } public?void?Dispose() { this.Dispose(); } public?IntPtr?Handle { get?{?return?IntPtr.Zero;?} } } }
以上就是小編今天的分享了,希望可以幫助到大家。