Example usage for java.util GregorianCalendar clone

List of usage examples for java.util GregorianCalendar clone

Introduction

In this page you can find the example usage for java.util GregorianCalendar clone.

Prototype

@Override
    public Object clone() 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal = new GregorianCalendar();

    // clone object cal into object y
    GregorianCalendar y = (GregorianCalendar) cal.clone();

    // print both cal and y
    System.out.println(cal.getTime());
    System.out.println(y.getTime());

}

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal1 = (GregorianCalendar) GregorianCalendar.getInstance();

    // create a second calendar equal to first one
    GregorianCalendar cal2 = (GregorianCalendar) (Calendar) cal1.clone();

    // print cal2
    System.out.println(cal2.getTime());

    // compare the two calendars
    System.out.println("Cal1 and Cal2 are equal:" + cal1.equals(cal2));

    // change cal 2 a bit
    cal2.add(GregorianCalendar.YEAR, 5);

    // compare the two calendars
    System.out.println("Cal1 and Cal2 are equal:" + cal1.equals(cal2));

}

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal1 = (GregorianCalendar) GregorianCalendar.getInstance();

    // create a second calendar
    GregorianCalendar cal2 = new GregorianCalendar();

    // clone cal1 to cal2
    cal2 = (GregorianCalendar) cal1.clone();

    // print cal2
    System.out.println(cal2.getTime());

}

From source file:fr.ippon.wip.ltpa.token.LtpaLibrary.java

/**
 * Create a valid LTPA token for the specified user.
 *
 * @param username        - the user to create the LTPA token for.
 * @param creationTime    - the time the token becomes valid.
 * @param durationMinutes - the duration of the token validity in minutes.
 * @param ltpaSecretStr   - the LTPA Domino Secret to use to create the token.
 * @return - base64 encoded LTPA token, ready for the cookie.
 * @throws NoSuchAlgorithmException//  w ww  .jav a2 s. c o  m
 */
public static String createLtpaToken(String username, GregorianCalendar creationTime, int durationMinutes,
        String ltpaSecretStr) throws NoSuchAlgorithmException {
    // create byte array buffers for both strings
    byte[] ltpaSecret = Base64.decodeBase64(ltpaSecretStr.getBytes());
    byte[] usernameArray = username.getBytes();

    byte[] workingBuffer = new byte[preUserDataLength + usernameArray.length + ltpaSecret.length];

    // copy version into workingBuffer
    System.arraycopy(ltpaTokenVersion, 0, workingBuffer, 0, ltpaTokenVersion.length);

    GregorianCalendar expirationDate = (GregorianCalendar) creationTime.clone();
    expirationDate.add(Calendar.MINUTE, durationMinutes);

    // copy creation date into workingBuffer
    String hex = dateStringFiller
            + Integer.toHexString((int) (creationTime.getTimeInMillis() / 1000)).toUpperCase();
    System.arraycopy(hex.getBytes(), hex.getBytes().length - dateStringLength, workingBuffer,
            creationDatePosition, dateStringLength);

    // copy expiration date into workingBuffer
    hex = dateStringFiller + Integer.toHexString((int) (expirationDate.getTimeInMillis() / 1000)).toUpperCase();
    System.arraycopy(hex.getBytes(), hex.getBytes().length - dateStringLength, workingBuffer,
            expirationDatePosition, dateStringLength);

    // copy user name into workingBuffer
    System.arraycopy(usernameArray, 0, workingBuffer, preUserDataLength, usernameArray.length);

    // copy the ltpaSecret into the workingBuffer
    System.arraycopy(ltpaSecret, 0, workingBuffer, preUserDataLength + usernameArray.length, ltpaSecret.length);

    byte[] hash = createHash(workingBuffer);

    // put the public data and the hash into the outputBuffer
    byte[] outputBuffer = new byte[preUserDataLength + usernameArray.length + hashLength];
    System.arraycopy(workingBuffer, 0, outputBuffer, 0, preUserDataLength + usernameArray.length);
    System.arraycopy(hash, 0, outputBuffer, preUserDataLength + usernameArray.length, hashLength);

    return new String(Base64.encodeBase64(outputBuffer));
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.BookingRoomAjaxController.java

@Override
public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
    Map map = new HashMap<String, Object>();
    GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson());

    if (request.getParameter("type").compareTo("info") == 0) {
        int id = Integer.parseInt(request.getParameter("id"));
        Reservation reservation = reservationDao.getReservationById(id);
        GregorianCalendar created = new GregorianCalendar();
        created.setTime(reservation.getCreationTime());
        GregorianCalendar startTime = new GregorianCalendar();
        startTime.setTime(reservation.getStartTime());
        GregorianCalendar endTime = new GregorianCalendar();
        endTime.setTime(reservation.getEndTime());

        Map data = new HashMap<String, Object>();
        data.put("id", id);
        data.put("person", reservation.getPerson());
        data.put("created", BookingRoomUtils.getDate(created) + ", " + BookingRoomUtils.getTime(created));
        data.put("date", BookingRoomUtils.getDate(startTime));
        data.put("start", BookingRoomUtils.getHoursAndMinutes(startTime));
        data.put("end", BookingRoomUtils.getHoursAndMinutes(endTime));

        map.put("data", data);
        return map;
    }/* w  ww  . j a  v  a  2  s .c  o  m*/

    if (request.getParameter("type").compareTo("delete") == 0) {
        int id = Integer.parseInt(request.getParameter("id"));

        if (reservationDao.deleteReservation(id)) {
            map.put("status", messageSource.getMessage("bookRoom.delete.success", null,
                    RequestContextUtils.getLocale(request)));
        } else {
            map.put("status", messageSource.getMessage("bookRoom.delete.error", null,
                    RequestContextUtils.getLocale(request)));
        }

        return map;
    }

    if (request.getParameter("type").compareTo("timeline") == 0) {
        String date = request.getParameter("date") + " 00:00:00";
        log.debug("XML DATE=" + date);
        GregorianCalendar monthStart = BookingRoomUtils.getCalendar(date);
        monthStart.set(Calendar.DAY_OF_MONTH, 1);
        GregorianCalendar monthEnd = (GregorianCalendar) monthStart.clone();
        monthEnd.add(Calendar.MONTH, 1);
        monthEnd.add(Calendar.SECOND, -1);

        String xml = BookingRoomXmlUtils.formatReservationsList(
                reservationDao.getReservationsBetween(monthStart, monthEnd), personDao.getLoggedPerson());

        map.put("xmlContent", xml);
        return map;
    }

    throw new InvalidAttributeValueException(
            "Attribute '" + request.getParameter("type") + "' is not allowed!");
}

From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java

private ArrayList<String> buildLabels(GregorianCalendar start, GregorianCalendar end, int scale) {

    ArrayList<String> labels = new ArrayList<String>();

    GregorianCalendar lower = (GregorianCalendar) start.clone();
    GregorianCalendar upper = new GregorianCalendar();
    GregorianCalendar split = new GregorianCalendar();

    while (lower.getTimeInMillis() <= end.getTimeInMillis()) {
        upper.setTime(lower.getTime());/*from ww w  . ja v  a 2 s .  c  om*/
        upper.add(scale, 1);
        split.setTime(
                new Date(lower.getTimeInMillis() + (upper.getTimeInMillis() - lower.getTimeInMillis()) / 2));
        /*
        System.out.printf("%s-%s-%s%n", lower.getTime().toString(),
                   split.getTime().toString(),
                   upper.getTime().toString());
         */
        labels.add(getLabel(scale, split));
        lower.setTime(upper.getTime());
    }

    return labels;

}

From source file:com.example.oris1991.anotherme.ExternalCalendar.CalendarAdapter.java

public CalendarAdapter(Context c, GregorianCalendar monthCalendar) {
    CalendarAdapter.dayString = new ArrayList<String>();
    Locale.setDefault(Locale.US);
    month = monthCalendar;//from  w  w  w . j  a va  2s .c  om
    selectedDate = (GregorianCalendar) monthCalendar.clone();
    mContext = c;
    month.set(GregorianCalendar.DAY_OF_MONTH, 1);
    this.items = new ArrayList<String>();
    df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    curentDateString = df.format(selectedDate.getTime());
    refreshDays();
}

From source file:com.dell.asm.asmcore.asmmanager.db.entity.ServiceTemplateEntity.java

public void setUpdatedDate(GregorianCalendar updatedDate) {
    this.updatedDate = (updatedDate == null) ? null : (GregorianCalendar) updatedDate.clone();
}

From source file:com.dell.asm.asmcore.asmmanager.db.entity.ServiceTemplateEntity.java

public void setCreatedDate(GregorianCalendar createdDate) {
    this.createdDate = (createdDate == null) ? null : (GregorianCalendar) createdDate.clone();

}

From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java

private ArrayList<Integer> buildFrequencies(GregorianCalendar start, GregorianCalendar end, int scale,
        Long[] list) {//from   w  w w  .  j a  v a  2 s . c o  m

    ArrayList<Integer> freqs = new ArrayList<Integer>();

    GregorianCalendar lower = (GregorianCalendar) start.clone();
    GregorianCalendar upper = new GregorianCalendar();

    while (lower.getTimeInMillis() <= end.getTimeInMillis()) {
        upper.setTime(lower.getTime());
        upper.add(scale, 1);

        int freq = 0;

        for (int i = 0; i < list.length; i++) {
            if (lower.getTimeInMillis() <= list[i] && list[i] < upper.getTimeInMillis()) {
                freq++;
                //System.out.printf("%d - %d - %d - %d%n", lower.getTimeInMillis(), list[i], upper.getTimeInMillis(), freq);
            }
        }
        freqs.add(freq);
        lower.setTime(upper.getTime());

    }

    return freqs;

}