Example usage for java.util Calendar WEEK_OF_YEAR

List of usage examples for java.util Calendar WEEK_OF_YEAR

Introduction

In this page you can find the example usage for java.util Calendar WEEK_OF_YEAR.

Prototype

int WEEK_OF_YEAR

To view the source code for java.util Calendar WEEK_OF_YEAR.

Click Source Link

Document

Field number for get and set indicating the week number within the current year.

Usage

From source file:com.frameworkset.platform.sanylog.action.CounterController.java

@SuppressWarnings("rawtypes")
public @ResponseBody String operUserCompare(String type, String appId, String time) throws Exception {
    if ("".equals(appId) || null == appId) {
        return null;
    }//  w w  w .j  a v  a2s  . co m
    String tableName = "";
    float divisor = 1;
    if ("day".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            time = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN);
        }
        tableName = "TD_LOG_OPERSTATIC_BYDAY";
        divisor = 30;

    } else if ("week".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            String todayTime = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN);
            String week = String.valueOf(today.get(Calendar.WEEK_OF_YEAR));
            time = todayTime.substring(0, 4) + "-" + week;
        }
        tableName = "TD_LOG_OPERSTATIC_BYWEEK";
        divisor = 4;
    } else if ("month".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            time = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN).substring(0, 7);
        }
        divisor = (float) 0.083;
        tableName = "TD_LOG_OPERSTATIC_BYMONTH";
    } else if ("year".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            time = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN).substring(0, 4);
        }
        tableName = "TD_LOG_OPERSTATIC_BYYEAR";
    }
    List<OperChart> datas = counterManager.getOperChartUser(appId, time, tableName, divisor);
    String dataXML = "<chart xAxisName = '??' yAxisName='' showValues='0'>";
    dataXML += "<dataset label='' value='' />";
    String categories = "<categories>";
    String datasetSim = "<dataset seriesName=''>";
    String datasetCom = "<dataset seriesName=''>";
    if (datas.size() > 0) {
        for (OperChart bean : datas) {
            categories += "<category label=' " + bean.getModuleName() + " ' />";
            datasetSim += "<set value='" + bean.getVcountUser() + "' />";
            datasetCom += "<set value='" + bean.getEstimateUser() + "' />";
        }
    }
    categories += "</categories>";
    datasetSim += "</dataset>";
    datasetCom += "</dataset>";
    dataXML += categories + datasetSim + datasetCom;
    dataXML += "</chart>";
    return dataXML;

}

From source file:org.skfiy.typhon.spi.hero.HeroProvider.java

/**
 * //from  ww w  . ja va2  s . c o m
 * @param packet
 */
public void buyTuhaoLottery(Packet packet) {
    Player player = SessionUtils.getPlayer();
    MultipleValue result = MultipleValue.createResult(packet);

    Calendar cal = Calendar.getInstance();
    // ?
    int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
    if (weekOfYear != 1 && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        weekOfYear--;
    }

    TuhaoWeekLottery tuhaoWeekLottery = tuhaoWeekLotteries.get(weekOfYear - 1);

    boolean heroed = drawTuhao0(player, tuhaoWeekLottery);
    if (heroed) {
        result.addVal(pushLottery(tuhaoWeekLottery, false, true));
    } else {
        int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
        Lottery tuhaoDayLottery = spueLottery(tuhaoRandom, tuhaoDayLotteries.get(dayOfMonth - 1), 100);
        result.addVal(pushLottery(tuhaoDayLottery, false, true));
    }

    Lottery tuhaoLottery;
    for (int i = 0; i < 5; i++) {
        tuhaoLottery = spueLottery(tuhaoRandom, tuhaoLotteries, tuhaoRandomFactor);
        result.addVal(pushLottery(tuhaoLottery, false, true));
    }

    int diamond = Typhons.getInteger("typhon.spi.hero.diamondTuhaoLottery.1.depletion");

    JSONObject plog = new JSONObject();
    plog.put("name", "Tuhao");
    plog.put("items", result.getVals());
    SessionUtils.decrementDiamond(diamond, plog.toJSONString());

    player.getSession().write(result);
}

From source file:com.aurel.track.report.dashboard.StatusOverTimeGraph.java

/**
* Create a map of hierarchical data with TStateChangeBeans for the workItems in the periods
* -   key: year/*from w w w. j  a v  a2 s  .  co  m*/
* -   value: map
*          -   key: period
*          -   Set of HistorySelectValues
* @param statusChangeList
* @param timeInterval
* @param sample sample (only last from the period) or action (all statuses during a period)
* @return
*/
private static SortedMap<Integer, SortedMap<Integer, List<HistorySelectValues>>> getStatusChangesMap(
        List<HistorySelectValues> statusChangeList, int timeInterval, boolean sample) {
    SortedMap<Integer, SortedMap<Integer, List<HistorySelectValues>>> yearToIntervalToStatusChangeBeans = new TreeMap<Integer, SortedMap<Integer, List<HistorySelectValues>>>();
    Map yearToIntervalToWorkItemIDs = new HashMap();
    int yearValue;
    int intervalValue;
    Integer workItemID;
    if (statusChangeList != null && !statusChangeList.isEmpty()) {
        Calendar calendarLastModified = Calendar.getInstance();
        //get them in the reverse order (the later first)
        Iterator iterator = statusChangeList.iterator();
        int calendarInterval = getCalendarInterval(timeInterval);
        Set workItemsIDsForInterval = new HashSet();
        while (iterator.hasNext()) {
            HistorySelectValues stateChangeBean = (HistorySelectValues) iterator.next();
            workItemID = stateChangeBean.getWorkItemID();
            calendarLastModified.setTime(stateChangeBean.getLastEdit());
            yearValue = calendarLastModified.get(Calendar.YEAR);
            intervalValue = calendarLastModified.get(calendarInterval);
            if (Calendar.WEEK_OF_YEAR == calendarInterval) {
                //avoid adding the first week of the new year as the first week of the old year,
                //because it can be that the year is the old one but the last days of the year belong to the first week of the next year
                //and that would add an entry with the first week of the old year
                int monthValue = calendarLastModified.get(Calendar.MONTH);
                if (monthValue >= 11 && intervalValue == 1) {
                    yearValue = yearValue + 1;
                }
            }
            if (sample) {
                Map intervalToWorkItems = (Map) yearToIntervalToWorkItemIDs.get(new Integer(yearValue));
                if (intervalToWorkItems == null) {
                    yearToIntervalToWorkItemIDs.put(new Integer(yearValue), new HashMap());
                    intervalToWorkItems = (Map) yearToIntervalToWorkItemIDs.get(new Integer(yearValue));
                }
                workItemsIDsForInterval = (Set) intervalToWorkItems.get(new Integer(intervalValue));
                if (workItemsIDsForInterval == null) {
                    intervalToWorkItems.put(new Integer(intervalValue), new HashSet());
                    workItemsIDsForInterval = (Set) intervalToWorkItems.get(new Integer(intervalValue));
                }
            }
            //add the stateChangeBean if:
            //1. if not sample add all stateChangeBeans
            //2. if sample: add only one (the latest i.e. the first one from the list) for each period
            if (!sample || !workItemsIDsForInterval.contains(workItemID)) {
                if (sample) {
                    //add workItemID to forbid adding the same workItemID again for the same period
                    workItemsIDsForInterval.add(workItemID);
                    //the last state change bean for the period for the workItem is
                    //a change to a status which is not selected to be shown, so simply neglect it
                    /*if (!statusIDsSet.contains(stateChangeBean.getNewValue())) {
                       continue;
                    }*/
                }
                //workItemIDsSet.add(workItemID);
                SortedMap<Integer, List<HistorySelectValues>> intervalToStatusChangeBeans = yearToIntervalToStatusChangeBeans
                        .get(new Integer(yearValue));
                if (intervalToStatusChangeBeans == null) {
                    yearToIntervalToStatusChangeBeans.put(new Integer(yearValue),
                            new TreeMap<Integer, List<HistorySelectValues>>());
                    intervalToStatusChangeBeans = yearToIntervalToStatusChangeBeans.get(new Integer(yearValue));
                }
                List<HistorySelectValues> statusChangeBeansForInterval = intervalToStatusChangeBeans
                        .get(new Integer(intervalValue));
                if (statusChangeBeansForInterval == null) {
                    intervalToStatusChangeBeans.put(new Integer(intervalValue), new ArrayList());
                    statusChangeBeansForInterval = intervalToStatusChangeBeans.get(new Integer(intervalValue));
                }
                statusChangeBeansForInterval.add(stateChangeBean);
            }
        }
    }
    return yearToIntervalToStatusChangeBeans;
}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

private void writeDays(DOMContext domContext, FacesContext facesContext, ResponseWriter writer,
        SelectInputDate inputComponent, Calendar timeKeeper, int currentDay, int weekStartsAtDayIndex,
        int weekDayOfFirstDayOfMonth, int lastDayInMonth, Element table, String[] months, String[] weekdays,
        String[] weekdaysLong, Converter converter, Date value) throws IOException {
    Calendar cal;/* w w w. jav a2  s  .  c  o m*/

    int space = (weekStartsAtDayIndex < weekDayOfFirstDayOfMonth)
            ? (weekDayOfFirstDayOfMonth - weekStartsAtDayIndex)
            : (weekdays.length - weekStartsAtDayIndex + weekDayOfFirstDayOfMonth);

    if (space == weekdays.length) {
        space = 0;
    }

    int columnIndexCounter = 0;

    Element tr1 = null;
    for (int i = 0; i < space; i++) {
        if (columnIndexCounter == 0) {
            tr1 = domContext.createElement(HTML.TR_ELEM);
            table.appendChild(tr1);
            if (inputComponent.isRenderWeekNumbers()) {
                cal = copyCalendar(facesContext, timeKeeper);
                cal.set(Calendar.DAY_OF_MONTH, 1);
                Element td = domContext.createElement(HTML.TD_ELEM);
                td.setAttribute(HTML.CLASS_ATTR, Util.getQualifiedStyleClass(inputComponent,
                        CSS_DEFAULT.DEFAULT_WEEK_NUM_CLASS, inputComponent.isDisabled()));
                tr1.appendChild(td);
                Text text = domContext.createTextNode(String.valueOf(cal.get(Calendar.WEEK_OF_YEAR)));
                td.appendChild(text);
            }
        }

        writeCell(domContext, facesContext, writer, inputComponent, NBSP, null,
                inputComponent.getDayCellClass(), tr1, null, (weekStartsAtDayIndex + i) % 7, timeKeeper, months,
                weekdaysLong, converter);
        columnIndexCounter++;
    }

    Element tr2 = null;
    for (int i = 0; i < lastDayInMonth; i++) {
        if (columnIndexCounter == 0) {
            // don't create a new row until we have finished the last
            tr2 = domContext.createElement(HTML.TR_ELEM);
            table.appendChild(tr2);
        }

        cal = copyCalendar(facesContext, timeKeeper);
        cal.set(Calendar.DAY_OF_MONTH, i + 1); // i starts at 0 DAY_OF_MONTH start at 1

        // get day, month and year
        // use these to check if the currentDayCell style class should be used
        int day = 0;
        int month = 0;
        int year = 0;
        try {
            Calendar current = copyCalendar(facesContext, timeKeeper);
            current.setTime(value);

            day = current.get(Calendar.DAY_OF_MONTH); // starts with 1
            month = current.get(Calendar.MONTH); // starts with 0
            year = current.get(Calendar.YEAR);
        } catch (Exception e) {
            // hmmm this should never happen
        }
        if (inputComponent.isRenderWeekNumbers() && columnIndexCounter == 0) {
            Element td = domContext.createElement(HTML.TD_ELEM);
            td.setAttribute(HTML.CLASS_ATTR, Util.getQualifiedStyleClass(inputComponent,
                    CSS_DEFAULT.DEFAULT_WEEK_NUM_CLASS, inputComponent.isDisabled()));
            tr2.appendChild(td);
            Text text = domContext.createTextNode(String.valueOf(cal.get(Calendar.WEEK_OF_YEAR)));
            td.appendChild(text);
        }

        if (inputComponent.getHightlightRules().size() > 0) {
            int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
            int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
            int date = cal.get(Calendar.DATE);
            int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
            int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
            int dayOfWeekInMonth = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);

            if (inputComponent.getHightlightRules().containsKey(Calendar.WEEK_OF_YEAR + "$" + weekOfYear)) {
                inputComponent.addHighlightWeekClass(String.valueOf(
                        inputComponent.getHightlightRules().get(Calendar.WEEK_OF_YEAR + "$" + weekOfYear)));
            }
            if (inputComponent.getHightlightRules().containsKey(Calendar.WEEK_OF_MONTH + "$" + weekOfMonth)) {
                inputComponent.addHighlightWeekClass(String.valueOf(
                        inputComponent.getHightlightRules().get(Calendar.WEEK_OF_MONTH + "$" + weekOfMonth)));
            }
            if (inputComponent.getHightlightRules().containsKey(Calendar.DATE + "$" + date)) {
                inputComponent.addHighlightDayClass(
                        String.valueOf(inputComponent.getHightlightRules().get(Calendar.DATE + "$" + date)));
            }
            if (inputComponent.getHightlightRules().containsKey(Calendar.DAY_OF_YEAR + "$" + dayOfYear)) {
                inputComponent.addHighlightDayClass(String.valueOf(
                        inputComponent.getHightlightRules().get(Calendar.DAY_OF_YEAR + "$" + dayOfYear)));
            }
            if (inputComponent.getHightlightRules().containsKey(Calendar.DAY_OF_WEEK + "$" + dayOfWeek)) {
                inputComponent.addHighlightDayClass(String.valueOf(
                        inputComponent.getHightlightRules().get(Calendar.DAY_OF_WEEK + "$" + dayOfWeek)));
            }
            if (inputComponent.getHightlightRules()
                    .containsKey(Calendar.DAY_OF_WEEK_IN_MONTH + "$" + dayOfWeekInMonth)) {
                inputComponent.addHighlightDayClass(String.valueOf(inputComponent.getHightlightRules()
                        .get(Calendar.DAY_OF_WEEK_IN_MONTH + "$" + dayOfWeekInMonth)));
            }
        }

        String cellStyle = CSSNamePool
                .get(inputComponent.getDayCellClass() + " " + inputComponent.getHighlightDayCellClass());

        if ((cal.get(Calendar.DAY_OF_MONTH) == day) && (cal.get(Calendar.MONTH) == month)
                && (cal.get(Calendar.YEAR) == year)) {
            cellStyle = inputComponent.getCurrentDayCellClass();
        }

        // do not automatically select date when navigating by month
        if ((cal.get(Calendar.DAY_OF_MONTH) == day) && (cal.get(Calendar.MONTH) == month)
                && (cal.get(Calendar.YEAR) == year)) {
            cellStyle = inputComponent.getCurrentDayCellClass();
        }

        if (tr2 == null) {
            // finish the first row
            writeCell(domContext, facesContext, writer, inputComponent, String.valueOf(i + 1), cal.getTime(),
                    cellStyle, tr1, null, i, timeKeeper, months, weekdaysLong, converter);
        } else {
            // write to new row
            writeCell(domContext, facesContext, writer, inputComponent, String.valueOf(i + 1), cal.getTime(),
                    cellStyle, tr2, null, i, timeKeeper, months, weekdaysLong, converter);
        }

        columnIndexCounter++;

        if (columnIndexCounter == weekdays.length) {
            columnIndexCounter = 0;
        }
        inputComponent.resetHighlightClasses(Calendar.WEEK_OF_YEAR);
    }

    if ((columnIndexCounter != 0) && (tr2 != null)) {
        for (int i = columnIndexCounter; i < weekdays.length; i++) {
            writeCell(domContext, facesContext, writer, inputComponent, NBSP, null,
                    inputComponent.getDayCellClass(), tr2, null, (weekStartsAtDayIndex + i) % 7, timeKeeper,
                    months, weekdaysLong, converter);
        }
    }

}

From source file:com.aurel.track.report.dashboard.StatusOverTimeGraph.java

/**
* Create a map of hierarchical data with TWorkItemBeans in the periods
* -   key: year//from w  ww  . ja v  a2s  .com
* -   value: map
*          -   key: period
*          -   Set of TStateChangeBeans, one for each workItem
* @param timeInterval
* @return
*/
private static SortedMap<Integer, SortedMap<Integer, List<TWorkItemBean>>> getNewWorkItemsMap(List workItemList,
        int timeInterval, Date dateFrom, Date dateTo) {
    SortedMap<Integer, SortedMap<Integer, List<TWorkItemBean>>> yearToIntervalToWorkItemBeans = new TreeMap();
    int yearValue;
    int intervalValue;
    if (workItemList != null) {
        Calendar calendarCreated = Calendar.getInstance();
        Iterator iterator = workItemList.iterator();
        int calendarInterval = getCalendarInterval(timeInterval);
        while (iterator.hasNext()) {
            TWorkItemBean workItemBean = (TWorkItemBean) iterator.next();
            Date createDate = workItemBean.getCreated();
            if (createDate == null) {
                continue;
            }
            if (dateFrom != null && dateFrom.after(createDate) || dateTo != null && dateTo.before(createDate)) {
                continue;
            }
            calendarCreated.setTime(workItemBean.getCreated());
            yearValue = calendarCreated.get(Calendar.YEAR);
            intervalValue = calendarCreated.get(calendarInterval);
            if (Calendar.WEEK_OF_YEAR == calendarInterval) {
                //avoid adding the first week of the new year as the first week of the old year,
                //because it can be that the year is the old one but the last days of the year belong to the first week of the next year
                //and that would add an entry with the first week of the old year
                int monthValue = calendarCreated.get(Calendar.MONTH);
                if (monthValue >= 11 && intervalValue == 1) {
                    yearValue = yearValue + 1;
                }
            }
            SortedMap<Integer, List<TWorkItemBean>> intervalToWorkItemBeans = yearToIntervalToWorkItemBeans
                    .get(new Integer(yearValue));
            if (intervalToWorkItemBeans == null) {
                yearToIntervalToWorkItemBeans.put(new Integer(yearValue), new TreeMap());
                intervalToWorkItemBeans = yearToIntervalToWorkItemBeans.get(new Integer(yearValue));
            }
            List<TWorkItemBean> workItemBeansForInterval = intervalToWorkItemBeans
                    .get(new Integer(intervalValue));
            if (workItemBeansForInterval == null) {
                intervalToWorkItemBeans.put(new Integer(intervalValue), new ArrayList());
                workItemBeansForInterval = intervalToWorkItemBeans.get(new Integer(intervalValue));
            }
            workItemBeansForInterval.add(workItemBean);
        }
    }
    return yearToIntervalToWorkItemBeans;
}

From source file:com.aurel.track.report.dashboard.StatusOverTimeGraph.java

/**
 * Get the corresponding calendar constant
 * @param timeInterval/*  w w  w.  ja  v  a 2  s .  c  o m*/
 * @return
 */
private static int getCalendarInterval(int timeInterval) {
    switch (timeInterval) {
    case TIME_INTERVAL.DAY:
        return Calendar.DAY_OF_YEAR;
    case TIME_INTERVAL.WEEK:
        return Calendar.WEEK_OF_YEAR;
    default:
        return Calendar.MONTH;
    }
}

From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java

private void SingleChoice() {
    Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.choose_time));
    // dropdown setup
    final String array_spinner[];

    array_spinner = new String[4];
    array_spinner[0] = getString(R.string.time_period_1week);
    array_spinner[1] = getString(R.string.time_period_1month);
    array_spinner[2] = getString(R.string.time_period_3months);
    array_spinner[3] = getString(R.string.time_period_1year);

    builder.setItems(array_spinner, new DialogInterface.OnClickListener() {
        @Override//from  w w  w .j  ava  2s.c om
        public void onClick(DialogInterface dialog, int which) {

            int weeks = 0;

            if (array_spinner[which] == getString(R.string.time_period_1week)) {
                weeks = 1;
            }
            if (array_spinner[which] == getString(R.string.time_period_1month)) {
                weeks = 4;
            }
            if (array_spinner[which] == getString(R.string.time_period_3months)) {
                weeks = 12;
            }
            if (array_spinner[which] == getString(R.string.time_period_1year)) {
                weeks = 52;
            }

            TextView tvHeader = (TextView) findViewById(R.id.timeperiod);
            tvHeader.setText(array_spinner[which]);

            loadAverage(weeks);

            Calendar now = Calendar.getInstance();
            long current_dtime = now.getTimeInMillis();
            now.add(Calendar.WEEK_OF_YEAR, weeks * -1);
            long starting_dtime = now.getTimeInMillis();

            // update charts
            data = new JSONObject();

            data = dbHelper.getGraphData(TestResult.DOWNLOAD_TEST_ID, starting_dtime, current_dtime);
            graphHandler1.setData(data);
            graphHandler1.update();

            data = dbHelper.getGraphData(TestResult.UPLOAD_TEST_ID, starting_dtime, current_dtime);
            graphHandler2.setData(data);
            graphHandler2.update();

            data = dbHelper.getGraphData(TestResult.LATENCY_TEST_ID, starting_dtime, current_dtime);
            graphHandler3.setData(data);
            graphHandler3.update();

            data = dbHelper.getGraphData(TestResult.PACKETLOSS_TEST_ID, starting_dtime, current_dtime);
            graphHandler4.setData(data);
            graphHandler4.update();

            data = dbHelper.getGraphData(TestResult.JITTER_TEST_ID, starting_dtime, current_dtime);
            graphHandler5.setData(data);
            graphHandler5.update();

            dialog.dismiss();
        }
    });
    builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:ECallCenter21.java

private void orderVergunningCode() {
    String[] status = new String[2];
    //        activationCodeField.setText(Long.toString(Calendar.getInstance().getTimeInMillis()));
    String activationCodeString = null;
    String activationCodeKeyString = null;

    vergunning.setVergunningOrderInProgress(true);
    performanceMeter.setCallPerHourScale(0, (Vergunning.CALLSPERHOUR_ENTERPRISE / 100),
            (Vergunning.CALLSPERHOUR_ENTERPRISE / 1000));

    // Prematurely writing Vergunning Type Details
    if (!vergunningTypeList.isSelectionEmpty()) {
        if (vergunningTypeList.getSelectedValue().equals("Demo")) {
            vergunning.setVergunningType("Demo");
            vergunning.setPhoneLines(vergunning.PHONELINES_DEMO);
            vergunning.setCallsPerHour(vergunning.CALLSPERHOUR_DEMO);
            vergunning.setMaxCalls(vergunning.MAXCALLS_DEMO);
            vergunning.setDestinationDigits(vergunning.DESTINATIONDIGITS_DEMO);
            vergunningDetailsTable.setValueAt(vergunning.getVergunningType(), 1, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getPhoneLines()), 5, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getCallsPerHour()), 6, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getMaxCalls()), 7, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getDestinationDigits()), 8, 1);
        } else if (vergunningTypeList.getSelectedValue().equals("Standard")) {
            vergunning.setVergunningType("Standard");
            vergunning.setPhoneLines(vergunning.PHONELINES_STANDARD);
            vergunning.setCallsPerHour(vergunning.CALLSPERHOUR_STANDARD);
            vergunning.setMaxCalls(vergunning.MAXCALLS_STANDARD);
            vergunning.setDestinationDigits(vergunning.DESTINATIONDIGITS_STANDARD);
            vergunningDetailsTable.setValueAt(vergunning.getVergunningType(), 1, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getPhoneLines()), 5, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getCallsPerHour()), 6, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getMaxCalls()), 7, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getDestinationDigits()), 8, 1);
        } else if (vergunningTypeList.getSelectedValue().equals("Professional")) {
            vergunning.setVergunningType("Professional");
            vergunning.setPhoneLines(vergunning.PHONELINES_PROFESSIONAL);
            vergunning.setCallsPerHour(vergunning.CALLSPERHOUR_PROFESSIONAL);
            vergunning.setMaxCalls(vergunning.MAXCALLS_PROFESSIONAL);
            vergunning.setDestinationDigits(vergunning.DESTINATIONDIGITS_PROFESSIONAL);
            vergunningDetailsTable.setValueAt(vergunning.getVergunningType(), 1, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getPhoneLines()), 5, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getCallsPerHour()), 6, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getMaxCalls()), 7, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getDestinationDigits()), 8, 1);
        } else if (vergunningTypeList.getSelectedValue().equals("Enterprise")) {
            vergunning.setVergunningType("Enterprise");
            vergunning.setPhoneLines(vergunning.PHONELINES_ENTERPRISE);
            vergunning.setCallsPerHour(vergunning.CALLSPERHOUR_ENTERPRISE);
            vergunning.setMaxCalls(vergunning.MAXCALLS_ENTERPRISE);
            vergunning.setDestinationDigits(vergunning.DESTINATIONDIGITS_ENTERPRISE);
            vergunningDetailsTable.setValueAt(vergunning.getVergunningType(), 1, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getPhoneLines()), 5, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getCallsPerHour()), 6, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getMaxCalls()), 7, 1);
            vergunningDetailsTable.setValueAt(Integer.toString(vergunning.getDestinationDigits()), 8, 1);
        }/*  www  . ja  v  a2s  .  co  m*/
    }

    // Prematurely writing vergunning Start Date Details
    if (vergunningDateChooserPanel.getSelectedDate() != null) {
        vergunningEndCalendar.setTimeInMillis(vergunningStartCalendar.getTimeInMillis());
        if (vergunningPeriodList.getSelectedValue().equals("Day")) {
            vergunningEndCalendar.add(Calendar.DAY_OF_YEAR, 1);
            vergunning.setVergunningEndDate(vergunningEndCalendar);
        } else if (vergunningPeriodList.getSelectedValue().equals("Week")) {
            vergunningEndCalendar.add(Calendar.WEEK_OF_YEAR, 1);
            vergunning.setVergunningEndDate(vergunningEndCalendar);
        } else if (vergunningPeriodList.getSelectedValue().equals("Month")) {
            vergunningEndCalendar.add(Calendar.MONTH, 1);
            vergunning.setVergunningEndDate(vergunningEndCalendar);
        } else if (vergunningPeriodList.getSelectedValue().equals("Year")) {
            vergunningEndCalendar.add(Calendar.YEAR, 1);
            vergunning.setVergunningEndDate(vergunningEndCalendar);
        }

        vergunningDetailsTable.setValueAt(String.format("%04d", vergunningStartCalendar.get(Calendar.YEAR))
                + "-" + String.format("%02d", (vergunningStartCalendar.get(Calendar.MONTH)) + 1) + "-"
                + String.format("%02d", vergunningStartCalendar.get(Calendar.DAY_OF_MONTH)), 3, 1);
        vergunningDetailsTable.setValueAt(String.format("%04d", vergunningEndCalendar.get(Calendar.YEAR)) + "-"
                + String.format("%02d", (vergunningEndCalendar.get(Calendar.MONTH)) + 1) + "-"
                + String.format("%02d", vergunningEndCalendar.get(Calendar.DAY_OF_MONTH)), 4, 1);
    }

    // Prematurely writing vergunning Period Details
    if (!vergunningPeriodList.isSelectionEmpty()) {
        vergunning.setVergunningPeriod(vergunningPeriodList.getSelectedValue().toString());
        vergunningDetailsTable.setValueAt(vergunning.getVergunningPeriod(), 2, 1);
    }

    // If all vergunning fields are selected then write ActivationCode
    if ((vergunningTypeList.getSelectedValue() != null)
            && (vergunningDateChooserPanel.getSelectedDate() != null)
            && (vergunningPeriodList.getSelectedValue() != null)) {
        status = vergunning.getAK();
        if (status[0].equals("0")) {
            activationCodeKeyString = status[1];
            activationCodeString = vergunningTypeList.getSelectedValue().toString() + "-"
                    + String.format("%04d", vergunningStartCalendar.get(Calendar.YEAR)) + "-"
                    + String.format("%02d", (vergunningStartCalendar.get(Calendar.MONTH)) + 1) + "-"
                    + String.format("%02d", vergunningStartCalendar.get(Calendar.DAY_OF_MONTH)) + "-"
                    + vergunningPeriodList.getSelectedValue().toString() + "-" + activationCodeKeyString;
            activationCodeField.setText(activationCodeString);
            requestVergunningButton.setEnabled(true);
            showStatus("Please goto www." + Vergunning.BRAND.toLowerCase() + ".nl and request your LicenseCode",
                    false, false);
            vergunningCodeField.setText("");
            vergunningCodeField.setEnabled(true);
        }
    }

    // Put a little show on stage
    if (getCallCenterStatus() == POWEREDOFF) {
        movePerformanceMeter((vergunning.getCallsPerHour() / 100), true);
    } // true = smooth
}

From source file:kobytest.KobyTest.java

public static void wrapper_historico(int id_valor, String date, double high, double low, double open,
        double close) {
    System.out.println("Wrapper historico");

    if (date.indexOf("finished") != -1) {
        // we are finished
        // we should send the data now

        System.out.println("We are FINISHED. Let's send the data");
        enviar_datos_historicos(id_valor);

        return;//from w  w w . j a  va  2s .  c  o m
    }
    // date = 20141201 
    // 1. a que weeks_ago corresponde el date?
    int weeks_ago = 1;
    System.out.println("Fecha => " + date);
    int y = Integer.parseInt(date.substring(0, 4));
    int m = Integer.parseInt(date.substring(4, 6));
    int d = Integer.parseInt(date.substring(6, 8));

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, d);
    cal.set(Calendar.MONTH, m - 1);
    cal.set(Calendar.YEAR, y);
    System.out.println("The day returned: " + cal.getTime());
    int that_week = cal.get(Calendar.WEEK_OF_YEAR);

    Calendar cal_current = Calendar.getInstance();
    int current_week = cal_current.get(Calendar.WEEK_OF_YEAR);

    System.out.println("YEAR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + cal_current.get(Calendar.YEAR));
    System.out.println("THAT WEEK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + that_week);

    if (1 == that_week && cal_current.get(Calendar.YEAR) != y) {

        y = cal_current.get(Calendar.YEAR);
    }

    //if((current_week - that_week) < 0 )
    weeks_ago = current_week + 52 * (cal_current.get(Calendar.YEAR) - y) - that_week;
    //  else
    //      weeks_ago = current_week - that_week;
    System.out.println("Weeks ago => " + weeks_ago + "(" + current_week + "-" + that_week + ")");

    /*  if (weeks_ago < 0) {
     weeks_ago = current_week - (weeks_ago);
     weeks_ago--;
     }*/
    // historico_valores          HashMap<String,HashMap<Integer, HashMap<String,Double>>>
    System.out.println("is_valor -> " + id_valor);
    String valor = (String) valores_tabla.get(id_valor);
    System.out.println("simbolo -> " + valor);

    HashMap<String, Double> aux;// = historico_valores.get(valor).get(weeks_ago);
    //Test if exist. Override si se superan.

    if (historico_valores.get(valor).get(weeks_ago) == null) {
        System.out.println("1.1");
        aux = new HashMap<String, Double>();
        System.out.println("2");
        aux.put("high", high);
        aux.put("low", low);
        aux.put("values_collected", 1.);
        historico_valores.get(valor).put(weeks_ago, aux);
        historico_valores_cumulativo.get(valor).put(weeks_ago, null);
    } else {
        aux = historico_valores.get(valor).get(weeks_ago);
        // compare
        System.out.println("3");
        if (high != -1.0 && high > aux.get("high")) {
            aux.put("high", high);
        }
        if (low != -1.0 && low < aux.get("low")) {
            aux.put("low", low);
        }
        aux.put("values_collected", aux.get("values_collected") + 1);
        System.out.println("Carrying " + aux.get("values_collected"));
    }

    int i = (int) Math.floor(aux.get("values_collected"));
    System.out.println("Values collected so far:" + i);
    // devuelve todos los dias aunque no haya abierto??

    // Si queremos enviarlo cuando tenemos los 5 dias sin espera a todo.
    // Pero existe un problema: dias festivos: la semana no es de 5 dias
    /*
     if(i>=5){ //5 dias    
               
     // esperamos tambien a tener todos los dias?? total_weeks_ago?
     System.out.println("THERE YOU GO - "+valor +" FOR WEEKs ago "+weeks_ago);
     System.out.println("High: "+aux.get("high"));
     System.out.println("Low: "+aux.get("low"));
     System.out.println("Values collected: "+aux.get("values_collected"));
     // llamamos a callbak_historico solo si ya hemos preguntado por todos los dias        
     //callback_historico( valor,  weeks_ago,  high,  low, open,  close);
     }
     */
}

From source file:phenoviewer.ReNameJFrame.java

private String replaceTokens(Date date, int counter, String path) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);/*from   w  w w .  ja  v  a2  s .c om*/

    Map<String, Object> tokens = new HashMap<String, Object>();
    tokens.put("ERA", getText(gc.get(Calendar.ERA), "BC", "AD"));
    tokens.put("YEAR", getString(gc.get(Calendar.YEAR), 4, "0"));
    tokens.put("MONTH", getString(gc.get(Calendar.MONTH) + 1, 2, "0"));
    tokens.put("WEEK_OF_YEAR", getString(gc.get(Calendar.WEEK_OF_YEAR), 2, "0"));
    tokens.put("WEEK_OF_MONTH", getString(gc.get(Calendar.WEEK_OF_MONTH), 0, ""));
    tokens.put("DATE", getString(gc.get(Calendar.DATE), 2, "0"));
    tokens.put("DAY_OF_MONTH", getString(gc.get(Calendar.DAY_OF_MONTH), 2, "0"));
    tokens.put("DAY_OF_YEAR", getString(gc.get(Calendar.DAY_OF_YEAR), 3, "0"));
    tokens.put("DAY_OF_WEEK", getString(gc.get(Calendar.DAY_OF_WEEK), 0, ""));
    tokens.put("DAY_OF_WEEK_IN_MONTH", getString(gc.get(Calendar.DAY_OF_WEEK_IN_MONTH), 0, ""));
    tokens.put("AM_PM", getText(gc.get(Calendar.AM_PM), "AM", "PM"));
    tokens.put("HOUR", getString(gc.get(Calendar.HOUR), 2, "0"));
    tokens.put("HOUR_OF_DAY", getString(gc.get(Calendar.HOUR_OF_DAY), 2, "0"));
    tokens.put("MINUTE", getString(gc.get(Calendar.MINUTE), 2, "0"));
    tokens.put("SECOND", getString(gc.get(Calendar.SECOND), 2, "0"));
    tokens.put("MILLISECOND", getString(gc.get(Calendar.MILLISECOND), 3, "0"));
    // tokens.put("ZONE_OFFSET", getString((gc.get(Calendar.ZONE_OFFSET)/(60*60*1000)), 0, ""));
    // tokens.put("DST_OFFSET", getString((gc.get(Calendar.DST_OFFSET)/(60*60*1000)), 0, ""));
    tokens.put("COUNTER", getString(counter, 0, ""));

    return processParams(path, tokens);
}