List of usage examples for java.lang Enum toString
public String toString()
From source file:com.project.implementation.ReservationImplementation.java
public ArrayList<HashMap<String, String>> calculateBill(String reservation_token, String user_name, Double discountDouble) {/*from w w w. jav a 2 s. com*/ //check if service agent exist List<User> userName = userDAO.verifyUserByUserName(user_name); Integer user_id = userName.get(0).getUser_id(); System.out.println("user_id: " + user_id); String userNameString = userName.get(0).getUser_name().toString(); System.out.println("userNameString: " + userNameString); ArrayList<HashMap<String, String>> billList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> billHash = new HashMap<String, String>(); if (user_name.equals(userNameString)) { //fetch reservation id List<Reservation> reservRecords = reservationDAO.find(reservation_token); Integer reservation_id = reservRecords.get(0).getReservation_id(); System.out.println("reservation_id: " + reservation_id); Integer guest_id = reservRecords.get(0).getGuest_id(); System.out.println("guest_id:: " + guest_id); List<Guest> emailRecord = guestDAO.findGuestEmailId(reservRecords.get(0).getGuest_id()); String guestEmailID = emailRecord.get(0).getGuest_email(); String guestName = emailRecord.get(0).getGuest_name(); System.out.println("emailRecord: " + guestEmailID); System.out.println("guestName: " + guestName); System.out.println(reservRecords.size()); System.out.println(reservRecords.get(0).getReservation_id()); Integer s = reservRecords.get(0).getReservation_id(); System.out.println("integer value: " + s); //Integer reservation_id = reservRecords.get(0).getReservation_id(); //fetch checkin mapping table data ReservationDTO reservDTO = new ReservationDTO(); reservDTO.setReservation_id(reservRecords.get(0).getReservation_id()); List<CheckinRoomMapping> checkinMappingRecords = checkinRoomMappingDAO.findMappingForBilling(reservDTO); Date checkin_date = checkinMappingRecords.get(0).getCheckin_date(); Date checkout_date = checkinMappingRecords.get(0).getCheckout_date(); long daysStay = ((checkout_date.getTime() - checkin_date.getTime()) / MILLISECONDS_IN_DAY) + 1;// System.out.println("daysStay: " + daysStay); String noOfDaysStayed = String.valueOf(daysStay);// System.out.println("noOfDaysStayed: " + noOfDaysStayed); Double totalBill = 0.0; ArrayList<HashMap<String, String>> mailContent = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < checkinMappingRecords.size(); i++) { System.out.println("Room(" + i + ") : " + checkinMappingRecords.get(i).getRoom_no()); Integer room_no = checkinMappingRecords.get(i).getRoom_no(); String roomNoInString = String.valueOf(room_no);// System.out.println("roomNoInString: " + roomNoInString); RoomDTO roomDTO = new RoomDTO(); roomDTO.setRoom_no(room_no); Enum<RoomType> roomType = roomDAO.findRoomType(roomDTO); String type = roomType.toString();// if (type.equalsIgnoreCase("K")) type = "King"; if (type.equalsIgnoreCase("Q")) type = "Queen"; if (type.equalsIgnoreCase("SK")) type = "Smoking - King"; if (type.equalsIgnoreCase("SQ")) type = "Smoking - Queen"; System.out.println("room type: " + type); //Fetch price by room type Double roomPrice = roomPriceDAO.getRoomPrice(roomType);// System.out.println("roomPrice:::" + roomPrice); String roomPriceString = String.valueOf(roomPrice); System.out.println("roomPriceString: " + roomPriceString); Double billPerRoom = roomPrice * daysStay;// String billPerRoomString = String.valueOf(billPerRoom); System.out.println("billPerRoomString:" + billPerRoomString); totalBill = totalBill + billPerRoom; //set hash map HashMap<String, String> mailBody = new HashMap<String, String>(); mailBody.put("Room_Number", roomNoInString); mailBody.put("Room_Type", type); mailBody.put("Room_Price", roomPriceString); mailBody.put("NoOfDays", noOfDaysStayed); mailBody.put("BillPerRoom", billPerRoomString); mailContent.add(mailBody); //end hash map System.out.println("-------"); } System.out.println("totalBill::" + totalBill); String templateForEmailBody = ""; for (HashMap<String, String> h : mailContent) { System.out.println("room_numer" + h.get("Room_Number")); templateForEmailBody = templateForEmailBody + "<tr><td>" + h.get("Room_Number") + "</td><td>" + h.get("Room_Type") + "</td><td>" + h.get("Room_Price") + "</td><td>" + h.get("NoOfDays") + "</td><td>" + h.get("BillPerRoom") + "</td><tr><br>"; } System.out.println("templateForEmailBody" + templateForEmailBody); Integer bill_no = guest_id; String bill_no_String = String.valueOf(bill_no); System.out.println("discount" + discountDouble); //String bill_no_String = String.valueOf(discountDouble); Double totalDiscount = (discountDouble / 100) * totalBill; String totalDiscountString = String.valueOf(totalDiscount); Double amountPayable = totalBill - totalDiscount; String amountPayableString = String.valueOf(amountPayable); //ReservationDTO res = new ReservationDTO(); BillingDTO billingDTO = new BillingDTO(); billingDTO.setBill_no(bill_no); billingDTO.setReservation_id(reservation_id); billingDTO.setUser_id(user_id); billingDTO.setDiscount(totalDiscount); billingDTO.setAmount(amountPayable); Reservation resObj = new Reservation(); resObj.setReservation_id(reservation_id); User userObj = new User(); userObj.setUser_id(user_id); Billing billObject = new Billing(); billObject.setBill_no(bill_no); billObject.setReservation(resObj); billObject.setUser(userObj); billObject.setDiscount(totalDiscount); billObject.setAmount(amountPayable); // try { // org.apache.commons.beanutils.BeanUtils.copyProperties(billObject, billingDTO); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } catch (InvocationTargetException e) { // e.printStackTrace(); // } Integer billID = billingDAO.insertBillData(billObject); System.out.println("Bill id after Insert: " + billID); if (billID != null) { //email final String from = "express.minihotel@gmail.com"; String to = guestEmailID; String body = "Hello " + guestName + ",<br><br>You bill details are as follows:<br>" + "<table border='1' style=\"border-collapse: collapse;\"><tr>" + "<td><b>Room Number</b></td>" + "<td><b>Room Type</b></td>" + "<td><b>Price per day ($)</b></td>" + "<td><b>Duration of Stay (days)</b></td>" + "<td><b>Bill for Room ($)</b></td></tr>" + templateForEmailBody + "</table><br>Net Bill: $" + totalBill + "<br><br>" + "Discount: $" + totalDiscountString + "<br></br>" + "<br/><b>Total Bill Paid($): <font color='red'>" + amountPayable + "</font></b><br></br><br></br>Thank You for choosing Express Hotel.<br/><br/><i>--Express Hotel</i>"; String subject = "Express Hotel - Bill Receipt (Receipt No : " + bill_no_String + ")"; final String password = "Minihotel@2015"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, password); } }); try { MimeMessage email = new MimeMessage(session); email.setFrom(new InternetAddress(from)); email.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to)); email.setSubject(subject); email.setContent(body, "text/html"); Transport.send(email); } catch (MessagingException e) { throw new RuntimeException(e); } //email billHash.put("bill_amount", amountPayableString); billHash.put("bill_body", body); billList.add(billHash); //return billList; } } else { //username doesnot exist billHash.put("bill_amount", "User does not exist"); billList.add(billHash); //return billList; } return billList; }
From source file:com.aliyun.odps.graph.local.TaskContextImpl.java
@Override public Counter getCounter(Enum<?> name) { if (name == null) { throw new RuntimeException("ODPS-0730001: Counter name must be not null."); }/*from ww w. ja va 2s . c o m*/ return getCounter(name.getDeclaringClass().getName(), name.toString()); }
From source file:kg.apc.jmeter.listener.GraphsGeneratorListener.java
/** * Override the setProperty method in order to convert * the original String calcMode property. * This used the locale-dependent display value, so caused * problems when the language was changed. * Note that the calcMode StringProperty is replaced with an IntegerProperty * so the conversion only needs to happen once. *///from ww w.j ava 2s. c om @Override public void setProperty(JMeterProperty property) { if (property instanceof StringProperty) { final String pn = property.getName(); if (pn.equals("exportMode")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<ExportMode> e : ExportMode.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } } super.setProperty(property); }
From source file:com.evolveum.midpoint.prism.marshaller.BeanMarshaller.java
private XNode marshalEnum(Enum enumValue, SerializationContext ctx) { Class<? extends Enum> enumClass = enumValue.getClass(); String enumStringValue = inspector.findEnumFieldValue(enumClass, enumValue.toString()); if (StringUtils.isEmpty(enumStringValue)) { enumStringValue = enumValue.toString(); }/* w ww . j a va2 s.c o m*/ QName fieldTypeName = inspector.findTypeName(null, enumClass, DEFAULT_PLACEHOLDER); return createPrimitiveXNode(enumStringValue, fieldTypeName, false); }
From source file:org.kohsuke.github.Requester.java
public Requester with(String key, Enum e) { if (e == null) return _with(key, null); // by convention Java constant names are upper cases, but github uses // lower-case constants. GitHub also uses '-', which in Java we always // replace by '_' return with(key, e.toString().toLowerCase(Locale.ENGLISH).replace('_', '-')); }
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
protected void pAddEnumProps(Class<?> propClass, Property property) { final boolean useIndex = pMapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX); final boolean useToString = pMapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); @SuppressWarnings("unchecked") Class<Enum<?>> enumClass = (Class<Enum<?>>) propClass; for (Enum<?> en : enumClass.getEnumConstants()) { String n;/*from w w w. ja v a2 s . com*/ if (useIndex) { n = String.valueOf(en.ordinal()); } else if (useToString) { n = en.toString(); } else { n = pIntr.findEnumValue(en); } if (property instanceof StringProperty) { StringProperty sp = (StringProperty) property; sp._enum(n); } } }
From source file:org.apache.hadoop.mapred.Counters.java
/** * Find the counter for the given enum. The same enum will always return the * same counter.// ww w. j ava 2 s .co m * @param key the counter key * @return the matching counter object */ public synchronized Counter findCounter(Enum key) { Counter counter = cache.get(key); if (counter == null) { Group group = getGroup(key.getDeclaringClass().getName()); if (group != null) { counter = group.getCounterForName(key.toString()); if (counter != null) cache.put(key, counter); } } return counter; }
From source file:com.heliosphere.demeter.base.runner.AbstractRunner.java
/** * Checks the definition of the parameters against their enumeration class. * <hr>//w ww . j a v a 2s . c o m * @param clazz Parameter enumeration class. * @throws ParameterException Thrown in case an error occurred when validating a parameter type against its enumeration class. */ @SuppressWarnings({ "unchecked", "rawtypes", "nls" }) private final void checkParameterDefinitionAgainstEnumeration(@NonNull final Class clazz) throws ParameterException { Class<? extends Enum<? extends IParameterType>> enumeration = clazz; List<Enum<? extends IParameterType>> list = (List<Enum<? extends IParameterType>>) Arrays .asList(enumeration.getEnumConstants()); for (Enum<? extends IParameterType> e : list) { boolean found = false; for (IParameterConfiguration p : configuration.getContent().getElements()) { if (p.getType() == e) { found = true; break; } } if (!found && !e.toString().equals("UNKNOWN")) { throw new ParameterException(String.format( "Unable to find parameter name: '%1s' in file: '%2s' corresponding to enumeration class: %3s for enumerated value: %4s", ((IParameterType) e).getName(), configuration.getResource().getFile().getName(), clazz.getSimpleName(), e.toString())); } } }
From source file:com.chinamobile.bcbsp.bspcontroller.Counters.java
/** * Find the counter for the given enum. The same enum will always return the * same counter./*from ww w. ja va 2 s. c om*/ * @param key * the counter key * @return the matching counter object */ public synchronized Counter findCounter(Enum<?> key) { Counter counter = cache.get(key); if (counter == null) { Group group = getGroup(key.getDeclaringClass().getName()); counter = group.getCounterForName(key.toString()); cache.put(key, counter); } return counter; }
From source file:com.anrisoftware.sscontrol.core.groovy.statementsmap.StatementsMap.java
/** * Returns the statement value with the specified name. * <p>//ww w . j a va 2 s . com * * The following statement returns "value": * * <pre> * statement "value" * </pre> * * @param name * the {@link Enum} name. * * @return the {@link Object} value or {@code null}. */ public <T> T value(Enum<?> name) { return value(name.toString()); }