Example usage for org.joda.time LocalTime LocalTime

List of usage examples for org.joda.time LocalTime LocalTime

Introduction

In this page you can find the example usage for org.joda.time LocalTime LocalTime.

Prototype

public LocalTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:LocalTimeTypeAdapter.java

License:Apache License

@Override
public LocalTime read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*from ww w .ja  v  a 2 s  .  co  m*/
        return null;
    }
    return new LocalTime(in.nextString());
}

From source file:com.baulsupp.kolja.util.LocalTimePropertyEditor.java

License:Open Source License

public void setAsText(String text) throws IllegalArgumentException {
    setValue(new LocalTime(text));
}

From source file:com.clicktravel.common.random.Randoms.java

License:Apache License

/**
 * @return A random local time.
 */
public static LocalTime randomLocalTime() {
    return new LocalTime(randomDateTime());
}

From source file:com.controller.webServices.JsonAutoDetect.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException, ClassNotFoundException {
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();

    JsonObject jsonResult = new JsonObject();
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonArray errorArray = new JsonArray();

    String date = request.getParameter("date");
    String token = request.getParameter("token");

    //validation - date
    if (date == null) {
        errorArray.add(new JsonPrimitive("missing date"));
    } else {/*www  . j  a v  a 2s . co m*/
        try {
            DateTime ts2 = new DateTime(date);
        } catch (IllegalArgumentException e) {
            errorArray.add(new JsonPrimitive("invalid date"));
        }
    }

    //validation - token
    if (token == null) {
        errorArray.add(new JsonPrimitive("missing token"));
    } else if (token.equals("")) {
        errorArray.add(new JsonPrimitive("blank token"));
    } else {
        try {
            JWTUtility.verify(token, "ylleeg4t8");
        } catch (JWTException e) {
            errorArray.add(new JsonPrimitive("invalid token"));
        }
    }

    if (errorArray.size() > 0) {
        jsonResult.add("message", errorArray);
        out.println(gson.toJson(jsonResult));
        return;
    }

    if (errorArray.size() == 0) {
        String date1 = date.substring(0, date.indexOf("T"));
        String time = date.substring(date.indexOf("T") + 1, date.length());

        try {

            LocalTime after = new LocalTime(Timestamp.valueOf(date1 + " " + time));
            int hour = Integer.parseInt(time.substring(0, time.indexOf(":")));
            int minute = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.lastIndexOf(":")));
            int second = Integer.parseInt(time.substring(time.lastIndexOf(":") + 1, time.length()));
            if (hour >= 24 || minute >= 60 || second >= 60) {
                throw new Exception();
            }
            Timestamp tsAfter = Timestamp.valueOf(date1 + " " + after);
            Timestamp tsBefore = new Timestamp(tsAfter.getTime() - 900000);

            ArrayList<Group> groupList = new ArrayList<Group>();

            AutoGroupDetectController ac = new AutoGroupDetectController();
            System.out.println(tsBefore.toString() + " " + tsAfter.toString());
            groupList = ac.getFullGroups(tsBefore.toString(), tsAfter.toString());

            jsonResult.addProperty("status", "success");

            int count = 0;
            HashSet set = new HashSet();
            for (Group g : groupList) {
                set.addAll(g.getIndivSet());

            }
            count = set.size();
            jsonResult.addProperty("total-groups", groupList.size());
            jsonResult.addProperty("total-users", count);

            JsonArray groupArray = new JsonArray();
            JsonArraySorter sorter = new JsonArraySorter();

            for (Group g : groupList) {
                JsonObject groupObject = new JsonObject();
                groupObject.addProperty("size", g.getIndivSet().size());
                groupObject.addProperty("total-time-spent", g.getFullCount());

                JsonArray memberArray = new JsonArray();
                HashSet<FullUser> userSet = g.getIndivSet();
                Iterator i = userSet.iterator();
                while (i.hasNext()) {
                    FullUser fullUser = (FullUser) i.next();
                    JsonObject memberObj = new JsonObject();
                    memberObj.addProperty("email", fullUser.getEmail());
                    memberObj.addProperty("mac-address", fullUser.getMacAddress());
                    memberArray.add(memberObj);
                }
                memberArray = sorter.sortAGDMembers(memberArray);
                groupObject.add("members", memberArray);

                // Add location objects 

                JsonArray locationArray = new JsonArray();
                HashMap<String, Integer> locationMapping = g.getLocTimeMap();
                for (String s : locationMapping.keySet()) {
                    JsonObject locationObject = new JsonObject();
                    locationObject.addProperty("location", s);
                    locationObject.addProperty("time-spent", locationMapping.get(s));
                    locationArray.add(locationObject);
                }

                locationArray = sorter.sortAGDlocation(locationArray);
                groupObject.add("locations", locationArray);

                groupArray.add(groupObject);
            }
            groupArray = sorter.sortAGDGroup(groupArray);
            jsonResult.add("groups", groupArray);

            out.println(gson.toJson(jsonResult));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
    }

    // =======     End of Json Codes    ======= 
}

From source file:com.controller.webServices.JsonTopKGroupNextPlaces.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    PrintWriter out = response.getWriter();

    System.out.println("======  Group Next Places   ======== ");

    JsonObject jsonResult = new JsonObject();
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonArray errorArray = new JsonArray();

    String date = request.getParameter("date");
    String token = request.getParameter("token");
    Timestamp ts = null;/*from w w w. ja  v  a 2  s .  c  o m*/
    Timestamp tsBefore = null;
    Timestamp tsAfter = null;
    HashMap<String, Integer> finalMap = null;
    ArrayList<String[]> personCount = null;

    //validation - date
    if (date == null) {
        errorArray.add(new JsonPrimitive("missing date"));
    } else {
        try {
            DateTime ts2 = new DateTime(date);
        } catch (IllegalArgumentException e) {
            errorArray.add(new JsonPrimitive("invalid date"));
        }
    }

    //validation - token
    if (token == null) {
        errorArray.add(new JsonPrimitive("missing token"));
    }
    //        } else if (token.equals("")) {
    //            errorArray.add(new JsonPrimitive("blank token"));
    //        } else {
    //            try {
    //                JWTUtility.verify(token, "ylleeg4t8");
    //            } catch (JWTException e) {
    //                errorArray.add(new JsonPrimitive("invalid token"));
    //            }
    //        }

    // Validation: Semantic Places
    String place = request.getParameter("origin");
    if (place == null) {
        errorArray.add(new JsonPrimitive("missing origin"));
    } else if (place.equals("")) {
        errorArray.add(new JsonPrimitive("blank origin"));
    }

    if (errorArray.size() > 0) {
        jsonResult.add("message", errorArray);
        out.println(gson.toJson(jsonResult));
        return;
    }

    ArrayList<Group> finalGroup = null;

    if (errorArray.size() == 0) {
        String date1 = date.substring(0, date.indexOf("T"));
        String time = date.substring(date.indexOf("T") + 1, date.length());

        try {

            LocalTime after = new LocalTime(Timestamp.valueOf(date1 + " " + time));
            int hour = Integer.parseInt(time.substring(0, time.indexOf(":")));
            int minute = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.lastIndexOf(":")));
            int second = Integer.parseInt(time.substring(time.lastIndexOf(":") + 1, time.length()));
            if (hour >= 24 || minute >= 60 || second >= 60) {
                throw new Exception();
            }
            ts = Timestamp.valueOf(date1 + " " + time);
            tsBefore = new Timestamp(ts.getTime() - 900000);
            tsAfter = new Timestamp(ts.getTime() + 900000);

            ArrayList<Group> groupList = new ArrayList<Group>();
            finalMap = new HashMap<String, Integer>();
            personCount = new ArrayList<String[]>();

            AutoGroupDetectController agd = new AutoGroupDetectController();
            System.out.println("Group next places: " + tsBefore.toString() + " " + ts.toString());

            LocationLookupDAO llDAO = new LocationLookupDAO();
            HashMap<String, String> referMap = llDAO.retrieveAll();

            ArrayList<Group> firstGroup = agd.getFullGroups(tsBefore.toString(), ts.toString());
            //                if (firstGroup.size() == 0) {
            //                    request.setAttribute("results", personCount);
            //                    RequestDispatcher rd = request.getRequestDispatcher("group_next.jsp");
            //                    rd.forward(request, response);
            //                    return;
            //                }

            System.out.println("List size for group next places: " + firstGroup.size());
            ArrayList<Group> midGroup = new ArrayList<Group>();
            for (Group g : firstGroup) {
                String s = referMap.get(g.getLastPlace());
                System.out.println(s);
                if (s.equals(place)) {
                    midGroup.add(g);
                }
            }
            System.out.println("Mid list size for group next places: " + midGroup.size());
            finalGroup = agd.getMatchingGroups(ts.toString(), tsAfter.toString(), midGroup);
            System.out.println("Final list size for group next places: " + finalGroup.size());

            LocationLookupDAO lookupDAO = new LocationLookupDAO();
            HashMap<String, String> lookupMap = lookupDAO.retrieveAll();
            for (Group g : finalGroup) {
                ArrayList<Interval> groupInterList = new ArrayList<Interval>();
                HashMap<Interval, Integer> tempMap = new HashMap<Interval, Integer>();
                HashMap<String, ArrayList<Interval>> overlapMap = g.getLocOverlapMap();
                for (String s : overlapMap.keySet()) {
                    ArrayList<Interval> interList = overlapMap.get(s);
                    groupInterList.addAll(interList);
                    for (Interval in : interList) {
                        Integer i = Integer.parseInt(s);
                        tempMap.put(in, i);
                    }
                }
                Collections.sort(groupInterList, new IntervalEndComparator(groupInterList));
                for (Interval in : groupInterList) {
                    if (Seconds.secondsIn(in).getSeconds() >= 300) {
                        Integer i = tempMap.get(in);
                        String semPlace = lookupMap.get(String.valueOf(i));
                        Integer groupCount = finalMap.get(semPlace);
                        if (groupCount != null) {
                            finalMap.put(semPlace, (groupCount + 1));
                        } else {
                            finalMap.put(semPlace, 1);
                        }
                        break;
                    }
                }
            }

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (Entry<String, Integer> entry : finalMap.entrySet()) {

            String[] countArray = new String[] { entry.getKey(), entry.getValue().toString() };
            personCount.add(countArray);
        }

        Collections.sort(personCount, new ValueComparator(personCount));

        jsonResult.addProperty("status", "success");
        jsonResult.addProperty("total-groups", finalGroup.size());
        jsonResult.addProperty("total-next-place-groups", personCount.size());
        JsonArray results = new JsonArray();
        for (int i = 0; i < personCount.size(); i++) {
            String[] arr = personCount.get(i);
            JsonObject nextPlaceObject = new JsonObject();
            nextPlaceObject.addProperty("rank", i + 1);
            nextPlaceObject.addProperty("semantic-place", arr[0]);
            nextPlaceObject.addProperty("num-groups", Integer.parseInt(arr[1]));
            results.add(nextPlaceObject);
        }
        jsonResult.add("results", results);

        out.println(gson.toJson(jsonResult));

        //            request.setAttribute("results", personCount);
        //            RequestDispatcher rd = request.getRequestDispatcher("group_next.jsp");
        //            rd.forward(request, response);
    }
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.ThermostatPageUIImpl.java

License:Open Source License

/**
 * Sets the page load time on login.//ww  w  .  j ava 2  s  .  co  m
 * @param endTime the new page load time on login
 * @see com.ecofactor.qa.automation.mobile.page.ThermostatPage#setPageLoadTimeOnLogin(org.joda.time.LocalTime)
 */
@Override
public void setPageLoadTimeOnLogin(LocalTime endTime) {

    this.pageLoadTimeOnLogin = new LocalTime(endTime);
}

From source file:com.excilys.sugadroid.beans.AppointmentBeanV5.java

License:Open Source License

public void setDateStart(LocalDateTime dateStart) {
    this.dateStart = new LocalDate(dateStart);
    timeStart = new LocalTime(dateStart);
}

From source file:com.github.cassandra.jdbc.provider.datastax.CassandraPreparedStatement.java

License:Apache License

@Override
protected void setParameter(int paramIndex, Object paramValue) throws SQLException {
    String typeName = parameterMetaData.getParameterTypeName(paramIndex);
    Class javaClass = getDataTypeMappings().javaTypeFor(typeName);

    boolean replaceNullValue = this.cqlStmt.getConfiguration().replaceNullValue();

    if (javaClass != null) {
        paramValue = getDataTypeConverters().convert(paramValue, javaClass, replaceNullValue);
        // time is mapped by the driver to a primitive long, representing the number of nanoseconds since midnight
        if (CassandraDataType.TIME.getTypeName().equals(typeName) && paramValue instanceof Time) {
            Time time = (Time) paramValue;
            paramValue = new LocalTime(time).getMillisOfDay() * 1000000L;
        } else if (CassandraDataType.DATE.getTypeName().equals(typeName) && paramValue instanceof Date) {
            LocalDate localDate = LocalDate.fromDateFields((Date) paramValue);
            paramValue = com.datastax.driver.core.LocalDate.fromYearMonthDay(localDate.getYear(),
                    localDate.getMonthOfYear(), localDate.getDayOfMonth());
        } else if (CassandraDataType.BLOB.getTypeName().equals(typeName) && paramValue instanceof byte[]) {
            paramValue = ByteBuffer.wrap((byte[]) paramValue);
        }/*from  w  ww. j  a v a  2 s  . co  m*/

        parameters.put(paramIndex, paramValue);
    } else {
        super.setParameter(paramIndex, paramValue);
    }
}

From source file:com.github.cassandra.jdbc.provider.datastax.codecs.JavaSqlTimeCodec.java

License:Apache License

@Override
public ByteBuffer serialize(Time value, ProtocolVersion protocolVersion) throws InvalidTypeException {
    if (value == null)
        return null;
    return bigint().serializeNoBoxing(new LocalTime(value.getTime()).getMillisOfDay() * 1000000L,
            protocolVersion);/*from w w w  . j  av  a 2 s  .  co m*/
}

From source file:com.github.cassandra.jdbc.provider.datastax.codecs.JavaSqlTimeCodec.java

License:Apache License

@Override
public String format(Time value) {
    if (value == null)
        return "NULL";
    return quote(new LocalTime(value.getTime()).toString());
}