Example usage for org.apache.commons.lang3 Range getMaximum

List of usage examples for org.apache.commons.lang3 Range getMaximum

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Range getMaximum.

Prototype

public T getMaximum() 

Source Link

Document

Gets the maximum value in this range.

Usage

From source file:com.offbynull.portmapper.upnpigd.UpnpIgdDiscovery.java

private static Range<Long> extractRangeIfAvailable(String min, String max, Long absoluteMin, Long absoluteMax) {
    if (!NumberUtils.isNumber(min) || !NumberUtils.isNumber(max)) {
        return null;
    }//from  w  w  w.  j a v  a2s  .  c om

    Range<Long> ret = Range.between(Long.valueOf(min), Long.valueOf(max));

    if (absoluteMin != null && ret.getMinimum() < absoluteMin) {
        return null;
    }

    if (absoluteMax != null && ret.getMaximum() > absoluteMax) {
        return null;
    }

    return ret;
}

From source file:cherry.foundation.bizcal.BizYearManagerImpl.java

@Override
public int getNumberOfDaysOfBizYear(LocalDate dt) {
    Range<LocalDate> range = bizYearByDate(dt).getRight();
    return Days.daysBetween(range.getMinimum(), range.getMaximum()).getDays() + 1;
}

From source file:cherry.foundation.bizcal.BizYearManagerImpl.java

@Override
public int getNumberOfDaysOfBizYear(int bizYear) {
    Range<LocalDate> range = bizYearStrategy.rangeOfBizYear(bizYear);
    return Days.daysBetween(range.getMinimum(), range.getMaximum()).getDays() + 1;
}

From source file:cherry.foundation.bizcal.SimpleBizYearStrategyTest.java

@Test
public void test0101() {
    SimpleBizYearStrategy strategy = new SimpleBizYearStrategy();
    strategy.setYearOfFirstOffset(0);//from   w  w w  .j  a  v a  2 s  . c o m
    strategy.setMonthOfFirst(1);
    strategy.setDayOfFirst(1);
    for (int year = 1900; year < 3000; year++) {
        Range<LocalDate> range = strategy.rangeOfBizYear(year);
        assertEquals(new LocalDate(year, 1, 1), range.getMinimum());
        assertEquals(new LocalDate(year, 12, 31), range.getMaximum());
    }
}

From source file:cherry.foundation.bizcal.SimpleBizYearStrategyTest.java

@Test
public void test0401() {
    SimpleBizYearStrategy strategy = new SimpleBizYearStrategy();
    strategy.setYearOfFirstOffset(0);// w  ww .ja v a2s .  c om
    strategy.setMonthOfFirst(4);
    strategy.setDayOfFirst(1);
    for (int year = 1900; year < 3000; year++) {
        Range<LocalDate> range = strategy.rangeOfBizYear(year);
        assertEquals(new LocalDate(year, 4, 1), range.getMinimum());
        assertEquals(new LocalDate(year + 1, 3, 31), range.getMaximum());
    }
}

From source file:cherry.foundation.bizcal.SimpleBizYearStrategyTest.java

@Test
public void test0901() {
    SimpleBizYearStrategy strategy = new SimpleBizYearStrategy();
    strategy.setYearOfFirstOffset(-1);//from w w  w .j  a  va  2s  .com
    strategy.setMonthOfFirst(9);
    strategy.setDayOfFirst(1);
    for (int year = 1900; year < 3000; year++) {
        Range<LocalDate> range = strategy.rangeOfBizYear(year);
        assertEquals(new LocalDate(year - 1, 9, 1), range.getMinimum());
        assertEquals(new LocalDate(year, 8, 31), range.getMaximum());
    }
}

From source file:de.tor.tribes.util.report.ReportRule.java

public Element toXml(String name) {
    Element rule = new Element(name);
    rule.addContent(new Element("type").setText(type.name()));
    rule.addContent(new Element("targetSet").setText(targetSet));
    Element settings = new Element("settings");

    switch (type) {
    case AGE://from   w ww . j  ava2  s .  c  om
        Long maxAge = (Long) filterComponent;
        settings.setText(maxAge.toString());
        break;
    case ATTACKER_ALLY:
        List<Ally> attAllyList = (List<Ally>) filterComponent;
        for (Ally a : attAllyList) {
            settings.addContent(new Element("ally").setText(Integer.toString(a.getId())));
        }
        break;
    case ATTACKER_TRIBE:
        List<Tribe> attTribeList = (List<Tribe>) filterComponent;
        for (Tribe t : attTribeList) {
            settings.addContent(new Element("tribe").setText(Integer.toString(t.getId())));
        }
        break;
    case COLOR:
        Integer color = (Integer) filterComponent;
        settings.setText(color.toString());
        break;
    case DATE:
        Range<Long> dates = (Range<Long>) filterComponent;
        settings.setText(dates.getMinimum() + "-" + dates.getMaximum());
        break;
    case DEFENDER_ALLY:
        List<Ally> defAllyList = (List<Ally>) filterComponent;
        for (Ally a : defAllyList) {
            settings.addContent(new Element("ally").setText(Integer.toString(a.getId())));
        }
        break;
    case DEFENDER_TRIBE:
        List<Tribe> defTribeList = (List<Tribe>) filterComponent;
        for (Tribe t : defTribeList) {
            settings.addContent(new Element("tribe").setText(Integer.toString(t.getId())));
        }
        break;
    case CATA:
    case CONQUERED:
    case FAKE:
    case FARM:
    case OFF:
    case WALL:
        break;
    default:
        throw new IllegalArgumentException("wrong type");
    }

    rule.addContent(settings);
    return rule;
}

From source file:de.tor.tribes.util.algo.types.TimeFrame.java

/**
 * Check if a movement with the provided runtime is possible for this
 * AttackFitter//from   ww w  .j ava  2 s  .  c o m
 *
 * @param pRuntime Runtime to check
 * @param pVillage Village for which the runtime is valid
 * @return boolean TRUE=Runtime might be fitted if not all send times are
 * already used
 */
public boolean isMovementPossible(long pRuntime) {
    if (startRanges == null) {
        startRanges = startTimespansToRanges();
    }
    if (arriveRanges == null) {
        arriveRanges = arriveTimespansToRanges();
    }

    for (Range<Long> currentStartRange : startRanges) {
        Range<Long> arriveRangeForStartRange = Range.between(currentStartRange.getMinimum() + pRuntime,
                currentStartRange.getMaximum() + pRuntime);
        for (Range<Long> currentArriveRange : arriveRanges) {
            if (currentArriveRange.isOverlappedBy(arriveRangeForStartRange)) {
                //movement with 'pRuntime' starting in 'currentStartRange' will arrive withing 'currentArriveRange'
                return true;
            }
        }
    }
    //no overlapping range was found
    return false;
}

From source file:de.tor.tribes.util.report.ReportRule.java

public ReportRule(RuleType pType, Object pFilterComponent, String pTargetSet) throws IllegalArgumentException {
    try {//from  ww w .  j av a 2  s. c o m
        type = pType;
        filterComponent = pFilterComponent;
        targetSet = pTargetSet;

        //check arguments and throw Exception if illigal
        switch (type) {
        case AGE:
            Long maxAge = (Long) pFilterComponent;
            if (maxAge < 0)
                throw new IllegalArgumentException("Age < 0");
            break;
        case ATTACKER_ALLY:
            List<Ally> attAllyList = (List<Ally>) pFilterComponent;
            for (int i = attAllyList.size() - 1; i >= 0; i--) {
                if (attAllyList.get(i) == null) {
                    attAllyList.remove(i);
                    logger.debug("removed entry {}", i);
                }
            }
            if (attAllyList.isEmpty())
                throw new IllegalArgumentException("List empty!");
            break;
        case ATTACKER_TRIBE:
            List<Tribe> attTribeList = (List<Tribe>) pFilterComponent;
            for (int i = attTribeList.size() - 1; i >= 0; i--) {
                if (attTribeList.get(i) == null) {
                    attTribeList.remove(i);
                    logger.debug("removed entry {}", i);
                }
            }
            if (attTribeList.isEmpty())
                throw new IllegalArgumentException("List empty!");
            break;
        case COLOR:
            if ((((Integer) pFilterComponent) & 0x1F) == 0)
                throw new IllegalArgumentException("No color");
            break;
        case DATE:
            Range<Long> dates = (Range<Long>) pFilterComponent;
            if (dates.getMinimum().equals(dates.getMaximum()))
                throw new IllegalArgumentException("Empty Range");
            break;
        case DEFENDER_ALLY:
            List<Ally> defAllyList = (List<Ally>) pFilterComponent;
            for (int i = defAllyList.size() - 1; i >= 0; i--) {
                if (defAllyList.get(i) == null) {
                    defAllyList.remove(i);
                    logger.debug("removed entry {}", i);
                }
            }
            if (defAllyList.isEmpty())
                throw new IllegalArgumentException("List empty!");
            break;
        case DEFENDER_TRIBE:
            List<Tribe> defTribeList = (List<Tribe>) pFilterComponent;
            for (int i = defTribeList.size() - 1; i >= 0; i--) {
                if (defTribeList.get(i) == null) {
                    defTribeList.remove(i);
                    logger.debug("removed entry {}", i);
                }
            }
            if (defTribeList.isEmpty())
                throw new IllegalArgumentException("List empty!");
            break;
        case CATA:
        case CONQUERED:
        case FAKE:
        case FARM:
        case OFF:
        case WALL:
            filterComponent = null;
            break;
        default:
            throw new IllegalArgumentException("wrong type");
        }
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:forge.deck.DeckFormat.java

public String getDeckConformanceProblem(Deck deck) {
    if (deck == null) {
        return "is not selected";
    }/*  ww w.  j a va2  s. com*/

    int deckSize = deck.getMain().countAll();

    int min = getMainRange().getMinimum();
    int max = getMainRange().getMaximum();

    // TODO "Your minimum deck size is reduced by five."
    // Adjust minimum base on number of Advantageous Proclamation or similar cards

    if (deckSize < min) {
        return String.format("should have at least %d cards", min);
    }

    if (deckSize > max) {
        return String.format("should have no more than %d cards", max);
    }

    if (hasCommander()) { //Must contain exactly 1 legendary Commander and a sideboard of 10 or zero cards.
        final CardPool cmd = deck.get(DeckSection.Commander);
        if (cmd == null || cmd.isEmpty()) {
            return "is missing a commander";
        }
        if (!isLegalCommander(cmd.get(0).getRules())) {
            return "has an illegal commander";
        }

        final ColorSet cmdCI = cmd.get(0).getRules().getColorIdentity();
        final List<PaperCard> erroneousCI = new ArrayList<PaperCard>();

        for (final Entry<PaperCard, Integer> cp : deck.get(DeckSection.Main)) {
            if (!cp.getKey().getRules().getColorIdentity().hasNoColorsExcept(cmdCI.getColor())) {
                erroneousCI.add(cp.getKey());
            }
        }
        if (deck.has(DeckSection.Sideboard)) {
            for (final Entry<PaperCard, Integer> cp : deck.get(DeckSection.Sideboard)) {
                if (!cp.getKey().getRules().getColorIdentity().hasNoColorsExcept(cmdCI.getColor())) {
                    erroneousCI.add(cp.getKey());
                }
            }
        }

        if (erroneousCI.size() > 0) {
            StringBuilder sb = new StringBuilder(
                    "contains one or more cards that do not match the commanders color identity:");

            for (PaperCard cp : erroneousCI) {
                sb.append("\n").append(cp.getName());
            }

            return sb.toString();
        }
    }

    if (cardPoolFilter != null) {
        final List<PaperCard> erroneousCI = new ArrayList<PaperCard>();
        for (final Entry<PaperCard, Integer> cp : deck.getAllCardsInASinglePool()) {
            if (!cardPoolFilter.apply(cp.getKey().getRules())) {
                erroneousCI.add(cp.getKey());
            }
        }
        if (erroneousCI.size() > 0) {
            final StringBuilder sb = new StringBuilder("contains the following illegal cards:\n");

            for (final PaperCard cp : erroneousCI) {
                sb.append("\n").append(cp.getName());
            }

            return sb.toString();
        }
    }

    final int maxCopies = getMaxCardCopies();
    if (maxCopies < Integer.MAX_VALUE) {
        //Must contain no more than 4 of the same card
        //shared among the main deck and sideboard, except
        //basic lands, Shadowborn Apostle and Relentless Rats

        final CardPool allCards = deck.getAllCardsInASinglePool(hasCommander());
        final ImmutableSet<String> limitExceptions = ImmutableSet.of("Relentless Rats", "Shadowborn Apostle");

        // should group all cards by name, so that different editions of same card are really counted as the same card
        for (final Entry<String, Integer> cp : Aggregates.groupSumBy(allCards, PaperCard.FN_GET_NAME)) {
            final IPaperCard simpleCard = StaticData.instance().getCommonCards().getCard(cp.getKey());
            if (simpleCard == null) {
                return String.format("contains the nonexisting card %s", cp.getKey());
            }

            final boolean canHaveMultiple = simpleCard.getRules().getType().isBasicLand()
                    || limitExceptions.contains(cp.getKey());
            if (!canHaveMultiple && cp.getValue() > maxCopies) {
                return String.format("must not contain more than %d copies of the card %s", maxCopies,
                        cp.getKey());
            }
        }
    }

    // The sideboard must contain either 0 or 15 cards
    int sideboardSize = deck.has(DeckSection.Sideboard) ? deck.get(DeckSection.Sideboard).countAll() : 0;
    Range<Integer> sbRange = getSideRange();
    if (sbRange != null && sideboardSize > 0 && !sbRange.contains(sideboardSize)) {
        return sbRange.getMinimum() == sbRange.getMaximum()
                ? String.format("must have a sideboard of %d cards or no sideboard at all",
                        sbRange.getMaximum())
                : String.format("must have a sideboard of %d to %d cards or no sideboard at all",
                        sbRange.getMinimum(), sbRange.getMaximum());
    }

    return null;
}