Example usage for java.util Calendar getMaximum

List of usage examples for java.util Calendar getMaximum

Introduction

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

Prototype

public abstract int getMaximum(int field);

Source Link

Document

Returns the maximum value for the given calendar field of this Calendar instance.

Usage

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser.java

private Query buildEnd(String field, Calendar cal, int startField, int padField, int resolutionField) {
    BooleanQuery range = new BooleanQuery();
    Query part;/* w  ww  . ja  v  a2s .  c o m*/

    switch (startField) {
    case Calendar.YEAR:
        if (padField == Calendar.YEAR) {
            if (Calendar.YEAR < resolutionField) {
                if (cal.get(Calendar.YEAR) > cal.getMinimum(Calendar.YEAR)) {
                    part = new ConstantScoreRangeQuery(field, "YE" + cal.getMinimum(Calendar.YEAR),
                            "YE" + (cal.get(Calendar.YEAR) - 1), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.YEAR == resolutionField) {
                part = new ConstantScoreRangeQuery(field, "YE" + cal.getMinimum(Calendar.YEAR),
                        "YE" + (cal.get(Calendar.YEAR)), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.YEAR <= resolutionField) {
                part = new TermQuery(new Term(field, "YE" + cal.get(Calendar.YEAR)));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.MONTH:
        if (padField == Calendar.MONTH) {
            if (Calendar.MONTH < resolutionField) {
                if (cal.get(Calendar.MONTH) > cal.getMinimum(Calendar.MONTH)) {
                    part = new ConstantScoreRangeQuery(field, build2SF("MO", cal.getMinimum(Calendar.MONTH)),
                            build2SF("MO", (cal.get(Calendar.MONTH) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.MONTH == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("MO", cal.getMinimum(Calendar.MONTH)),
                        build2SF("MO", (cal.get(Calendar.MONTH))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.MONTH <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("MO", cal.get(Calendar.MONTH))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.DAY_OF_MONTH:
        if (padField == Calendar.DAY_OF_MONTH) {
            if (Calendar.DAY_OF_MONTH < resolutionField) {
                if (cal.get(Calendar.DAY_OF_MONTH) > cal.getMinimum(Calendar.DAY_OF_MONTH)) {
                    part = new ConstantScoreRangeQuery(field,
                            build2SF("DA", cal.getMinimum(Calendar.DAY_OF_MONTH)),
                            build2SF("DA", (cal.get(Calendar.DAY_OF_MONTH) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.DAY_OF_MONTH == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("DA", cal.getMinimum(Calendar.DAY_OF_MONTH)),
                        build2SF("DA", (cal.get(Calendar.DAY_OF_MONTH))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.DAY_OF_MONTH <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("DA", cal.get(Calendar.DAY_OF_MONTH))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.HOUR_OF_DAY:
        if (padField == Calendar.HOUR_OF_DAY) {
            if (Calendar.HOUR_OF_DAY < resolutionField) {
                if (cal.get(Calendar.HOUR_OF_DAY) > cal.getMinimum(Calendar.HOUR_OF_DAY)) {
                    part = new ConstantScoreRangeQuery(field,
                            build2SF("HO", cal.getMinimum(Calendar.HOUR_OF_DAY)),
                            build2SF("HO", (cal.get(Calendar.HOUR_OF_DAY) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }

            } else if (Calendar.HOUR_OF_DAY == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("HO", cal.getMinimum(Calendar.HOUR_OF_DAY)),
                        build2SF("HO", (cal.get(Calendar.HOUR_OF_DAY))), true, true);
                range.add(part, Occur.MUST);

            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.HOUR_OF_DAY <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("HO", cal.get(Calendar.HOUR_OF_DAY))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.MINUTE:
        if (padField == Calendar.MINUTE) {
            if (Calendar.MINUTE < resolutionField) {
                if (cal.get(Calendar.MINUTE) > cal.getMinimum(Calendar.MINUTE)) {
                    part = new ConstantScoreRangeQuery(field, build2SF("MI", cal.getMinimum(Calendar.MINUTE)),
                            build2SF("MI", (cal.get(Calendar.MINUTE) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.MINUTE == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("MI", cal.getMinimum(Calendar.MINUTE)),
                        build2SF("MI", (cal.get(Calendar.MINUTE))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        } else {
            if (Calendar.MINUTE <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("MI", cal.get(Calendar.MINUTE))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.SECOND:
        if (padField == Calendar.SECOND) {
            if (Calendar.SECOND < resolutionField) {
                if (cal.get(Calendar.SECOND) > cal.getMinimum(Calendar.SECOND)) {
                    part = new ConstantScoreRangeQuery(field, build2SF("SE", cal.getMinimum(Calendar.SECOND)),
                            build2SF("SE", (cal.get(Calendar.SECOND) - 1)), true, true);
                    range.add(part, Occur.MUST);
                } else {
                    return null;
                }
            } else if (Calendar.SECOND == resolutionField) {
                part = new ConstantScoreRangeQuery(field, build2SF("SE", cal.getMinimum(Calendar.SECOND)),
                        build2SF("SE", (cal.get(Calendar.SECOND))), true, true);
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
            break;
        }

        else {
            if (Calendar.SECOND <= resolutionField) {
                part = new TermQuery(new Term(field, build2SF("SE", cal.get(Calendar.SECOND))));
                range.add(part, Occur.MUST);
            } else {
                return null;
            }
        }
    case Calendar.MILLISECOND:
        if ((cal.get(Calendar.MILLISECOND) >= cal.getMinimum(Calendar.MILLISECOND))
                && (cal.get(Calendar.MILLISECOND) < cal.getMaximum(Calendar.MILLISECOND))) {
            if (Calendar.MILLISECOND <= resolutionField) {
                part = new ConstantScoreRangeQuery(field, build3SF("MS", cal.getMinimum(Calendar.MILLISECOND)),
                        build3SF("MS", cal.get(Calendar.MILLISECOND)), true, true);
                range.add(part, Occur.MUST);
            } else {
                break;
            }
        }
    default:
    }

    return getNonEmptyBooleanQuery(range);
}