IT科技

當前位置 /首頁/IT科技 > /列表

mono,java

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java mono是什麼,讓我們一起了解一下?

Mono是包含0或者1個元素的非同步序列。該序列中同樣可以包含與Flux相同的三種類型的訊息通知,Flux和Mono之間可以進行轉換,對一個Flux序列進行計數操作,得到的結果是一個 Mono

如何通過Mono靜態方法建立?

1、empty():建立一個不包含任何元素,只發布結束訊息的序列。

2、just():可以指定序列中包含的全部元素。創建出來的 Mono序列在釋出這些元素之後會自動結束。

3、justOrEmpty():從一個 Optional 物件或可能為 null 的物件中建立 Mono。只有 Optional 物件中包含值或物件不為 null 時,Mono 序列才產生對應的元素。

java 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 hereSetContentView(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; }}}}

TAG標籤:java mono #