java – ¿Cómo limpiar los datos de mi grafico barchart MPAndroidChart?

tengo una consulta y es la siguiente:

Estoy consumiendo un servicio rest que consulta datos con retrofit y los muestro en un gráfico usando MPAndroidChart, el problema es que cada consulta que realizo se queda la información anterior almacenada en el gráfico.

Y lo que deseo es que no suceda eso y solo muestre la información que se consulta.

Mi código

private void ConsultarxMeses(String fecha1,String fecha2){

        Call<List<ListaGrafico>> call = dashboardRest.ConsultarxMeses(fecha1,fecha2);
        call.enqueue(new Callback<List<ListaGrafico>>() {
            @Override
            public void onResponse(Call<List<ListaGrafico>> call, Response<List<ListaGrafico>> response) {
                if(!response.isSuccessful()){
                    Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_SHORT).show();
                    return;
                }
                List<ListaGrafico> dataGrafico = response.body();
                CreateGrafico(dataGrafico);

            }

            @Override
            public void onFailure(Call<List<ListaGrafico>> call, Throwable t) {
                Toast.makeText(MainActivity.this,t.getMessage(),Toast.LENGTH_SHORT).show();
            }
        });
    }

Método de crear Gráfico

private void CreateGrafico(List<ListaGrafico> t){

        ArrayList<String> labelsname= new ArrayList<>();
        ArrayList<BarEntry> barEntries= new ArrayList<>();
        ArrayList<Integer> colores= new ArrayList<>();
        Description description = new Description();
        description.setText("Gráfico Estadístico");

        barChart.setDescription(description);

        BarEntry barDescarga = new BarEntry(0,t.get(0).getDescarga());
        barEntries.add(barDescarga);
        BarEntry barRetiro = new BarEntry(1,t.get(0).getRetiro());
        barEntries.add(barRetiro);
        BarEntry barExportacion = new BarEntry(2,t.get(0).getExportacion());
        barEntries.add(barExportacion);
        BarEntry barEmbarque = new BarEntry(3,t.get(0).getEmbarque());
        barEntries.add(barEmbarque);

        String() nombresOperacion = {"Descarga","Retiro","Exportación","Embarque"};

        for(int i=0; nombresOperacion.length>i;i++ ){
            //barEntries.add(new BarEntry(i,contador));
            String tipo = nombresOperacion(i);
            labelsname.add(tipo);

        }

        BarDataSet barDataSet = new BarDataSet(barEntries,"Cantidad de Descuentos por Tipo");
        barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);

        BarData barData= new BarData(barDataSet);
        barChart.setData(barData);

        XAxis xaxis= barChart.getXAxis();
        xaxis.setValueFormatter(new IndexAxisValueFormatter(labelsname));

        xaxis.setPosition(XAxis.XAxisPosition.TOP);
        xaxis.setDrawAxisLine(false);
        xaxis.setDrawGridLines(false);
        xaxis.setGranularity(1f);
        xaxis.setLabelCount(labelsname.size());
        xaxis.setLabelRotationAngle(270);
        barChart.animateY(2000);

    }

java – RxJava and race conditions

I have seen some RxJava projects using multithreading with .subscribeOn(Schedulers.io()), and their .subscribe(() -> {...}) code is manipulating some data structures that are also processed by other Observable subscription handlers, and there are no synchronized() anywhere inside subscribe.

Coming from C/C++, I started to wonder – wait, if those subscribes happen to execute on different threads, then what about race conditions?

In C/C++ it would crash and burn with some access violation sooner or later. Of course, Java seems to be much more tolerant. But what if two subscribes happen to work with the same linked list in parallel? Won’t they mess up the links between nodes? Shouldn’t I protect them with synchronized()?

I searched for articles about RxJava and race conditions, but didn’t find much. One article claims the following:

So, whenever you want to switch threads for any particular observable, all you need to do is specify the observeOn() operator just above it. Synchronization, state inconsistencies, race conditions, and all other threading edge cases are automatically handled under the hood.

Is it true and RxJava indeed somehow automagically protects its subscribes for race conditions with other subscribes working on the same data? Or is the author talking only about race conditions with RxJava itself or specifically about observeOn and not subscribeOn?

java – Hotel booking with multiple options. Improvement through subclasses?

The code below runs perfectly fine as I want it to. I’d like to create more subclasses to get a better overview over the whole code. Can I place the setter and getter as well as the methods into the extended classes? I’d like to create subclasses as in single room, double room etc. extends room. Would it improve my code? My prof wants to see more classes.
Thanks in advance
(btw. the code comments are in German, so if there are any questions, I’m happy help)

To simplify my question, the option pet is just available for penthouse. Does it sence to creat a subclass for penthouse to move to setter and getter to the subclass?

import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Scanner;

public class Booking {
    private static boolean CustomerInterface = true;//Hauptprogramm boolean

    public static void main(String() args) throws IOException {
        Scanner input = new Scanner(System.in);

        Room() hotel = new Room(8);//Array für Zimmer

        hotel(0) = new Room(40, true, 1);//Single room
        hotel(1) = new Room(40, true, 2);//Single room
        hotel(2) = new Room(70, true, 3);//Double room
        hotel(3) = new Room(70, true, 4);//Double room
        hotel(4) = new Room(100, true, 5);//Triple room
        hotel(5) = new Room(100, true, 6);//Triple room
        hotel(6) = new Penthouse(200, true, 7, false);//Penthouse
        hotel(7) = new Penthouse(200, true, 8, false);//Penthouse

        System.out.println("Willkommen im Hotel AppDev1");//Begrüßung

        while (CustomerInterface) {//Abfrage des Boolean zum Start des Hauptprogramms
            System.out.println("Bitte wählen sie eine der folgenden Auswahlmöglichkeiten:");
            System.out.println("********************************************************");
            System.out.println("1: Buchen sie einen Raumn2: List der verfügbaren Zimmer anzeigen" +
                    "n3: Liste aller Zimmer anzeigenn4: Kunde auscheckenn5: Gäste Anzeigenn6: Program ende");
            System.out.println("********************************************************");

            String Selection = input.next();
            switch (Selection) {
                case "1":
                    Booking(hotel);//Methode zum Buchen
                    break;
                case "2":
                    ShowEmpty(hotel);//Freie Zimmer anzeigen
                    break;
                case "3":
                    ShowAll(hotel);//Alle Zimmer anzeigen
                    break;
                case "4":
                    DeleteCustomer(hotel);//Kundendaten je Zimmernummer löschen
                    break;
                case "5":
                    Gastdaten(hotel);//Gästedaten:Name, Preise, Buchungsoptionen anzeigen
                    break;
                case "6":
                    ShutDown();//Programm beenden
                    break;
                default:
                    WrongInput();//Flasche Eingabe getätigt
                    CustomerInterface = true;//Hauptprogramm neu starten
            }
        }
    }

    private static void PreisKategorie(Room ()hotel, int roomNr) {//Auswahl der Zimmerkategorie von Standart bis Luxus
        System.out.println("Welche Preiskategorie möchten sie?n1 = Standardn2 = Premium (10% Zuschlag)n 3 = Luxus (20% Zuschlag)");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch(userInput) {
            case "1":
                System.out.println("Sie haben Standard gewählt. ");
                hotel(roomNr).setPriceLevel(1.0);//Standartpreis
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() * hotel(roomNr).getPriceLevel());
                break;
            case "2":
                System.out.println("Sie haben Premium gewählt. ");
                hotel(roomNr).setPriceLevel(1.1);//10% Premiumzuschlag
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() * hotel(roomNr).getPriceLevel());
                break;
            case "3":
                System.out.println("Sie haben Luxus gewählt. ");
                hotel(roomNr).setPriceLevel(1.2);//20% Luxuszuschlag
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() * hotel(roomNr).getPriceLevel());
                break;
            default:
                WrongInput();//Falsche Eingabe
                PreisKategorie(hotel, roomNr);//Zurück zum Beginn der Kategorieauswahl
        }

    }

    private static void ShutDown() {//Programm beenden
        System.out.println("Danke, auf wiedersehen.");
        System.exit(0);
    }

    private static void Booking(Room() hotel) {//Zimmer buchen
        
                String userInput;
                Scanner input = new Scanner(System.in);
                System.out.println("Bitte geben sie eine der folgenden Zimmernummern ein:n1-2 Einzelzimmer, Preis für eine" +
                        " Übernachtung = " + " " + "n3-4 Doppelzimmer" +
                        "n5-6 Drreibettzimmern7-8 Ferienwohnugn9 Programm beenden");
                userInput = input.next();

                switch (userInput) {
                    case "1":
                        if (hotel(0).getAvailable(hotel(0).available)) {
                            System.out.println(hotel(0).getPricePerNight());
                            int roomNr = 0;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            System.out.println(hotel(0).getPricePerNight());
                            Balcony(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "2":
                        if (hotel(1).getAvailable(hotel(1).available)) {
                            int roomNr = 1;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            Balcony(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);

                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "3":
                        if (hotel(2).getAvailable(hotel(2).available)) {
                            int roomNr = 2;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            Balcony(hotel, roomNr);
                            SinglePerson(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "4":
                        if (hotel(3).getAvailable(hotel(3).available)) {
                            int roomNr = 3;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            Balcony(hotel, roomNr);
                            SinglePerson(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "5":
                        if (hotel(4).getAvailable(hotel(4).available)) {
                            int roomNr = 4;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            SecondToilet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "6":
                        if (hotel(5).getAvailable(hotel(5).available)) {
                            int roomNr = 5;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            SecondToilet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "7":
                        if (hotel(6).getAvailable(hotel(6).available)) {
                            int roomNr = 6;
                            PreisKategorie(hotel, roomNr);
                            CountGuests(hotel, roomNr);
                            Pet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            RoomService(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "8":
                        if (hotel(7).getAvailable(hotel(7).available)) {
                            int roomNr = 7;
                            PreisKategorie(hotel, roomNr);
                            CountGuests(hotel, roomNr);
                            Pet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            RoomService(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "9":
                        ShutDown();
                        break;
                    default:
                        WrongInput();
                        Booking(hotel);
                }

                //int roomNr;
                //roomNr = Integer.valueOf(userInput) - 1;//wandelt die eingabe in int um und -1 damit Zimmer 1 = room(0)
                //FinalizeBooking(hotel, roomNr);



    }

    private static void FinalizeBooking(Room @NotNull () hotel, int roomNr) {
        String userInput;
        Scanner input = new Scanner(System.in);
        String rName;
        System.out.println("Bitte geben sie ihren Namen ein : ");
        rName = input.next();//Kundenname für die Buchung
        //rName = String.valueOf(roomNr);//wandelt rName in int um es der arry zuzuodrnen
        //Option 1 mit boolean
        hotel(roomNr).setAvailable(false);
        //Option 2 mit equals
        hotel(roomNr).setName(rName);//hinterlegt in der arry den Namen des Gastes
        Receipt(hotel, roomNr);

    }

    private static void Receipt(Room @NotNull () hotel, int roomNr) {
        System.out.println("Danke für ihre Buchung, das Zimmer" + " " + (roomNr + 1) + " " +
                "ist für sie reserviertnDie Gesamtsumme beträgt: " + (hotel(roomNr).getPricePerNight() * 1.19) + "€" +
                "n Die enthaltende Mehrwertsteuer beträgt: " +(hotel(roomNr).getPricePerNight() * 0.19));
        if ((hotel(roomNr).getFrühstück()==true) || (hotel(roomNr).getBalkon()==true) || (hotel(roomNr).getSinglePerson()==true) || (hotel(roomNr).getGästetoilette()==true) || (hotel(roomNr).getPet()==true) || (hotel(roomNr).getRoomService()==true)) {
            System.out.println("Sie haben die folgenden optionen mit gebucht:");
            if (hotel(roomNr).getFrühstück() == true) {
                System.out.println("Frühstück: " + hotel(roomNr).getBreaky() * hotel(roomNr).getBookingPeriode() + "€");
            }

            if (hotel(roomNr).getBalkon() == true) {
                System.out.println("Balkon: " + hotel(roomNr).getBalcony() * hotel(roomNr).getBookingPeriode() + "€");
            }

            if (hotel(roomNr).getSinglePerson() == true) {
                System.out.println("Einzelpersonrabatt: " + hotel(roomNr).getEinzelPerson() * hotel(roomNr).getBookingPeriode() + "€");
            }

            if (hotel(roomNr).getGästetoilette() == true) {
                System.out.println("Gäste Toilette: " + hotel(roomNr).getSecondToilet() * hotel(roomNr).getBookingPeriode() + "€");
            }

            if (hotel(roomNr).getPet() == true) {
                System.out.println("Haustierzuschlag: " + hotel(roomNr).getHaustier() * hotel(roomNr).getBookingPeriode() + "€");
            }
            if (hotel(roomNr).getRoomService() == true) {
                System.out.println("Zimmerservie: " + hotel(roomNr).getZimmerservice() * hotel(roomNr).getBookingPeriode() + "€");
            }
        } else {
            System.out.println("Sie haben keine Zusatzoptionen gebucht");
        }
    }

    private static void RoomService(Room() hotel, int roomNr) {
        System.out.println("Möchten sie Zimmerservice dazubuchen? n" +" 1 = ja 2= Nein");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput){
            case "1":
                System.out.println("Sie haben inklusive Zimmerservice gebucht");
                hotel(roomNr).setRoomService(true);
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() + Room.getZimmerservice());
                break;
            case "2":
                System.out.println("Sie haben ohne Zimmerservice gebucht");
                hotel(roomNr).setRoomService(false);
                break;
            default: WrongInput();
            RoomService(hotel, roomNr);
        }
    }

    private static void AldreadyBooked(Room() hotel) {
        System.out.println("Dieses Zimmer ist leider schon belegtn Bitte wählen sie ein anders Zimmer.");
        //CustomerInterface = true;
        Booking(hotel);
    }

    private static void WrongInput() {
        System.out.println("********************************************************");
        System.out.println("Ihre eingabe war leider nicht Korrekt.nBitte versuchen sie es erneut.");
        System.out.println("********************************************************");
    }

    private static void Pet(Room() hotel, int roomNr) {
        System.out.println("Kommen Sie mit oder ohne Haustiern1 = mit n2 = ohne");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie nehmen ein Haustier mit");
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() + hotel(roomNr).getHaustier());//3 € Aufpreis für ein Haustier
                hotel(roomNr).pet = true;
                break;
            case "2":
                System.out.println("sie nehmen kein Haustier mit");
                hotel(roomNr).pet = false;
                break;
            default:
                WrongInput();
                Pet(hotel, roomNr);
                break;
        }
    }

    private static void BookingPeriode(Room() hotel, int roomNr) {
        if (roomNr < 7){
            System.out.println("Wie lange bleiben Sie? ");
            Scanner input = new Scanner(System.in);
            String userInput;
            userInput = input.next();
            switch (userInput) {
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                case "10":
                case "11":
                case "12":
                case "13":
                case "14":
                    System.out.println("sie haben" + " " + userInput + " " + "Tage gewählt");
                    hotel(roomNr).setBookinperiode(Integer.valueOf(userInput));
                    hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() * Integer.valueOf(userInput));

                    break;
                default:
                    WrongInput();
                    BookingPeriode(hotel, roomNr);}

        } else{
            System.out.println("Wie lange bleiben Sie? (Die Mindestbuchungsdauer beträgt 3 TagenDie maximale Buchungsdauer beträt 14 Tage)");
            Scanner input = new Scanner(System.in);
            String userInput;
            userInput = input.next();


            switch (userInput) {
                case "1":
                case "2":
                    MinBooking(hotel, roomNr);
                    break;
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                case "10":
                case "11":
                case "12":
                case "13":
                case "14":
                    System.out.println("sie haben" + " " + userInput + " " + "Tage gewählt");
                    hotel(roomNr).setBookinperiode(Integer.valueOf(userInput));
                    hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() * Integer.valueOf(userInput));
                    break;
                default:
                    WrongInput();
                    BookingPeriode(hotel, roomNr);
            }
        }
    }

    private static void MinBooking(Room() hotel, int roomNr) {
        System.out.println("Sie unterschreiten die Mindestbuchungsdauer! nMöchten Sie erneut wählen? 1 = neuwahl 2= Programm beenden");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        if (userInput.equals("1")) {
            BookingPeriode(hotel, roomNr);
        } else if (userInput.equals("2")) {
            ShutDown();
        } else {
            WrongInput();
            MinBooking(hotel, roomNr);
        }
    }

    private static void CountGuests(Room() hotel, int roomNr) {
        System.out.println("Mit wie vielen Personen möchten sie buchen?nDie maximale Anzahl beträt 6 Personen.)");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
            case "2":
            case "3":
            case "4":
            case "5":
            case "6":
                System.out.println("sie haben" + " " + userInput + " Personen gewählt");
                hotel(roomNr).setCountGuests(Integer.valueOf(userInput));
                break;
            default:
                WrongInput();
                CountGuests(hotel, roomNr);
        }
    }

    private static void SecondToilet(Room() hotel, int roomNr) {
        System.out.println("Möchten sie ein Zimmer mit Gäste Toilette? 1 = ohne Gäste Toilette 2 = 2 mit Gäste Toilette");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben ein Zimmer ohne Gäste Toilette gewählt");
                hotel(roomNr).gästetoilette = false;


                break;
            case "2":
                System.out.println("sie haben ein Zimmer mit Gäste Toilette gewählt");
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() + Room.getSecondToilet());//10 € Aufpreis für eine extra Toilette
                hotel(roomNr).gästetoilette = true;

                break;
            default:
                WrongInput();
                SecondToilet(hotel, roomNr);
        }
    }

    private static void SinglePerson(Room() hotel, int roomNr) {
        System.out.println("Bitte geben sie an um wie viele Personen es sich bei ihrer Buchung handeltn1 = Einzelperson 2= Paar");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben Einzelperson gewählt");
                System.out.println("Sie bekommen einen Sondertarif (10 Euro weniger)");

                hotel(roomNr).singlePerson = true;
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() - hotel(roomNr).getEinzelPerson());
                System.out.println(hotel(roomNr).getPricePerNight());
                break;
            case "2":
                System.out.println("sie haben die Paaroption gewählt");
                hotel(roomNr).singlePerson = false;
                //System.out.println(hotel(roomNr).getPricePerNight());
                break;
            default:
                WrongInput();
                SinglePerson(hotel, roomNr);
        }
    }

    private static void Balcony(Room() hotel, int roomNr) {
        System.out.println("Möchten sie ein Zimmer mit Balkon buchen? 1 = mit Balkon 2= ohne Balkon");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben ein Zimmer mit Balkon gewählt");
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() + Room.getBalcony());//5 € Aufpreis für einen Balkon
                hotel(roomNr).balkon = true;

                break;
            case "2":
                System.out.println("sie haben ein Zimmer ohne Balkon gewählt");
                hotel(roomNr).balkon = false;
                break;
            default:
                WrongInput();
                Balcony(hotel, roomNr);
        }
    }

    private static void Breakfast(Room @NotNull () hotel, int roomNr) {
        System.out.println("Möchten sie Frühstück dazu buchen? 1 = mit Frühstück 2= ohne Frühstück");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben ein Zimmer mit Frühstück gewählt");
                hotel(roomNr).setPricePerNight(hotel(roomNr).getPricePerNight() + Room.getBreaky());//3 € Aufprreis für Frühstück
                hotel(roomNr).frühstück = true;
                //System.out.println(hotel(roomNr).getPricePerNight());
                break;
            case "2":
                System.out.println("sie haben ein Zimmer ohne Frühstück gewählt");
                hotel(roomNr).frühstück = false;
                break;
            default:
                WrongInput();
                Breakfast(hotel, roomNr);
                break;
        }
    }

    private static void ShowEmpty(Room @NotNull () hotel) {
        for (int i = 0; i < hotel.length; i++) {
            if (hotel(i).getAvailable(hotel(i).available)) {
                System.out.println("Zimmer " + (i + 1) + " steht zur Verfügung");
            }else {
                System.out.println("Zimmer " + (i + 1) + " ist belegt");
            }
        }
    }

    private static void ShowAll(Room @NotNull () hotel) {
        for (int i = 0; i < hotel.length; i++) {
            System.out.println("Wir bieten Zimmer " + (i + 1) + " an. ");
        }
    }

    private static void DeleteCustomer(Room @NotNull () hotel) {
        Scanner input = new Scanner(System.in);
        int roomNr;
        System.out.println("Bitte geben sie die Zimmernummer ein");
        roomNr = input.nextInt() - 1;
        hotel(roomNr).setName("Name");
        hotel(roomNr).setAvailable(true);
        System.out.println("Eintrag gelöscht");
    }

    private static void Gastdaten(Room @NotNull () hotel) {
        for (int i = 0; i < hotel.length; i++) {
            if (hotel(i).getAvailable(!(hotel(i).available))) {

                System.out.println("Es befinden sich zur Zeit Gäste in Zimmer: " + hotel(i).roomNr +
                        "nName: " + hotel(i).getName() + "nGesamtpreis ohne MwST: "
                        + hotel(i).getPricePerNight());
                switch (hotel(i).getRoomNr()) {
                    case 1:
                    case 2:
                        System.out.println("Frühstück: " + hotel(i).getFrühstück() + "nBalkon: " + hotel(i).getBalkon() +
                                "nDauer des Aufenthalts:" + hotel(i).getBookingPeriode() + "n");
                        break;
                    case 3:
                    case 4:
                        System.out.println("Frühstück: " + hotel(i).getFrühstück() + "nBalkon: " + hotel(i).getBalkon() + "n"
                                + "Einzelpersonenrabatt:" + hotel(i).getSinglePerson() + "nDauer des Aufenthalts:" + hotel(i).getBookingPeriode() + "n");
                        break;
                    case 5:
                    case 6:
                        System.out.println("Frühstück: " + hotel(i).getFrühstück() + "nBalkon: " + hotel(i).getBalkon() + "n"
                                + "Gäste Toilette:" + hotel(i).getGästetoilette() + "nDauer des Aufenthalts:" + hotel(i).getBookingPeriode() + "n");
                        break;
                    case 7:
                    case 8:
                        System.out.println("Anzahl der Gäste: " + hotel(i).getCountGuests() + "nHaustier: " + hotel(i).getPet() + "n"
                                + "Zimmerservice: " + hotel(i).getRoomService() + "nDauer des Aufenthalts:" + hotel(i).getBookingPeriode() + "n");
                        break;
                }
            } else {
                System.out.println("Es befinden sich zur Zeit keine Gäste in Zimmer: " + " " + hotel(i).getRoomNr() + "n");
            }
        }
    }
}
package Hotel;

public class Room {



    //String CustomerName;
    private String Name;
    int roomNr;
    double pricePerNight;
    boolean available; //= true;//Zimmer frei oder belegt?
    static double breaky = 3;
    static double balcony = 5;
    boolean frühstück;
    boolean balkon;
    boolean singlePerson;
    boolean gästetoilette;
    static double secondToilet = 10;
    int countGuests;
    boolean pet;
    int bookinperiode;
    boolean roomservice;
    static double zimmerservice = 10;
    static double einzelPerson = 10;
    double haustier = 3;
    static double priceLevel;



    //Constructor
    public Room(double pricePerNight, boolean available,int roomNr) {
        this.pricePerNight = pricePerNight;
        this.available = available;
        this.roomNr = roomNr;
    }

    public boolean getPet() {
        return pet;
    }
    public double getHaustier() {
        return haustier;
    }

    public boolean getRoomService() {
        return roomservice;
    }
    public void setRoomService(boolean roomservice) {
        this.roomservice = roomservice;
    }
    public static double getZimmerservice() {
        return zimmerservice;
    }

    public boolean getGästetoilette() {
        return gästetoilette;
    }
    public static double getSecondToilet() {
        return secondToilet;
    }

    public void setCountGuests(int countGuests) {
        this.countGuests = countGuests;
    }
    public int getCountGuests() {
        return countGuests;
    }

    public boolean getSinglePerson() {
        return singlePerson;
    }
    public double getEinzelPerson() {
        return einzelPerson;
    }

    public boolean getBalkon() {
        return balkon;
    }
    public static double getBalcony() {
        return balcony;
    }

    public boolean getFrühstück() {
        return frühstück;
    }
    public static double getBreaky() {
        return breaky;
    }

    public void setPricePerNight(double pricePerNight) {
        this.pricePerNight = pricePerNight;
    }
    public double getPricePerNight() {
        return pricePerNight;
    }

    public void setBookinperiode(int bookinperiode) {
        this.bookinperiode = bookinperiode;
    }
    public int getBookingPeriode() {
        return bookinperiode;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }
    public boolean getAvailable(boolean available) {
        return available;
    }

    public String getName() {
        return Name;
    }
    public void setName(String Name) {
        this.Name = Name;
    }

    public double getPriceLevel() {
        return priceLevel;
    }
    public void setPriceLevel(double priceLevel) {
        this.priceLevel = priceLevel;
    }

    public int getRoomNr() {
        return roomNr;
    }
}```

java – Using a domain model to persist metrics

I am currently developing a spring boot web application in which no entity is persistent, and hence will not be saved on a database.

Although, I need to be able to query some business metrics from it. Suppose the following scenario:

  1. EntityA belongs to a third party API.
  2. An user on my web app requests to see some details of EntityA.
  3. My app then requests EntityA from the third party API, does some processing (could be combining that data with some other available on the web), and returns the desired info to the requesting user.

I am not required to persist EntityA because it is already being persisted inside the third party API. All the processing done is transient. But, I want to be able to check how many times EntityA was requested by an user on my web application, and what data it contained on each request. This metric is useful for audit purposes, for example, since the third party accepts input and output of data. I want to be able to check who input a certain piece of data, and how many times it was done.

If I were to persist EntityA, I would not need all fields that the domain model contain. Also, I would have to add some metadata fields to it (date of request, requesting user, etc.).

What is the correct approach to it?

  1. Persist the domain model of EntityA in my web app, adding the metadata fields on, for example, a superclass?
  2. Create a new entity that express the desired metric, for example RequestedEntity, and map the desired fields of EntityA to RequestedEntity before persisting?

java – How do I run LibGDX’s Particle Editor in Netbeans?

I am trying to run the Particle Editor that comes with LibGDX in Netbeans. The gdx-tools-1.9.10.jar file shows up in my dependencies, and I can see all of the packages and class files inside it:

gdx-tools-1.9.10.jar

Normally, when I want to run a file, I open the file by double-clicking it in the “Projects” panel, right click anywhere in the file, and then click the “Run File” option. However, when I use the same process to try to run a class file in gdx-tools, the “Run File” option appears to be grayed out:

Run File (Shift+F6)

I have also tried using the Shift+F6 shortcut, with no effect. Just as a sanity check, I did also make sure that the class file I am trying to run has a main method:

main method

I have also tried running the Particle Editor from the command line (I’m using Windows). I navigated to the gdx-tools directory using the following command:

cd C:Users<user>.gradlecachesmodules-2files-2.1com.badlogicgames.gdxgdx-tools1.9.10<hash>

I then tried to run the Particle Editor using the following command:

java -cp gdx-tools-1.9.10.jar com.badlogic.gdx.tools.particleeditor.ParticleEditor.class

And the result is simply:

Error: Could not find or load main class com.badlogic.gdx.tools.particleeditor.ParticleEditor.class

How do I run the Particle Editor? I would prefer to be able to run it in Netbeans, but I would be happy to get it to run at all. I am using LibGDX 1.9.10, Netbeans 8.2, and Java (JDK and JRE) 8u111 on Windows 10. I installed LibGDX using their setup app found here.

java – The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

I am attempting to run a curl request on my java web service project that should return XML code to the server, via the command prompt however I am running into the above error. I’ve tried many different techniques, and it seems to me that for some reason the server is unable to find the file, however I’ve included a screenshot showing that the predictions.jsp file is in the src file where my cwd is pointing in command line. if anyone is able to help me that would be greatly appreciated as I am new to web services in general and have no idea where I should go from here. Please let me know if you need any additional information to help answer my question and I will gladly include it. I’ve included the screenshots from my command line to show the complete error message as well as the cwd to show that the file predictions.jsp is included in the directory.

image of current working directory

image of full command line error

This project was originally developed using Eclipse IDE however running the project using the Apache Tomcat Server packaged with my Eclipse Install does not work either, as I simply get a blank screen when running the predictions.jsp file from that server.

java – LibGDX Change mouse cursor to custom image……and keep it there

I’m able to create a custom cursor no problem using the following code running in my GameScreen’s Show method:

Pixmap pixmap = new Pixmap(Gdx.files.internal("ui/cursor.png"));
Cursor cursor = Gdx.graphics.newCursor(pixmap, pixmap.getWidth() / 2, pixmap.getHeight() / 2);
Gdx.graphics.setCursor(cursor);
pixmap.dispose();

The problem is…if I deselect the game window and return back…the cursor has returned back to the default one. At least that happens for me on Mac desktop. If I move the cursor out of the screen (without deselecting) and then back again I get the custom cursor image back but I don’t think people would know to do that.

But after searching I couldn’t find any way for LibGDX to detect when the game window is deselected? I thought I would be able to find that since it would seem useful for something like automatically pausing when deselecting the game window and such.

That would seem to be the way to reset the cursor every time returning to the game window, unless there’s some other way to make it more permanent?

java – Unknown error when trying to register a Minecraft ArmorItem

The error in question is (Inferred type ‘I’ for type parameter ‘I’ is not within its bound; should extend ‘net.minecraft.item.Item’)

on the following snippet of code

// Armor Items
public static final RegistryObject<ArmorItem> RINGMAIL_HELMET = ITEMS.register("ringmail_helmet",
        new ArmorItem(DnDCraftArmorMaterial.RINGMAIL, EquipmentSlotType.HEAD, new Item.Properties().group(DnDCraft.TAB)));

I have tried many things like what I do here

public static final RegistryObject<Item> RING = ITEMS.register("ring", ItemBase::new);

by putting the ItemBase::new snippet in the last paramter.
I’ve also tried seeing what IntelliJ suggests is best in-context action but none of those approaches seemed to fix the issue.

I’m not super familiar with Java or Minecraft modding so this may just be something simple that I am missing but any help or recommendations would be nice. Thanks!

Also this is the ItemBase class, in case that helps.

package com.fire.dndcraft.items;

import com.fire.dndcraft.DnDCraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;

public class ItemBase extends Item {
    public ItemBase() {
        super(new Item.Properties().group(DnDCraft.TAB));
    }
}

Múltiplos uploads simultâneos API REST Java

Estou desenvolvendo uma API para receber imagens através de uma aplicação mobile. Só que testei a API com o JMeter enviando dois arquivos de 5MB cada, coloquei para repetir 50 vezes, e acaba que a aplicação não suporta, o JMeter aponta erros. Poderia me sugerir uma estratégia que suporte esse tipo de requisição? Pois acredito que pode acontecer o caso de vários usuários enviarem as imagens ao mesmo tempo.

java – Pré-visualização de relatório do jaspersoft studio

Fala, gente. To utilizando o jaspersoft studio para gerar uns relatórios a partir do java. Só que estou precisando fazer algumas modificações pequenas em algumas partes e sempre preciso estar gerando o relatório pra visualizar como ficaram os campos preenchidos com os dados, e sempre tenho que parar o tomcat e inicia-lo novamente pra ele poder pegar as alterações que fiz após a compilação do JRXML.
Alguém saberia se tem como pré-visualizar essas alterações no próprio jaspersoft studio ou pegar as alterações sem ter que parar o tomcat?