List of usage examples for javax.json JsonObject getJsonNumber
JsonNumber getJsonNumber(String name);
From source file:com.floreantpos.ui.views.payment.SettleTicketDialog.java
private void addCoupon(Ticket ticket, JsonObject jsonObject) { Set<String> keys = jsonObject.keySet(); for (String key : keys) { JsonNumber jsonNumber = jsonObject.getJsonNumber(key); double doubleValue = jsonNumber.doubleValue(); TicketDiscount coupon = new TicketDiscount(); coupon.setName(key);// w w w. j av a 2s. co m coupon.setType(Discount.FIXED_PER_ORDER); coupon.setValue(doubleValue); ticket.addTodiscounts(coupon); } }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importTimeslotList() { List<Timeslot> timeslotList = new ArrayList<>(); Map<Timeslot, List<Room>> timeslotToAvailableRoomsMap = new HashMap<>(); Map<Pair<LocalDateTime, LocalDateTime>, Timeslot> startAndEndTimeToTimeslotMap = new HashMap<>(); Long timeSlotId = 0L;//from ww w. ja va 2 s . co m String schedulesUrl = conferenceBaseUrl + "/schedules/"; LOGGER.debug("Sending a request to: " + schedulesUrl); JsonArray daysArray = readJson(schedulesUrl, JsonReader::readObject).getJsonArray("links"); for (int i = 0; i < daysArray.size(); i++) { JsonObject dayObject = daysArray.getJsonObject(i); String dayUrl = dayObject.getString("href"); LOGGER.debug("Sending a request to: " + dayUrl); JsonArray daySlotsArray = readJson(dayUrl, JsonReader::readObject).getJsonArray("slots"); for (int j = 0; j < daySlotsArray.size(); j++) { JsonObject timeslotObject = daySlotsArray.getJsonObject(j); LocalDateTime startDateTime = LocalDateTime.ofInstant( Instant.ofEpochMilli(timeslotObject.getJsonNumber("fromTimeMillis").longValue()), ZoneId.of(ZONE_ID)); LocalDateTime endDateTime = LocalDateTime.ofInstant( Instant.ofEpochMilli(timeslotObject.getJsonNumber("toTimeMillis").longValue()), ZoneId.of(ZONE_ID)); Room room = roomIdToRoomMap.get(timeslotObject.getString("roomId")); if (room == null) { throw new IllegalStateException("The timeslot (" + timeslotObject.getString("slotId") + ") has a roomId (" + timeslotObject.getString("roomId") + ") that does not exist in the rooms list"); } // Assuming slotId is of format: tia_room6_monday_12_.... take only "tia" String talkTypeName = timeslotObject.getString("slotId").split("_")[0]; TalkType timeslotTalkType = talkTypeNameToTalkTypeMap.get(talkTypeName); if (Arrays.asList(IGNORED_TALK_TYPES).contains(talkTypeName)) { continue; } Timeslot timeslot; if (startAndEndTimeToTimeslotMap.keySet().contains(Pair.of(startDateTime, endDateTime))) { timeslot = startAndEndTimeToTimeslotMap.get(Pair.of(startDateTime, endDateTime)); timeslotToAvailableRoomsMap.get(timeslot).add(room); if (timeslotTalkType != null) { timeslot.getTalkTypeSet().add(timeslotTalkType); } } else { timeslot = new Timeslot(timeSlotId++); timeslot.withStartDateTime(startDateTime).withEndDateTime(endDateTime) .withTalkTypeSet(timeslotTalkType == null ? new HashSet<>() : new HashSet<>(Arrays.asList(timeslotTalkType))); timeslot.setTagSet(new HashSet<>()); timeslotList.add(timeslot); timeslotToAvailableRoomsMap.put(timeslot, new ArrayList<>(Arrays.asList(room))); startAndEndTimeToTimeslotMap.put(Pair.of(startDateTime, endDateTime), timeslot); } if (!timeslotObject.isNull("talk")) { scheduleTalk(timeslotObject, room, timeslot); } for (TalkType talkType : timeslot.getTalkTypeSet()) { talkType.getCompatibleTimeslotSet().add(timeslot); } timeslotTalkTypeToTotalMap.merge(talkTypeName, 1, Integer::sum); } } for (Room room : solution.getRoomList()) { room.setUnavailableTimeslotSet(timeslotList.stream() .filter(timeslot -> !timeslotToAvailableRoomsMap.get(timeslot).contains(room)) .collect(Collectors.toSet())); } solution.setTimeslotList(timeslotList); }
From source file:org.rhwlab.dispim.nucleus.NucleusData.java
public NucleusData(JsonObject jsonObj) { this.time = jsonObj.getInt("Time"); this.name = jsonObj.getString("Name"); String precString = jsonObj.getJsonString("Precision").getString(); this.A = precisionFromString(precString); this.xC = jsonObj.getJsonNumber("X").longValue(); this.yC = jsonObj.getJsonNumber("Y").longValue(); this.zC = jsonObj.getJsonNumber("Z").longValue(); this.exp = jsonObj.getJsonNumber("Expression").longValue(); this.eigenA = new EigenDecomposition(A); this.adjustedA = this.A.copy(); this.adjustedEigenA = new EigenDecomposition(adjustedA); double[] adj = new double[3]; adj[0] = adj[1] = adj[2] = 1.0;/* w w w . ja va 2s.c om*/ this.setAdjustment(adj); }