|
| 1 | +/* |
| 2 | + * Copyright (c) 2024. MangoRage |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in all |
| 12 | + * copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 17 | + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE |
| 20 | + * OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + */ |
| 22 | + |
| 23 | +package org.mangorage.eventbus.event; |
| 24 | + |
| 25 | +import org.mangorage.eventbus.EventBus; |
| 26 | +import org.mangorage.eventbus.interfaces.IEvent; |
| 27 | +import org.mangorage.eventbus.interfaces.IEventBus; |
| 28 | +import org.mangorage.eventbus.interfaces.IEventType; |
| 29 | + |
| 30 | +public class Test { |
| 31 | + private static final IEventBus<IEventType.INormalBusEvent> BUS = EventBus.create(new NormalEventHandler(), IEventType.INormalBusEvent.class); |
| 32 | + |
| 33 | + public record Example(int amount) implements IEvent, IEventType.INormalBusEvent { |
| 34 | + } |
| 35 | + |
| 36 | + public record Example2(String name) implements IEvent, IEventType.INormalBusEvent { |
| 37 | + } |
| 38 | + |
| 39 | + public static void main(String[] args) { |
| 40 | + |
| 41 | + var clz = Object.class; |
| 42 | + if (!clz.isInterface()) { |
| 43 | + throw new IllegalStateException("oops"); |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + BUS.addListener(1, Example.class, e -> { |
| 48 | + System.out.println(e.amount()); |
| 49 | + }); |
| 50 | + BUS.addListener(1, Example2.class, e -> { |
| 51 | + System.out.println(e.name()); |
| 52 | + }); |
| 53 | + |
| 54 | + BUS.post(new Example(100)); |
| 55 | + BUS.post(new Example2("LOL")); |
| 56 | + } |
| 57 | +} |
0 commit comments