while (true) {
                addToBooster(booster, cards);
                int check = addMissingPartner(booster, partnerAllowed, -1, 1);
                if (check == 1) {
                    break;
                }
                if (check == 2) {
                    partnerAllowed = false;
                    break;
                }
            }

package mage.sets;

import mage.abilities.Ability;
import mage.abilities.keyword.PartnerWithAbility;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.Rarity;
import mage.constants.SetType;
import java.util.ArrayList;
import java.util.List;

/**
 * @author TheElk801
 */
public final class Battlebond extends ExpansionSet {

    private static final Battlebond instance = new Battlebond();

    public static Battlebond getInstance() {
        return instance;
    }

    private Battlebond() {
        super("Battlebond", "BBD", ExpansionSet.buildDate(2018, 6, 8), SetType.SUPPLEMENTAL);
        this.blockName = "Battlebond";
        this.hasBasicLands = true;
        this.hasBoosters = true;
        this.numBoosterLands = 1;
        this.numBoosterCommon = 10;
        this.numBoosterUncommon = 3;
        this.numBoosterRare = 1;
        this.ratioBoosterMythic = 8;
        // Don't use the 2 foil mystics copies because it would influence a random ratio
        this.maxCardNumberInBooster = 254;
        cards.add(new SetCardInfo("Aim High", 189, Rarity.UNCOMMON, mage.cards.a.AimHigh.class));
        cards.add(new SetCardInfo("Angel of Retribution", 86, Rarity.UNCOMMON, mage.cards.a.AngelOfRetribution.class));
        cards.add(new SetCardInfo("Angelic Chorus", 87, Rarity.RARE, mage.cards.a.AngelicChorus.class));
        cards.add(new SetCardInfo("Angelic Gift", 88, Rarity.COMMON, mage.cards.a.AngelicGift.class));
        cards.add(new SetCardInfo("Apocalypse Hydra", 217, Rarity.RARE, mage.cards.a.ApocalypseHydra.class));
        cards.add(new SetCardInfo("Arcane Artisan", 33, Rarity.MYTHIC, mage.cards.a.ArcaneArtisan.class));
        cards.add(new SetCardInfo("Archfiend of Despair", 44, Rarity.MYTHIC, mage.cards.a.ArchfiendOfDespair.class));
        cards.add(new SetCardInfo("Archon of Valor's Reach", 74, Rarity.RARE, mage.cards.a.ArchonOfValorsReach.class));
        cards.add(new SetCardInfo("Arena Rector", 23, Rarity.MYTHIC, mage.cards.a.ArenaRector.class));
        cards.add(new SetCardInfo("Assassin's Strike", 138, Rarity.UNCOMMON, mage.cards.a.AssassinsStrike.class));
        cards.add(new SetCardInfo("Assassinate", 139, Rarity.COMMON, mage.cards.a.Assassinate.class));
        cards.add(new SetCardInfo("Auger Spree", 218, Rarity.COMMON, mage.cards.a.AugerSpree.class));
        cards.add(new SetCardInfo("Aurora Champion", 24, Rarity.COMMON, mage.cards.a.AuroraChampion.class));
        cards.add(new SetCardInfo("Azra Bladeseeker", 55, Rarity.COMMON, mage.cards.a.AzraBladeseeker.class));
        cards.add(new SetCardInfo("Azra Oddsmaker", 75, Rarity.UNCOMMON, mage.cards.a.AzraOddsmaker.class));
        cards.add(new SetCardInfo("Bathe in Dragonfire", 164, Rarity.COMMON, mage.cards.b.BatheInDragonfire.class));
        cards.add(new SetCardInfo("Battle Mastery", 89, Rarity.UNCOMMON, mage.cards.b.BattleMastery.class));
        cards.add(new SetCardInfo("Battle Rampart", 165, Rarity.COMMON, mage.cards.b.BattleRampart.class));
        cards.add(new SetCardInfo("Battle-Rattle Shaman", 166, Rarity.UNCOMMON, mage.cards.b.BattleRattleShaman.class));
        cards.add(new SetCardInfo("Beast Within", 190, Rarity.UNCOMMON, mage.cards.b.BeastWithin.class));
        cards.add(new SetCardInfo("Benthic Giant", 113, Rarity.COMMON, mage.cards.b.BenthicGiant.class));
        cards.add(new SetCardInfo("Blaring Captain", 14, Rarity.UNCOMMON, mage.cards.b.BlaringCaptain.class));
        cards.add(new SetCardInfo("Blaring Recruiter", 13, Rarity.UNCOMMON, mage.cards.b.BlaringRecruiter.class));
        cards.add(new SetCardInfo("Blaze", 167, Rarity.UNCOMMON, mage.cards.b.Blaze.class));
        cards.add(new SetCardInfo("Blood Feud", 168, Rarity.UNCOMMON, mage.cards.b.BloodFeud.class));
        cards.add(new SetCardInfo("Bloodborn Scoundrels", 45, Rarity.COMMON, mage.cards.b.BloodbornScoundrels.class));
        cards.add(new SetCardInfo("Boldwyr Intimidator", 169, Rarity.UNCOMMON, mage.cards.b.BoldwyrIntimidator.class));
        cards.add(new SetCardInfo("Bonus Round", 56, Rarity.RARE, mage.cards.b.BonusRound.class));
        cards.add(new SetCardInfo("Borderland Marauder", 170, Rarity.COMMON, mage.cards.b.BorderlandMarauder.class));
        cards.add(new SetCardInfo("Bountiful Promenade", 81, Rarity.RARE, mage.cards.b.BountifulPromenade.class));
        cards.add(new SetCardInfo("Bramble Sovereign", 65, Rarity.MYTHIC, mage.cards.b.BrambleSovereign.class));
        cards.add(new SetCardInfo("Brightling", 25, Rarity.MYTHIC, mage.cards.b.Brightling.class));
        cards.add(new SetCardInfo("Bring Down", 26, Rarity.UNCOMMON, mage.cards.b.BringDown.class));
        cards.add(new SetCardInfo("Bull-Rush Bruiser", 57, Rarity.COMMON, mage.cards.b.BullRushBruiser.class));
        cards.add(new SetCardInfo("Call to Heel", 114, Rarity.COMMON, mage.cards.c.CallToHeel.class));
        cards.add(new SetCardInfo("Canopy Spider", 191, Rarity.COMMON, mage.cards.c.CanopySpider.class));
        cards.add(new SetCardInfo("Centaur Healer", 219, Rarity.COMMON, mage.cards.c.CentaurHealer.class));
        cards.add(new SetCardInfo("Chain Lightning", 171, Rarity.UNCOMMON, mage.cards.c.ChainLightning.class));
        cards.add(new SetCardInfo("Chakram Retriever", 15, Rarity.UNCOMMON, mage.cards.c.ChakramRetriever.class));
        cards.add(new SetCardInfo("Chakram Slinger", 16, Rarity.UNCOMMON, mage.cards.c.ChakramSlinger.class));
        cards.add(new SetCardInfo("Champion of Arashin", 90, Rarity.COMMON, mage.cards.c.ChampionOfArashin.class));
        cards.add(new SetCardInfo("Charging Binox", 66, Rarity.COMMON, mage.cards.c.ChargingBinox.class));
        cards.add(new SetCardInfo("Charging Rhino", 192, Rarity.COMMON, mage.cards.c.ChargingRhino.class));
        cards.add(new SetCardInfo("Cheering Fanatic", 58, Rarity.UNCOMMON, mage.cards.c.CheeringFanatic.class));
        cards.add(new SetCardInfo("Claustrophobia", 115, Rarity.COMMON, mage.cards.c.Claustrophobia.class));
        cards.add(new SetCardInfo("Combo Attack", 67, Rarity.COMMON, mage.cards.c.ComboAttack.class));
        cards.add(new SetCardInfo("Consulate Skygate", 232, Rarity.COMMON, mage.cards.c.ConsulateSkygate.class));
        cards.add(new SetCardInfo("Coralhelm Guide", 116, Rarity.COMMON, mage.cards.c.CoralhelmGuide.class));
        cards.add(new SetCardInfo("Cowl Prowler", 193, Rarity.COMMON, mage.cards.c.CowlProwler.class));
        cards.add(new SetCardInfo("Culling Dais", 233, Rarity.UNCOMMON, mage.cards.c.CullingDais.class));
        cards.add(new SetCardInfo("Daggerback Basilisk", 194, Rarity.COMMON, mage.cards.d.DaggerbackBasilisk.class));
        cards.add(new SetCardInfo("Daggerdrome Imp", 140, Rarity.COMMON, mage.cards.d.DaggerdromeImp.class));
        cards.add(new SetCardInfo("Decorated Champion", 69, Rarity.UNCOMMON, mage.cards.d.DecoratedChampion.class));
        cards.add(new SetCardInfo("Diabolic Intent", 141, Rarity.RARE, mage.cards.d.DiabolicIntent.class));
        cards.add(new SetCardInfo("Dinrova Horror", 220, Rarity.UNCOMMON, mage.cards.d.DinrovaHorror.class));
        cards.add(new SetCardInfo("Doomed Dissenter", 142, Rarity.COMMON, mage.cards.d.DoomedDissenter.class));
        cards.add(new SetCardInfo("Doomed Traveler", 91, Rarity.COMMON, mage.cards.d.DoomedTraveler.class));
        cards.add(new SetCardInfo("Doubling Season", 195, Rarity.MYTHIC, mage.cards.d.DoublingSeason.class));
        cards.add(new SetCardInfo("Dragon Breath", 172, Rarity.UNCOMMON, mage.cards.d.DragonBreath.class));
        cards.add(new SetCardInfo("Dragon Hatchling", 173, Rarity.COMMON, mage.cards.d.DragonHatchling.class));
        cards.add(new SetCardInfo("Dwarven Lightsmith", 27, Rarity.COMMON, mage.cards.d.DwarvenLightsmith.class));
        cards.add(new SetCardInfo("Eager Construct", 234, Rarity.COMMON, mage.cards.e.EagerConstruct.class));
        cards.add(new SetCardInfo("Earth Elemental", 174, Rarity.COMMON, mage.cards.e.EarthElemental.class));
        cards.add(new SetCardInfo("Elvish Visionary", 196, Rarity.COMMON, mage.cards.e.ElvishVisionary.class));
        cards.add(new SetCardInfo("Ember Beast", 175, Rarity.COMMON, mage.cards.e.EmberBeast.class));
        cards.add(new SetCardInfo("Enduring Scalelord", 221, Rarity.UNCOMMON, mage.cards.e.EnduringScalelord.class));
        cards.add(new SetCardInfo("Enthralling Victor", 176, Rarity.UNCOMMON, mage.cards.e.EnthrallingVictor.class));
        cards.add(new SetCardInfo("Evil Twin", 222, Rarity.RARE, mage.cards.e.EvilTwin.class));
        cards.add(new SetCardInfo("Expedite", 177, Rarity.COMMON, mage.cards.e.Expedite.class));
        cards.add(new SetCardInfo("Expedition Raptor", 92, Rarity.COMMON, mage.cards.e.ExpeditionRaptor.class));
        cards.add(new SetCardInfo("Eyeblight Assassin", 143, Rarity.COMMON, mage.cards.e.EyeblightAssassin.class));
        cards.add(new SetCardInfo("Fan Favorite", 46, Rarity.COMMON, mage.cards.f.FanFavorite.class));
        cards.add(new SetCardInfo("Feral Hydra", 197, Rarity.UNCOMMON, mage.cards.f.FeralHydra.class));
        cards.add(new SetCardInfo("Fertile Ground", 198, Rarity.COMMON, mage.cards.f.FertileGround.class));
        cards.add(new SetCardInfo("Fertilid", 199, Rarity.UNCOMMON, mage.cards.f.Fertilid.class));
        cards.add(new SetCardInfo("Fill with Fright", 144, Rarity.COMMON, mage.cards.f.FillWithFright.class));
        cards.add(new SetCardInfo("Flamewave Invoker", 178, Rarity.UNCOMMON, mage.cards.f.FlamewaveInvoker.class));
        cards.add(new SetCardInfo("Fog Bank", 117, Rarity.UNCOMMON, mage.cards.f.FogBank.class));
        cards.add(new SetCardInfo("Forest", 254, Rarity.LAND, mage.cards.basiclands.Forest.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Frost Lynx", 118, Rarity.COMMON, mage.cards.f.FrostLynx.class));
        cards.add(new SetCardInfo("Fumble", 34, Rarity.UNCOMMON, mage.cards.f.Fumble.class));
        cards.add(new SetCardInfo("Game Plan", 35, Rarity.RARE, mage.cards.g.GamePlan.class));
        cards.add(new SetCardInfo("Gang Up", 47, Rarity.UNCOMMON, mage.cards.g.GangUp.class));
        cards.add(new SetCardInfo("Generous Patron", 70, Rarity.RARE, mage.cards.g.GenerousPatron.class));
        cards.add(new SetCardInfo("Genesis Chamber", 235, Rarity.UNCOMMON, mage.cards.g.GenesisChamber.class));
        cards.add(new SetCardInfo("Giant Growth", 200, Rarity.COMMON, mage.cards.g.GiantGrowth.class));
        cards.add(new SetCardInfo("Goblin Razerunners", 179, Rarity.RARE, mage.cards.g.GoblinRazerunners.class));
        cards.add(new SetCardInfo("Gold-Forged Sentinel", 236, Rarity.UNCOMMON, mage.cards.g.GoldForgedSentinel.class));
        cards.add(new SetCardInfo("Gorm the Great", 8, Rarity.RARE, mage.cards.g.GormTheGreat.class));
        cards.add(new SetCardInfo("Greater Good", 201, Rarity.RARE, mage.cards.g.GreaterGood.class));
        cards.add(new SetCardInfo("Grotesque Mutation", 145, Rarity.COMMON, mage.cards.g.GrotesqueMutation.class));
        cards.add(new SetCardInfo("Grothama, All-Devouring", 71, Rarity.MYTHIC, mage.cards.g.GrothamaAllDevouring.class));
        cards.add(new SetCardInfo("Gwafa Hazid, Profiteer", 223, Rarity.RARE, mage.cards.g.GwafaHazidProfiteer.class));
        cards.add(new SetCardInfo("Hand of Silumgar", 146, Rarity.COMMON, mage.cards.h.HandOfSilumgar.class));
        cards.add(new SetCardInfo("Hexplate Golem", 237, Rarity.COMMON, mage.cards.h.HexplateGolem.class));
        cards.add(new SetCardInfo("Huddle Up", 36, Rarity.COMMON, mage.cards.h.HuddleUp.class));
        cards.add(new SetCardInfo("Hunted Wumpus", 202, Rarity.UNCOMMON, mage.cards.h.HuntedWumpus.class));
        cards.add(new SetCardInfo("Impetuous Protege", 19, Rarity.UNCOMMON, mage.cards.i.ImpetuousProtege.class));
        cards.add(new SetCardInfo("Impulse", 119, Rarity.COMMON, mage.cards.i.Impulse.class));
        cards.add(new SetCardInfo("Inner Demon", 48, Rarity.UNCOMMON, mage.cards.i.InnerDemon.class));
        cards.add(new SetCardInfo("Island", 251, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Jelenn Sphinx", 224, Rarity.UNCOMMON, mage.cards.j.JelennSphinx.class));
        cards.add(new SetCardInfo("Jubilant Mascot", 28, Rarity.UNCOMMON, mage.cards.j.JubilantMascot.class));
        cards.add(new SetCardInfo("Juggernaut", 238, Rarity.UNCOMMON, mage.cards.j.Juggernaut.class));
        cards.add(new SetCardInfo("Jungle Wayfinder", 72, Rarity.COMMON, mage.cards.j.JungleWayfinder.class));
        cards.add(new SetCardInfo("Karametra's Favor", 203, Rarity.UNCOMMON, mage.cards.k.KarametrasFavor.class));
        cards.add(new SetCardInfo("Khorvath Brightflame", 9, Rarity.RARE, mage.cards.k.KhorvathBrightflame.class));
        cards.add(new SetCardInfo("Khorvath's Fury", 59, Rarity.RARE, mage.cards.k.KhorvathsFury.class));
        cards.add(new SetCardInfo("Kiss of the Amesha", 225, Rarity.UNCOMMON, mage.cards.k.KissOfTheAmesha.class));
        cards.add(new SetCardInfo("Kitesail Corsair", 120, Rarity.COMMON, mage.cards.k.KitesailCorsair.class));
        cards.add(new SetCardInfo("Kor Spiritdancer", 93, Rarity.RARE, mage.cards.k.KorSpiritdancer.class));
        cards.add(new SetCardInfo("Kraken Hatchling", 121, Rarity.COMMON, mage.cards.k.KrakenHatchling.class));
        cards.add(new SetCardInfo("Kraul Warrior", 204, Rarity.COMMON, mage.cards.k.KraulWarrior.class));
        cards.add(new SetCardInfo("Krav, the Unredeemed", 4, Rarity.RARE, mage.cards.k.KravTheUnredeemed.class));
        cards.add(new SetCardInfo("Land Tax", 94, Rarity.MYTHIC, mage.cards.l.LandTax.class));
        cards.add(new SetCardInfo("Last Gasp", 147, Rarity.COMMON, mage.cards.l.LastGasp.class));
        cards.add(new SetCardInfo("Last One Standing", 76, Rarity.RARE, mage.cards.l.LastOneStanding.class));
        cards.add(new SetCardInfo("Lava-Field Overlord", 60, Rarity.UNCOMMON, mage.cards.l.LavaFieldOverlord.class));
        cards.add(new SetCardInfo("Lead by Example", 205, Rarity.COMMON, mage.cards.l.LeadByExample.class));
        cards.add(new SetCardInfo("Ley Weaver", 21, Rarity.UNCOMMON, mage.cards.l.LeyWeaver.class));
        cards.add(new SetCardInfo("Lightning Talons", 180, Rarity.COMMON, mage.cards.l.LightningTalons.class));
        cards.add(new SetCardInfo("Lightwalker", 95, Rarity.COMMON, mage.cards.l.Lightwalker.class));
        cards.add(new SetCardInfo("Liturgy of Blood", 148, Rarity.COMMON, mage.cards.l.LiturgyOfBlood.class));
        cards.add(new SetCardInfo("Long Road Home", 96, Rarity.UNCOMMON, mage.cards.l.LongRoadHome.class));
        cards.add(new SetCardInfo("Lore Weaver", 22, Rarity.UNCOMMON, mage.cards.l.LoreWeaver.class));
        cards.add(new SetCardInfo("Loyal Pegasus", 97, Rarity.UNCOMMON, mage.cards.l.LoyalPegasus.class));
        cards.add(new SetCardInfo("Luxury Suite", 82, Rarity.RARE, mage.cards.l.LuxurySuite.class));
        cards.add(new SetCardInfo("Magma Hellion", 61, Rarity.COMMON, mage.cards.m.MagmaHellion.class));
        cards.add(new SetCardInfo("Magmatic Force", 181, Rarity.RARE, mage.cards.m.MagmaticForce.class));
        cards.add(new SetCardInfo("Magus of the Candelabra", 206, Rarity.RARE, mage.cards.m.MagusOfTheCandelabra.class));
        cards.add(new SetCardInfo("Mangara of Corondor", 98, Rarity.RARE, mage.cards.m.MangaraOfCorondor.class));
        cards.add(new SetCardInfo("Midnight Guard", 99, Rarity.COMMON, mage.cards.m.MidnightGuard.class));
        cards.add(new SetCardInfo("Millennial Gargoyle", 239, Rarity.COMMON, mage.cards.m.MillennialGargoyle.class));
        cards.add(new SetCardInfo("Mind's Eye", 240, Rarity.RARE, mage.cards.m.MindsEye.class));
        cards.add(new SetCardInfo("Mindblade Render", 49, Rarity.RARE, mage.cards.m.MindbladeRender.class));
        cards.add(new SetCardInfo("Morbid Curiosity", 149, Rarity.UNCOMMON, mage.cards.m.MorbidCuriosity.class));
        cards.add(new SetCardInfo("Morphic Pool", 83, Rarity.RARE, mage.cards.m.MorphicPool.class));
        cards.add(new SetCardInfo("Mountain", 253, Rarity.LAND, mage.cards.basiclands.Mountain.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Mycosynth Lattice", 241, Rarity.MYTHIC, mage.cards.m.MycosynthLattice.class));
        cards.add(new SetCardInfo("Mystic Confluence", 122, Rarity.RARE, mage.cards.m.MysticConfluence.class));
        cards.add(new SetCardInfo("Najeela, the Blade-Blossom", 62, Rarity.MYTHIC, mage.cards.n.NajeelaTheBladeBlossom.class));
        cards.add(new SetCardInfo("Negate", 123, Rarity.COMMON, mage.cards.n.Negate.class));
        cards.add(new SetCardInfo("Night Market Guard", 242, Rarity.COMMON, mage.cards.n.NightMarketGuard.class));
        cards.add(new SetCardInfo("Nimbus Champion", 37, Rarity.UNCOMMON, mage.cards.n.NimbusChampion.class));
        cards.add(new SetCardInfo("Nimbus of the Isles", 124, Rarity.COMMON, mage.cards.n.NimbusOfTheIsles.class));
        cards.add(new SetCardInfo("Nirkana Revenant", 150, Rarity.MYTHIC, mage.cards.n.NirkanaRevenant.class));
        cards.add(new SetCardInfo("Noosegraf Mob", 151, Rarity.RARE, mage.cards.n.NoosegrafMob.class));
        cards.add(new SetCardInfo("Noxious Dragon", 152, Rarity.UNCOMMON, mage.cards.n.NoxiousDragon.class));
        cards.add(new SetCardInfo("Nyxathid", 153, Rarity.RARE, mage.cards.n.Nyxathid.class));
        cards.add(new SetCardInfo("Okaun, Eye of Chaos", 6, Rarity.RARE, mage.cards.o.OkaunEyeOfChaos.class));
        cards.add(new SetCardInfo("Omenspeaker", 125, Rarity.COMMON, mage.cards.o.Omenspeaker.class));
        cards.add(new SetCardInfo("Opportunity", 126, Rarity.UNCOMMON, mage.cards.o.Opportunity.class));
        cards.add(new SetCardInfo("Oracle's Insight", 127, Rarity.UNCOMMON, mage.cards.o.OraclesInsight.class));
        cards.add(new SetCardInfo("Oreskos Explorer", 100, Rarity.UNCOMMON, mage.cards.o.OreskosExplorer.class));
        cards.add(new SetCardInfo("Out of Bounds", 38, Rarity.UNCOMMON, mage.cards.o.OutOfBounds.class));
        cards.add(new SetCardInfo("Pacifism", 101, Rarity.COMMON, mage.cards.p.Pacifism.class));
        cards.add(new SetCardInfo("Painful Lesson", 154, Rarity.COMMON, mage.cards.p.PainfulLesson.class));
        cards.add(new SetCardInfo("Pathmaker Initiate", 182, Rarity.COMMON, mage.cards.p.PathmakerInitiate.class));
        cards.add(new SetCardInfo("Peace Strider", 243, Rarity.COMMON, mage.cards.p.PeaceStrider.class));
        cards.add(new SetCardInfo("Peregrine Drake", 128, Rarity.UNCOMMON, mage.cards.p.PeregrineDrake.class));
        cards.add(new SetCardInfo("Phantom Warrior", 129, Rarity.UNCOMMON, mage.cards.p.PhantomWarrior.class));
        cards.add(new SetCardInfo("Pierce Strider", 244, Rarity.COMMON, mage.cards.p.PierceStrider.class));
        cards.add(new SetCardInfo("Pir's Whim", 73, Rarity.RARE, mage.cards.p.PirsWhim.class));
        cards.add(new SetCardInfo("Pir, Imaginative Rascal", 11, Rarity.RARE, mage.cards.p.PirImaginativeRascal.class));
        cards.add(new SetCardInfo("Plains", 250, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Plated Crusher", 207, Rarity.UNCOMMON, mage.cards.p.PlatedCrusher.class));
        cards.add(new SetCardInfo("Play of the Game", 29, Rarity.RARE, mage.cards.p.PlayOfTheGame.class));
        cards.add(new SetCardInfo("Prakhata Club Security", 155, Rarity.COMMON, mage.cards.p.PrakhataClubSecurity.class));
        cards.add(new SetCardInfo("Primal Huntbeast", 208, Rarity.COMMON, mage.cards.p.PrimalHuntbeast.class));
        cards.add(new SetCardInfo("Proud Mentor", 20, Rarity.UNCOMMON, mage.cards.p.ProudMentor.class));
        cards.add(new SetCardInfo("Pulse of Murasa", 209, Rarity.UNCOMMON, mage.cards.p.PulseOfMurasa.class));
        cards.add(new SetCardInfo("Quest for the Gravelord", 156, Rarity.UNCOMMON, mage.cards.q.QuestForTheGravelord.class));
        cards.add(new SetCardInfo("Raptor Companion", 102, Rarity.COMMON, mage.cards.r.RaptorCompanion.class));
        cards.add(new SetCardInfo("Rebuke", 103, Rarity.COMMON, mage.cards.r.Rebuke.class));
        cards.add(new SetCardInfo("Reckless Reveler", 183, Rarity.COMMON, mage.cards.r.RecklessReveler.class));
        cards.add(new SetCardInfo("Reckless Scholar", 130, Rarity.UNCOMMON, mage.cards.r.RecklessScholar.class));
        cards.add(new SetCardInfo("Regna's Sanction", 30, Rarity.RARE, mage.cards.r.RegnasSanction.class));
        cards.add(new SetCardInfo("Regna, the Redeemer", 3, Rarity.RARE, mage.cards.r.RegnaTheRedeemer.class));
        cards.add(new SetCardInfo("Relentless Hunter", 226, Rarity.UNCOMMON, mage.cards.r.RelentlessHunter.class));
        cards.add(new SetCardInfo("Return to the Earth", 210, Rarity.COMMON, mage.cards.r.ReturnToTheEarth.class));
        cards.add(new SetCardInfo("Rhox Brute", 227, Rarity.COMMON, mage.cards.r.RhoxBrute.class));
        cards.add(new SetCardInfo("Riptide Crab", 228, Rarity.COMMON, mage.cards.r.RiptideCrab.class));
        cards.add(new SetCardInfo("Rotfeaster Maggot", 157, Rarity.COMMON, mage.cards.r.RotfeasterMaggot.class));
        cards.add(new SetCardInfo("Rowan Kenrith", 2, Rarity.MYTHIC, mage.cards.r.RowanKenrith.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Rowan Kenrith", 256, Rarity.MYTHIC, mage.cards.r.RowanKenrith.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Royal Trooper", 104, Rarity.COMMON, mage.cards.r.RoyalTrooper.class));
        cards.add(new SetCardInfo("Rushblade Commander", 77, Rarity.UNCOMMON, mage.cards.r.RushbladeCommander.class));
        cards.add(new SetCardInfo("Saddleback Lagac", 211, Rarity.COMMON, mage.cards.s.SaddlebackLagac.class));
        cards.add(new SetCardInfo("Saltwater Stalwart", 39, Rarity.COMMON, mage.cards.s.SaltwaterStalwart.class));
        cards.add(new SetCardInfo("Savage Ventmaw", 229, Rarity.UNCOMMON, mage.cards.s.SavageVentmaw.class));
        cards.add(new SetCardInfo("Screeching Buzzard", 158, Rarity.COMMON, mage.cards.s.ScreechingBuzzard.class));
        cards.add(new SetCardInfo("Sea of Clouds", 84, Rarity.RARE, mage.cards.s.SeaOfClouds.class));
        cards.add(new SetCardInfo("Seedborn Muse", 212, Rarity.RARE, mage.cards.s.SeedbornMuse.class));
        cards.add(new SetCardInfo("Seer's Lantern", 245, Rarity.COMMON, mage.cards.s.SeersLantern.class));
        cards.add(new SetCardInfo("Sentinel Tower", 79, Rarity.RARE, mage.cards.s.SentinelTower.class));
        cards.add(new SetCardInfo("Shambling Ghoul", 159, Rarity.COMMON, mage.cards.s.ShamblingGhoul.class));
        cards.add(new SetCardInfo("Shock", 184, Rarity.COMMON, mage.cards.s.Shock.class));
        cards.add(new SetCardInfo("Shoulder to Shoulder", 105, Rarity.COMMON, mage.cards.s.ShoulderToShoulder.class));
        cards.add(new SetCardInfo("Sickle Dancer", 50, Rarity.COMMON, mage.cards.s.SickleDancer.class));
        cards.add(new SetCardInfo("Silverchase Fox", 106, Rarity.COMMON, mage.cards.s.SilverchaseFox.class));
        cards.add(new SetCardInfo("Skyshroud Claim", 213, Rarity.COMMON, mage.cards.s.SkyshroudClaim.class));
        cards.add(new SetCardInfo("Skystreamer", 31, Rarity.COMMON, mage.cards.s.Skystreamer.class));
        cards.add(new SetCardInfo("Slum Reaper", 160, Rarity.UNCOMMON, mage.cards.s.SlumReaper.class));
        cards.add(new SetCardInfo("Soaring Show-Off", 40, Rarity.COMMON, mage.cards.s.SoaringShowOff.class));
        cards.add(new SetCardInfo("Solemn Offering", 107, Rarity.UNCOMMON, mage.cards.s.SolemnOffering.class));
        cards.add(new SetCardInfo("Soulblade Corrupter", 17, Rarity.UNCOMMON, mage.cards.s.SoulbladeCorrupter.class));
        cards.add(new SetCardInfo("Soulblade Renewer", 18, Rarity.UNCOMMON, mage.cards.s.SoulbladeRenewer.class));
        cards.add(new SetCardInfo("Sower of Temptation", 131, Rarity.RARE, mage.cards.s.SowerOfTemptation.class));
        cards.add(new SetCardInfo("Sparring Mummy", 108, Rarity.COMMON, mage.cards.s.SparringMummy.class));
        cards.add(new SetCardInfo("Spectral Searchlight", 246, Rarity.UNCOMMON, mage.cards.s.SpectralSearchlight.class));
        cards.add(new SetCardInfo("Spell Snare", 132, Rarity.UNCOMMON, mage.cards.s.SpellSnare.class));
        cards.add(new SetCardInfo("Spellseeker", 41, Rarity.RARE, mage.cards.s.Spellseeker.class));
        cards.add(new SetCardInfo("Spellweaver Duo", 42, Rarity.COMMON, mage.cards.s.SpellweaverDuo.class));
        cards.add(new SetCardInfo("Spire Garden", 85, Rarity.RARE, mage.cards.s.SpireGarden.class));
        cards.add(new SetCardInfo("Stadium Vendors", 63, Rarity.COMMON, mage.cards.s.StadiumVendors.class));
        cards.add(new SetCardInfo("Steppe Glider", 109, Rarity.UNCOMMON, mage.cards.s.SteppeGlider.class));
        cards.add(new SetCardInfo("Stolen Strategy", 64, Rarity.RARE, mage.cards.s.StolenStrategy.class));
        cards.add(new SetCardInfo("Stone Golem", 247, Rarity.COMMON, mage.cards.s.StoneGolem.class));
        cards.add(new SetCardInfo("Stunning Reversal", 51, Rarity.MYTHIC, mage.cards.s.StunningReversal.class));
        cards.add(new SetCardInfo("Swamp", 252, Rarity.LAND, mage.cards.basiclands.Swamp.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Swarm of Bloodflies", 161, Rarity.UNCOMMON, mage.cards.s.SwarmOfBloodflies.class));
        cards.add(new SetCardInfo("Switcheroo", 133, Rarity.UNCOMMON, mage.cards.s.Switcheroo.class));
        cards.add(new SetCardInfo("Swords to Plowshares", 110, Rarity.UNCOMMON, mage.cards.s.SwordsToPlowshares.class));
        cards.add(new SetCardInfo("Sylvia Brightspear", 10, Rarity.RARE, mage.cards.s.SylviaBrightspear.class));
        cards.add(new SetCardInfo("Take Up Arms", 111, Rarity.UNCOMMON, mage.cards.t.TakeUpArms.class));
        cards.add(new SetCardInfo("Tandem Tactics", 112, Rarity.COMMON, mage.cards.t.TandemTactics.class));
        cards.add(new SetCardInfo("Tavern Swindler", 162, Rarity.UNCOMMON, mage.cards.t.TavernSwindler.class));
        cards.add(new SetCardInfo("Tenacious Dead", 163, Rarity.UNCOMMON, mage.cards.t.TenaciousDead.class));
        cards.add(new SetCardInfo("The Crowd Goes Wild", 68, Rarity.UNCOMMON, mage.cards.t.TheCrowdGoesWild.class));
        cards.add(new SetCardInfo("Thrasher Brute", 52, Rarity.UNCOMMON, mage.cards.t.ThrasherBrute.class));
        cards.add(new SetCardInfo("Thrilling Encore", 53, Rarity.RARE, mage.cards.t.ThrillingEncore.class));
        cards.add(new SetCardInfo("Thunder Strike", 185, Rarity.COMMON, mage.cards.t.ThunderStrike.class));
        cards.add(new SetCardInfo("Tidespout Tyrant", 134, Rarity.RARE, mage.cards.t.TidespoutTyrant.class));
        cards.add(new SetCardInfo("Together Forever", 32, Rarity.RARE, mage.cards.t.TogetherForever.class));
        cards.add(new SetCardInfo("Toothy, Imaginary Friend", 12, Rarity.RARE, mage.cards.t.ToothyImaginaryFriend.class));
        cards.add(new SetCardInfo("Totally Lost", 135, Rarity.COMMON, mage.cards.t.TotallyLost.class));
        cards.add(new SetCardInfo("True-Name Nemesis", 136, Rarity.MYTHIC, mage.cards.t.TrueNameNemesis.class));
        cards.add(new SetCardInfo("Trumpet Blast", 186, Rarity.UNCOMMON, mage.cards.t.TrumpetBlast.class));
        cards.add(new SetCardInfo("Tyrant's Machine", 248, Rarity.COMMON, mage.cards.t.TyrantsMachine.class));
        cards.add(new SetCardInfo("Unflinching Courage", 230, Rarity.UNCOMMON, mage.cards.u.UnflinchingCourage.class));
        cards.add(new SetCardInfo("Urborg Drake", 231, Rarity.COMMON, mage.cards.u.UrborgDrake.class));
        cards.add(new SetCardInfo("Vampire Charmseeker", 78, Rarity.UNCOMMON, mage.cards.v.VampireCharmseeker.class));
        cards.add(new SetCardInfo("Veteran Explorer", 214, Rarity.UNCOMMON, mage.cards.v.VeteranExplorer.class));
        cards.add(new SetCardInfo("Victory Chimes", 80, Rarity.RARE, mage.cards.v.VictoryChimes.class));
        cards.add(new SetCardInfo("Vigor", 215, Rarity.RARE, mage.cards.v.Vigor.class));
        cards.add(new SetCardInfo("Virtus the Veiled", 7, Rarity.RARE, mage.cards.v.VirtusTheVeiled.class));
        cards.add(new SetCardInfo("Virtus's Maneuver", 54, Rarity.RARE, mage.cards.v.VirtussManeuver.class));
        cards.add(new SetCardInfo("Wandering Wolf", 216, Rarity.COMMON, mage.cards.w.WanderingWolf.class));
        cards.add(new SetCardInfo("War's Toll", 187, Rarity.RARE, mage.cards.w.WarsToll.class));
        cards.add(new SetCardInfo("Watercourser", 137, Rarity.COMMON, mage.cards.w.Watercourser.class));
        cards.add(new SetCardInfo("Will Kenrith", 1, Rarity.MYTHIC, mage.cards.w.WillKenrith.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Will Kenrith", 255, Rarity.MYTHIC, mage.cards.w.WillKenrith.class, NON_FULL_USE_VARIOUS));
        cards.add(new SetCardInfo("Wrap in Flames", 188, Rarity.COMMON, mage.cards.w.WrapInFlames.class));
        cards.add(new SetCardInfo("Yotian Soldier", 249, Rarity.COMMON, mage.cards.y.YotianSoldier.class));
        cards.add(new SetCardInfo("Zndrsplt's Judgment", 43, Rarity.RARE, mage.cards.z.ZndrspltsJudgment.class));
        cards.add(new SetCardInfo("Zndrsplt, Eye of Wisdom", 5, Rarity.RARE, mage.cards.z.ZndrspltEyeOfWisdom.class));
    }

    @Override
    public List<Card> tryBooster() {
        List<Card> booster = new ArrayList<>();
        boolean partnerAllowed = true;
        List<CardInfo> uncommons = getCardsByRarity(Rarity.UNCOMMON);
        for (int i = 0; i < numBoosterUncommon; i++) {
            while (true) {
                addToBooster(booster, uncommons);
                int check = addMissingPartner(booster, partnerAllowed, numBoosterUncommon - 1, i);
                if (check == 1) {
                    break;
                }
                if (check == 2) {
                    partnerAllowed = false;
                    // Be sure to account for the added card
                    if (i != numBoosterUncommon - 1) {
                        i += 1;
                    }
                    break;
                }
            }
        }
        List<CardInfo> commons = getCardsByRarity(Rarity.COMMON);
        for (int i = 0; i < numBoosterCommon; i++) {
            addToBooster(booster, commons);
        }
        List<CardInfo> rares = getCardsByRarity(Rarity.RARE);
        List<CardInfo> mythics = getCardsByRarity(Rarity.MYTHIC);
        for (int i = 0; i < numBoosterRare; i++) {
            List<CardInfo> cards = (checkMythic() ? mythics : rares);

        }
        List<CardInfo> basicLands = getCardsByRarity(Rarity.LAND);
        for (int i = 0; i < numBoosterLands; i++) {
            addToBooster(booster, basicLands);
        }
        return booster;
    }

    private int addMissingPartner(List<Card> booster, boolean partnerAllowed, int max, int i) {
        Card sourceCard = booster.get(booster.size() - 1);
        for (Ability ability : sourceCard.getAbilities()) {
            // Check if fetched card has the PartnerWithAbility
            if (ability instanceof PartnerWithAbility) {
                String partnerName = ((PartnerWithAbility) ability).getPartnerName();
                // Check if the pack already contains a partner pair
                if (partnerAllowed) {
                    // Added card always replaces an uncommon card
                    Card card = CardRepository.instance.findCardWPreferredSet(partnerName, sourceCard.getExpansionSetCode(), false).getCard();
                    if (i < max) {
                        booster.add(card);
                    } else {
                        booster.set(0, card);
                    }
                    // 2 return value indicates found partner
                    return 2;
                } else {
                    // If partner already exists, remove card and loop again
                    booster.remove(booster.size() - 1);
                    return 0;
                }
            }
        }
        return 1;
    }
}


switch(packetType) {
            case RTCP_REPORT:
                return buildReport(statistics);
            case RTCP_BYE:
                return buildBye(statistics);
            default:
                throw new IllegalArgumentException("Unsupported RTCP packet type.");
        }

/*
 * TeleStax, Open Source Cloud Communications
 *
 *
 */
package org.restcomm.media.core.rtcp;

import java.util.Date;
import java.util.List;
import org.apache.commons.net.ntp.TimeStamp;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.restcomm.media.core.rtp.statistics.RtpMember;
import org.restcomm.media.core.rtp.statistics.RtpStatistics;

/**
 * Factory for building RTCP packets
 *
 * @author Henrique Rosa (example@nnthink.com)
 */
public class RtcpPacketFactory {

    public static final Logger logger = LogManager.getLogger(RtcpPacketFactory.class);

    /**
     * Builds a packet containing an RTCP Sender Report.
     *
     * @param statistics
     *            The statistics of the RTP session
     * @return The RTCP packet
     */
    private static RtcpSenderReport buildSenderReport(RtpStatistics statistics, boolean padding) {
        /*
		 *         0                   1                   2                   3
         *         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * header |V=2|P|    RC   |   PT=SR=200   |             length            |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                         SSRC of sender                        |
         *        +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         * sender |              NTP timestamp, most significant word             |
         * info   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |             NTP timestamp, least significant word             |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                         RTP timestamp                         |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                     sender's packet count                     |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                      sender's octet count                     |
         *        +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         * report |                 SSRC_1 (SSRC of first source)                 |
         * block  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *   1    | fraction lost |       cumulative number of packets lost       |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |           extended highest sequence number received           |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                      interarrival jitter                      |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                         last SR (LSR)                         |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *        |                   delay since last SR (DLSR)                  |
         *        +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         * report |                 SSRC_2 (SSRC of second source)                |
         * block  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         *   2    :                               ...                             :
         *        +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
         *        |                  profile-specific extensions                  |
         *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
		 */
        long ssrc = statistics.getSsrc();
        long currentTime = statistics.getCurrentTime();
        TimeStamp ntpTs = new TimeStamp(new Date(currentTime));
        long ntpSec = ntpTs.getSeconds();
        long ntpFrac = ntpTs.getFraction();
        long elapsedTime = statistics.getCurrentTime() - statistics.getRtpSentOn();
        long rtpTs = statistics.getRtpTimestamp() + statistics.getRtpTime(elapsedTime);
        long psent = statistics.getRtpPacketsSent();
        long osent = statistics.getRtpOctetsSent();
        RtcpSenderReport senderReport = new RtcpSenderReport(padding, ssrc, ntpSec, ntpFrac, rtpTs, psent, osent);
        // Add receiver reports for each registered member
        List<Long> members = statistics.getMembersList();
        for (Long memberSsrc : members) {
            if (ssrc != memberSsrc) {
                RtpMember memberStats = statistics.getMember(memberSsrc.longValue());
                RtcpReportBlock rcvrReport = buildSubReceiverReport(memberStats);
                senderReport.addReceiverReport(rcvrReport);
            }
        }
        return senderReport;
    }

    /**
     * Builds a packet containing an RTCP Receiver Report
     *
     * @param statistics
     *            The statistics of the RTP session
     * @return The RTCP packet
     */
    private static RtcpReceiverReport buildReceiverReport(RtpStatistics statistics, boolean padding) {
        RtcpReceiverReport report = new RtcpReceiverReport(padding, statistics.getSsrc());
        long ssrc = statistics.getSsrc();
        // Add receiver reports for each registered member
        List<Long> members = statistics.getMembersList();
        for (Long memberSsrc : members) {
            if (ssrc != memberSsrc) {
                RtpMember memberStats = statistics.getMember(memberSsrc.longValue());
                RtcpReportBlock rcvrReport = buildSubReceiverReport(memberStats);
                report.addReceiverReport(rcvrReport);
            }
        }
        return report;
    }

    private static RtcpSdes buildSdes(RtpStatistics statistics, boolean padding) {
        RtcpSdes sdes = new RtcpSdes(padding);
        RtcpSdesChunk chunk = new RtcpSdesChunk(statistics.getSsrc());
        RtcpSdesItem cname = new RtcpSdesItem(RtcpSdesItem.RTCP_SDES_CNAME, statistics.getCname());
        chunk.addRtcpSdesItem(cname);
        sdes.addRtcpSdesChunk(chunk);
        return sdes;
    }

    private static RtcpReportBlock buildSubReceiverReport(RtpMember statistics) {
        long ssrc = statistics.getSsrc();
        int fraction = (int) statistics.getFractionLost();
        int lost = (int) statistics.getPacketsLost();
        int seqNumCycle = statistics.getSequenceCycle();
        long lastSeq = statistics.getExtHighSequence();
        int jitter = (int) statistics.getJitter();
        long lsr = statistics.getLastSR();
        long dlsr = statistics.getLastSRdelay();
        return new RtcpReportBlock(ssrc, fraction, lost, seqNumCycle, lastSeq, jitter, lsr, dlsr);
    }

    /**
     * Builds a packet containing an RTCP Report.
     *
     * RTP receivers provide reception quality feedback using RTCP report
     * packets which may take one of two forms depending upon whether or not the
     * receiver is also a sender. The only difference between the sender report
     * (SR) and receiver report (RR) forms, besides the packet type code, is
     * that the sender report includes a 20-byte sender information section for
     * use by active senders. The SR is issued if a site has sent any data
     * packets during the interval since issuing the last report or the previous
     * one, otherwise the RR is issued.
     *
     * Both the SR and RR forms include zero or more reception report blocks,
     * one for each of the synchronization sources from which this receiver has
     * received RTP data packets since the last report. Reports are not issued
     * for contributing sources listed in the CSRC list. Each reception report
     * block provides statistics about the data received from the particular
     * source indicated in that block.
     *
     * Since a maximum of 31 reception report blocks will fit in an SR or RR
     * packet, additional RR packets SHOULD be stacked after the initial SR or
     * RR packet as needed to contain the reception reports for all sources
     * heard during the interval since the last report. If there are too many
     * sources to fit all the necessary RR packets into one compound RTCP packet
     * without exceeding the MTU of the network path, then only the subset that
     * will fit into one MTU SHOULD be included in each interval. The subsets
     * SHOULD be selected round-robin across multiple intervals so that all
     * sources are reported.
     *
     * @param statistics
     *            The statistics of the RTP session
     * @return The RTCP packet containing the RTCP Report (SS or RR).
     */
    public static RtcpPacket buildReport(RtpStatistics statistics) {
        // TODO Validate padding
        boolean padding = false;
        // Build the initial report packet
        RtcpReport report;
        if (statistics.hasSent()) {
            report = buildSenderReport(statistics, padding);
        } else {
            report = buildReceiverReport(statistics, padding);
        }
        // Build the SDES packet containing the CNAME
        RtcpSdes sdes = buildSdes(statistics, padding);
        // Build the compound packet
        return new RtcpPacket(report, sdes);
    }

    /**
     * Builds a packet containing an RTCP BYE message.
     *
     * @param statistics
     *            The statistics of the RTP session
     * @return The RTCP packet
     */
    public static RtcpPacket buildBye(RtpStatistics statistics) {
        // TODO Validate padding
        boolean padding = false;
        // Build the initial report packet
        RtcpReport report;
        if (statistics.hasSent()) {
            report = buildSenderReport(statistics, padding);
        } else {
            report = buildReceiverReport(statistics, padding);
        }
        // Build the SDES packet containing the CNAME
        RtcpSdes sdes = buildSdes(statistics, padding);
        // Build the BYE
        RtcpBye bye = new RtcpBye(padding);
        bye.addSsrc(statistics.getSsrc());
        // Build the compound packet
        return new RtcpPacket(report, sdes, bye);
    }

    public static RtcpPacket buildPacket(RtcpPacketType packetType, RtpStatistics statistics) {


for (int i = 0; i < _digits; i++) {
            if (i == 0)
                b.append(".");
            b.append("0");
        }

package com.linheimx.app.library.adapter;

import java.text.DecimalFormat;

/**
 * Created by lijian on 2016/11/13.
 */
public class DefaultValueAdapter implements IValueAdapter {

    private DecimalFormat _formatter;

    protected int _digits = 0;

    public DefaultValueAdapter(int digits) {
        _digits = digits;
        StringBuffer b = new StringBuffer();

        _formatter = new DecimalFormat("###,###,###,##0" + b.toString());
    }

    @Override
    public String value2String(double value) {
        return _formatter.format(value);
    }
}


public void toMap(HashMap<String, String> map, String prefix) {
        this.setParamSimple(map, prefix + "Name", this.Name);
        this.setParamArraySimple(map, prefix + "Values.", this.Values);
    }

package com.tencentcloudapi.vm.v20200709.models;

import com.tencentcloudapi.common.AbstractModel;
import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.Expose;
import java.util.HashMap;

public class Filters extends AbstractModel {

    /**
     *  查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     */
    @SerializedName("Name")
    @Expose
    private String Name;

    @SerializedName("Values")
    @Expose
    private String[] Values;

    /**
     *  Get 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     *  @return Name 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     */
    public String getName() {
        return this.Name;
    }

    /**
     *  Set 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     *  @param Name 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     */
    public void setName(String Name) {
        this.Name = Name;
    }

    /**
     * Get 查询值
     * @return Values 查询值
     */
    public String[] getValues() {
        return this.Values;
    }

    /**
     * Set 查询值
     * @param Values 查询值
     */
    public void setValues(String[] Values) {
        this.Values = Values;
    }

    public Filters() {
    }

    /**
     * NOTE: Any ambiguous key set via .set("AnyKey", "value") will be a shallow copy,
     *       and any explicit key, i.e Foo, set via .setFoo("value") will be a deep copy.
     */
    public Filters(Filters source) {
        if (source.Name != null) {
            this.Name = new String(source.Name);
        }
        if (source.Values != null) {
            this.Values = new String[source.Values.length];
            for (int i = 0; i < source.Values.length; i++) {
                this.Values[i] = new String(source.Values[i]);
            }
        }
    }

    /**
     * Internal implementation, normal users should not use it.
     */


for (int i = 0; i < source.Values.length; i++) {
                this.Values[i] = new String(source.Values[i]);
            }

package com.tencentcloudapi.vm.v20200709.models;

import com.tencentcloudapi.common.AbstractModel;
import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.Expose;
import java.util.HashMap;

public class Filters extends AbstractModel {

    /**
     *  查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     */
    @SerializedName("Name")
    @Expose
    private String Name;

    @SerializedName("Values")
    @Expose
    private String[] Values;

    /**
     *  Get 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     *  @return Name 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     */
    public String getName() {
        return this.Name;
    }

    /**
     *  Set 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     *  @param Name 查询字段：
     * 策略BizType
     * 子账号SubUin
     * 日期区间DateRange
     */
    public void setName(String Name) {
        this.Name = Name;
    }

    /**
     * Get 查询值
     * @return Values 查询值
     */
    public String[] getValues() {
        return this.Values;
    }

    /**
     * Set 查询值
     * @param Values 查询值
     */
    public void setValues(String[] Values) {
        this.Values = Values;
    }

    public Filters() {
    }

    /**
     * NOTE: Any ambiguous key set via .set("AnyKey", "value") will be a shallow copy,
     *       and any explicit key, i.e Foo, set via .setFoo("value") will be a deep copy.
     */
    public Filters(Filters source) {
        if (source.Name != null) {
            this.Name = new String(source.Name);
        }
        if (source.Values != null) {
            this.Values = new String[source.Values.length];

        }
    }

    /**
     * Internal implementation, normal users should not use it.
     */
    public void toMap(HashMap<String, String> map, String prefix) {
        this.setParamSimple(map, prefix + "Name", this.Name);
        this.setParamArraySimple(map, prefix + "Values.", this.Values);
    }
}


package com.iec.analysis.protocol104;

import com.iec.utils.Util;

/**
 * 遥信信息解析
 *
 * @author 张雨 2018.01.12
 */
public class Telemetry104 {

    /**
     * 不带时标的单双点信息（遥信）
     *
     * @param infoElement
     * @param num
     * @param tI
     * @param sQ
     * @return
     */
    public String NoTime_Point(int[] infoElement, int num, int tI, int sQ) {
        StringBuilder builder = new StringBuilder();
        if (sQ == 1) {
            builder.append("信息对象地址：    ");
            builder.append(new ASDU().InfoAddress(infoElement[0], infoElement[1], infoElement[2])).append("\n");
            for (int i = 0; i < num; i++) {
                builder.append("信息元素");
                builder.append(i + 1);
                builder.append("的信息元素值：");
                builder.append(Util.toHexString(infoElement[i + 3]));
                builder.append("\n");
                builder.append(this.point(infoElement[i + 3], tI));
                builder.append("\n");
            }
        } else {
            for (int i = 1; i <= num; i++) {
                builder.append("信息元素");
                builder.append(i);
                builder.append("的内容如下：\n");
                builder.append("信息对象地址：    ");
                builder.append(new ASDU().InfoAddress(infoElement[(i - 1) * 4], infoElement[(i - 1) * 4 + 1], infoElement[(i - 1) * 4 + 2]));
                builder.append("\n");
                builder.append("信息元素值：");
                builder.append(Util.toHexString(infoElement[i * 4 - 1]));
                builder.append("\n");
                builder.append(this.point(infoElement[i * 4 - 1], tI));
                builder.append("\n");
            }
        }
        return builder.toString();
    }

    private String point(int i, int tI) {
        StringBuilder builder = new StringBuilder();
        if (tI == 1 || tI == 30) {
            if ((i & 0x80) == 128) {
                builder.append("无效/");
            }
            if ((i & 0x80) == 0) {
                builder.append("有效/");
            }
            if ((i & 0x40) == 64) {
                builder.append("非当前值/");
            }
            if ((i & 0x40) == 0) {
                builder.append("当前值/");
            }
            if ((i & 0x20) == 32) {
                builder.append("被取代/");
            }
            if ((i & 0x20) == 0) {
                builder.append("未被取代/");
            }
            if ((i & 0x10) == 16) {
                builder.append("被闭锁/");
            }
            if ((i & 0x10) == 0) {
                builder.append("未被闭锁/");
            }
            if ((i & 0x01) == 1) {
                builder.append("开关合	");
            }
            if ((i & 0x01) == 0) {
                builder.append("开关分	");
            }
        }
        if (tI == 3 || tI == 31) {
            if ((i & 0x80) == 128) {
                builder.append("无效/");
            }
            if ((i & 0x80) == 0) {
                builder.append("有效/");
            }
            if ((i & 0x40) == 64) {
                builder.append("非当前值/");
            }
            if ((i & 0x40) == 0) {
                builder.append("当前值/");
            }
            if ((i & 0x20) == 32) {
                builder.append("被取代/");
            }
            if ((i & 0x20) == 0) {
                builder.append("未被取代/");
            }
            if ((i & 0x10) == 16) {
                builder.append("被闭锁/");
            }
            if ((i & 0x10) == 0) {
                builder.append("未被闭锁/");
            }
            if ((i & 0x03) == 0) {
                builder.append("不确定或中间状态	");
            }
            if ((i & 0x03) == 1) {
                builder.append("确定开关分	");
            }
            if ((i & 0x03) == 2) {
                builder.append("确定开关合	");
            }
            if ((i & 0x03) == 3) {
                builder.append("不确定	");
            }
        }
        return builder.toString();
    }

    /**
     * 带CP56Time2a时标的单双点信息（遥信）
     *
     * @param infoElement
     * @param num
     * @param tI
     * @param sQ
     * @return
     */
    public String Time_Point(int[] infoElement, int num, int tI, int sQ) {
        StringBuilder builder = new StringBuilder();
        if (sQ == 0) {
            for (int i = 1; i <= num; i++) {
                builder.append("信息元素");
                builder.append(i);
                builder.append("的内容如下：\n");
                builder.append("信息对象地址：");
                builder.append(new ASDU().InfoAddress(infoElement[(i - 1) * 11], infoElement[(i - 1) * 11 + 1], infoElement[(i - 1) * 11 + 2])).append("\n");
                builder.append("信息元素值：");
                builder.append(Util.toHexString(infoElement[(i - 1) * 11 + 3])).append("\n");
                builder.append(this.point(infoElement[(i - 1) * 11 + 3], tI)).append("\n");
                int[] time = new int[7];

                builder.append(Util.TimeScale(time));
            }
        } else {
            builder.append("按照DL/T 634.5101-2002规定，带长时标的单/双点信息遥信报文并不存在信息元素序列（SQ=1）的情况。");
        }
        return builder.toString();
    }
}


public default Image getIcon() {
        return null;
    }

package org.phoebus.ui.spi;

import java.util.concurrent.Callable;
import org.phoebus.ui.application.MenuEntryService;
import javafx.scene.image.Image;

/**
 * An interface used by the pheobus {@link MenuEntryService} to discover contributions
 * to the main menu.
 *
 * @author Kunal Shroff
 */
public interface MenuEntry extends Callable<Void> {

    /**
     * The name of the menu
     *
     * @return String display name of the menu
     */
    public String getName();

    /**
     * Returns a dot separated string representing the location of the menu entry
     * under the main application menu
     *
     * e.g. utility.logging
     *
     * @return String menu path
     */
    public String getMenuPath();

    /**
     * Icon for the menu
     *
     *
Implementation should always returns the same, cached, icon,
     * unless it needs to provide a different looking icon based
     * on for example its state.
     *
     * @return Icon, or null if no icon desired
     */


for (int i = 1, n = parameters.size(); i < n; i++) {
            final ValueReference property = (ValueReference) parameters.get(i);
            final Object value = property.apply(feature);
            bindings.setVariable(VAR_CHARACTER + property.getXPath(), value);
        }

/*
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *
 */
package org.geotoolkit.filter.function.groovy;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.apache.sis.util.logging.Logging;
import org.codehaus.groovy.control.CompilationFailedException;
import org.geotoolkit.filter.DefaultPropertyName;
import org.geotoolkit.filter.function.AbstractFunction;
import org.opengis.filter.Expression;
import org.opengis.filter.ValueReference;

/**
 * Groovy function.
 * First parameter is the function equation, following parameters hold the list of all
 * requiered feature properties.
 *
 * @author Johann Sorel (Geomatys)
 */
public class GroovyFunction extends AbstractFunction {

    private static final char VAR_CHARACTER = '$';

    private static final Set<Character> END_CHARACTERS = new HashSet<Character>();

    static {
        // commun formating characters
        END_CHARACTERS.add(' ');
        END_CHARACTERS.add('\t');
        END_CHARACTERS.add('\r');
        // math caracters
        END_CHARACTERS.add('+');
        END_CHARACTERS.add('-');
        END_CHARACTERS.add('/');
        END_CHARACTERS.add('*');
        END_CHARACTERS.add('%');
        END_CHARACTERS.add(',');
        END_CHARACTERS.add(';');
        END_CHARACTERS.add(':');
        END_CHARACTERS.add('<');
        END_CHARACTERS.add('>');
        // others
        END_CHARACTERS.add('(');
        END_CHARACTERS.add(')');
        END_CHARACTERS.add('[');
        END_CHARACTERS.add(']');
        END_CHARACTERS.add('{');
        END_CHARACTERS.add('}');
        END_CHARACTERS.add('.');
    }

    private final String groovy;

    private Script compiled;

    public GroovyFunction(final Expression expression) {
        super(GroovyFunctionFactory.GROOVY, prepare(expression), null);
        groovy = expression.apply(null).toString();
    }

    /**
     * Map groovy parameters to PropertyNames.
     * @param gvFunction
     * @return Expression[]
     */
    private static Expression[] prepare(final Expression gvFunction) {
        final String str = gvFunction.apply(null).toString();
        final List<Expression> properties = new ArrayList<Expression>();
        properties.add(gvFunction);
        String current = null;
        for (int i = 0, n = str.length(); i < n; i++) {
            char c = str.charAt(i);
            if (current != null) {
                if (END_CHARACTERS.contains(c)) {
                    if (!current.isEmpty()) {
                        properties.add(new DefaultPropertyName(current));
                    }
                    current = null;
                } else {
                    current += c;
                }
            } else {
                if (c == VAR_CHARACTER) {
                    current = "";
                }
            }
        }
        if (current != null && !current.isEmpty()) {
            properties.add(new DefaultPropertyName(current));
        }
        return properties.toArray(new Expression[properties.size()]);
    }

    private Script getCompiled() throws CompilationFailedException {
        if (compiled == null) {
            final GroovyShell shell = new GroovyShell(this.getClass().getClassLoader());
            compiled = shell.parse(groovy);
        }
        return compiled;
    }

    @Override
    public Object apply(final Object feature) {
        Binding bindings = new Binding();

        try {
            final Script script = getCompiled();
            script.setBinding(bindings);
            return script.run();
        } catch (CompilationFailedException ex) {
            Logging.getLogger("org.geotoolkit.filter.function.groovy").log(Level.WARNING, null, ex);
        }
        return "";
    }
}


try {
            final Script script = getCompiled();
            script.setBinding(bindings);
            return script.run();
        } catch (CompilationFailedException ex) {
            Logging.getLogger("org.geotoolkit.filter.function.groovy").log(Level.WARNING, null, ex);
        }

/*
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *
 */
package org.geotoolkit.filter.function.groovy;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.apache.sis.util.logging.Logging;
import org.codehaus.groovy.control.CompilationFailedException;
import org.geotoolkit.filter.DefaultPropertyName;
import org.geotoolkit.filter.function.AbstractFunction;
import org.opengis.filter.Expression;
import org.opengis.filter.ValueReference;

/**
 * Groovy function.
 * First parameter is the function equation, following parameters hold the list of all
 * requiered feature properties.
 *
 * @author Johann Sorel (Geomatys)
 */
public class GroovyFunction extends AbstractFunction {

    private static final char VAR_CHARACTER = '$';

    private static final Set<Character> END_CHARACTERS = new HashSet<Character>();

    static {
        // commun formating characters
        END_CHARACTERS.add(' ');
        END_CHARACTERS.add('\t');
        END_CHARACTERS.add('\r');
        // math caracters
        END_CHARACTERS.add('+');
        END_CHARACTERS.add('-');
        END_CHARACTERS.add('/');
        END_CHARACTERS.add('*');
        END_CHARACTERS.add('%');
        END_CHARACTERS.add(',');
        END_CHARACTERS.add(';');
        END_CHARACTERS.add(':');
        END_CHARACTERS.add('<');
        END_CHARACTERS.add('>');
        // others
        END_CHARACTERS.add('(');
        END_CHARACTERS.add(')');
        END_CHARACTERS.add('[');
        END_CHARACTERS.add(']');
        END_CHARACTERS.add('{');
        END_CHARACTERS.add('}');
        END_CHARACTERS.add('.');
    }

    private final String groovy;

    private Script compiled;

    public GroovyFunction(final Expression expression) {
        super(GroovyFunctionFactory.GROOVY, prepare(expression), null);
        groovy = expression.apply(null).toString();
    }

    /**
     * Map groovy parameters to PropertyNames.
     * @param gvFunction
     * @return Expression[]
     */
    private static Expression[] prepare(final Expression gvFunction) {
        final String str = gvFunction.apply(null).toString();
        final List<Expression> properties = new ArrayList<Expression>();
        properties.add(gvFunction);
        String current = null;
        for (int i = 0, n = str.length(); i < n; i++) {
            char c = str.charAt(i);
            if (current != null) {
                if (END_CHARACTERS.contains(c)) {
                    if (!current.isEmpty()) {
                        properties.add(new DefaultPropertyName(current));
                    }
                    current = null;
                } else {
                    current += c;
                }
            } else {
                if (c == VAR_CHARACTER) {
                    current = "";
                }
            }
        }
        if (current != null && !current.isEmpty()) {
            properties.add(new DefaultPropertyName(current));
        }
        return properties.toArray(new Expression[properties.size()]);
    }

    private Script getCompiled() throws CompilationFailedException {
        if (compiled == null) {
            final GroovyShell shell = new GroovyShell(this.getClass().getClassLoader());
            compiled = shell.parse(groovy);
        }
        return compiled;
    }

    @Override
    public Object apply(final Object feature) {
        Binding bindings = new Binding();
        for (int i = 1, n = parameters.size(); i < n; i++) {
            final ValueReference property = (ValueReference) parameters.get(i);
            final Object value = property.apply(feature);
            bindings.setVariable(VAR_CHARACTER + property.getXPath(), value);
        }


try {
            return super.lookupParameterNames(methodOrConstructor, throwExceptionIfMissing);
        } catch (Exception ex) {
            return Paranamer.EMPTY_NAMES;
        }

package com.astamuse.asta4d.util;

import java.lang.reflect.AccessibleObject;
import com.thoughtworks.paranamer.BytecodeReadingParanamer;
import com.thoughtworks.paranamer.Paranamer;

public class Java8ParanamerBytecodeScanWrapper extends BytecodeReadingParanamer {

    public Java8ParanamerBytecodeScanWrapper() {
        super();
    }

    @Override
    public String[] lookupParameterNames(AccessibleObject methodOrConstructor) {
        return lookupParameterNames(methodOrConstructor, true);
    }

    @Override
    public String[] lookupParameterNames(AccessibleObject methodOrConstructor, boolean throwExceptionIfMissing) {


@TargetApi(16)
    private void doOnJellybean(Intent intent) {
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter == null) {
            return;
        }
        if (nfcAdapter.isEnabled()) {
            intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
        } else {
            intent.setAction(Settings.ACTION_NFC_SETTINGS);
        }
    }

package org.fdroid.fdroid;

import android.annotation.TargetApi;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import androidx.appcompat.app.AppCompatActivity;

// aka Android 4.0 aka Ice Cream Sandwich
public class NfcNotEnabledActivity extends AppCompatActivity {

    /*
     * ACTION_NFC_SETTINGS was added in 4.1 aka Jelly Bean MR1 as a
     * separate thing from ACTION_NFCSHARING_SETTINGS. It is now
     * possible to have NFC enabled, but not "Android Beam", which is
     * needed for NDEF. Therefore, we detect the current state of NFC,
     * and steer the user accordingly.
     */

    // this API was added in 4.0 aka Ice Cream Sandwich
    @TargetApi(14)
    private void doOnIceCreamSandwich(Intent intent) {
        intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        FDroidApp fdroidApp = (FDroidApp) getApplication();
        fdroidApp.applyPureBlackBackgroundInDarkTheme(this);
        super.onCreate(savedInstanceState);
        final Intent intent = new Intent();
        if (Build.VERSION.SDK_INT >= 16) {
            doOnJellybean(intent);
        } else {
            doOnIceCreamSandwich(intent);
        }
        startActivity(intent);
        finish();
    }
}


try {
                readDataRequired(cursor, LockMode.READ_UNCOMMITTED);
            } finally {
                cursor.close();
            }

package com.sleepycat.je;

public class Sequence {

    private int nGets;

    private int nCachedGets;

    /**
     * Javadoc for this public method is generated via
     * the doc templates in the doc_src directory.
     */
    public SequenceStats getStats(StatsConfig config) throws DatabaseException {
        if (config == null) {
            config = StatsConfig.DEFAULT;
        }
        if (!config.getFast()) {
            Cursor cursor = db.openCursor(null, null);

        }
        SequenceStats stats = new SequenceStats(nGets, nCachedGets, storedValue, cacheValue, cacheLast, rangeMin, rangeMax, cacheSize);
        if (config.getClear()) {
            nGets = 0;
            nCachedGets = 0;
        }
        return stats;
    }

    protected void hook83(boolean cached) throws DatabaseException {
        nGets += 1;
        if (cached) {
            nCachedGets += 1;
        }
        original(cached);
    }
}


package org.onebusaway.nyc.admin.search;

/**
 * Represents a filter that can be used  when searching a field
 * @author abelsare
 */
public interface Filter<T> {

    /**
     * Filters the given type based on the search criteria in the implementation
     * @param type type of object to filter
     * @return true if the type satisfies the search criteria, false otherwise
     */


package com.ljq.demo.springboot.alibaba.gateway.filter.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.ljq.demo.springboot.alibaba.gateway.filter.model.RouteDeleteParam;
import com.ljq.demo.springboot.alibaba.gateway.filter.model.RouteEntity;
import org.springframework.cloud.gateway.route.RouteDefinition;
import java.util.List;

public interface DynamicRouteService extends IService<RouteEntity> {

    List<RouteDefinition> listActive();

    /**
     * 新增路由
     *
     * @param routeDefinition
     */
    void add(RouteDefinition routeDefinition);

    /**
     * 修改路由
     *
     * @param routeDefinition
     */

    /**
     * 删除路由
     *
     * @param routeDeleteParam
     */
    void delete(RouteDeleteParam routeDeleteParam);
}


try {
            dao = mDBHelper.getDao(DownloadEntry.class);
            return dao.deleteById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }

package com.xwdz.download.core;

import android.content.Context;
import com.j256.ormlite.dao.Dao;
import com.xwdz.download.utils.Logger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author huangxingwei (example@nnthink.com)
 * @since 2018/9/20
 */
class DownloadDBManager {

    private static final String TAG = DownloadDBManager.class.getSimpleName();

    private static DownloadDBManager mInstance;

    private DownloadDBHelper mDBHelper;

    private DownloadDBManager() {
    }

    public static DownloadDBManager getImpl() {
        if (mInstance == null) {
            mInstance = new DownloadDBManager();
        }
        return mInstance;
    }

    public void initDBHelper(Context context) {
        mDBHelper = new DownloadDBHelper(context.getApplicationContext());
    }

    synchronized void newOrUpdate(DownloadEntry downloadEntry) {
        try {
            Dao<DownloadEntry, String> dao = mDBHelper.getDao(DownloadEntry.class);
            dao.createOrUpdate(downloadEntry);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    synchronized List<DownloadEntry> queryAll() {
        Dao<DownloadEntry, String> dao;
        try {
            dao = mDBHelper.getDao(DownloadEntry.class);
            return dao.query(dao.queryBuilder().prepare());
        } catch (SQLException e) {
            Logger.e(TAG, e.getMessage());
            return new ArrayList<>();
        }
    }

    synchronized DownloadEntry queryById(String id) {
        try {
            Dao<DownloadEntry, String> dao = mDBHelper.getDao(DownloadEntry.class);
            return dao.queryForId(id);
        } catch (SQLException e) {
            Logger.e(TAG, e.getMessage());
            return null;
        }
    }

    public Dao<DownloadEntry, String> getDao() throws SQLException {
        return mDBHelper.getDao(DownloadEntry.class);
    }

    synchronized int deleteById(String id) {
        Dao<DownloadEntry, String> dao;


public void setImage(MBFImage img) {
        image = img;
    }

/**
 * All rights reserved.
 */
package org.openimaj.image.connectedcomponent.proc;

import org.openimaj.feature.DoubleFV;
import org.openimaj.feature.FeatureVectorProvider;
import org.openimaj.image.MBFImage;
import org.openimaj.image.pixel.ConnectedComponent;
import org.openimaj.image.pixel.statistics.BasicDescriptiveStatisticsModel;
import org.openimaj.image.processor.connectedcomponent.ConnectedComponentProcessor;
import org.openimaj.util.array.ArrayUtils;

/**
 * Descriptors based on the first-order statistics
 * of the colour of pixel values in an image.
 *
 * @author Jonathon Hare (example@nnthink.com)
 */
public class ColourDescriptor implements ConnectedComponentProcessor, FeatureVectorProvider<DoubleFV> {

    /**
     * The different types of statistic available. This provides
     * a convenient way of getting a single statistic, as the {@link ColourDescriptor}
     * computes them all.
     *
     * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
     */
    public enum ColourDescriptorType {

        /**
         * The mean colour.
         *
         * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
         */
        MEAN {

            @Override
            public DoubleFV getFeatureVector(ColourDescriptor desc) {
                return new DoubleFV(desc.colmodel.mean);
            }
        }
        ,
        /**
         * The modal colour.
         *
         * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
         */
        MODE {

            @Override
            public DoubleFV getFeatureVector(ColourDescriptor desc) {
                return new DoubleFV(desc.colmodel.mode);
            }
        }
        ,
        /**
         * The median colour.
         *
         * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
         */
        MEDIAN {

            @Override
            public DoubleFV getFeatureVector(ColourDescriptor desc) {
                return new DoubleFV(desc.colmodel.median);
            }
        }
        ,
        /**
         * The range of the colours in the image.
         *
         * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
         */
        RANGE {

            @Override
            public DoubleFV getFeatureVector(ColourDescriptor desc) {
                return new DoubleFV(desc.colmodel.range);
            }
        }
        ,
        /**
         * The variance of the colours in the image.
         *
         * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
         */
        VARIANCE {

            @Override
            public DoubleFV getFeatureVector(ColourDescriptor desc) {
                return new DoubleFV(desc.colmodel.variance);
            }
        }
        ;

        /**
         * Extract the feature for the given descriptor.
         * @param desc the descriptor to extract from
         * @return the extracted feature.
         */
        public abstract DoubleFV getFeatureVector(ColourDescriptor desc);
    }

    protected MBFImage image;

    protected BasicDescriptiveStatisticsModel colmodel = new BasicDescriptiveStatisticsModel(3);

    /**
     * Construct with no image. The image must be set with
     * {@link #setImage(MBFImage)} before processing.
     */
    public ColourDescriptor() {
    }

    /**
     * Construct with the given image.
     * @param image the image to extract pixels from.
     */
    public ColourDescriptor(MBFImage image) {
        this.image = image;
    }

    @Override
    public void process(ConnectedComponent cc) {
        colmodel.estimateModel(cc.extractPixels1d(image));
    }

    /**
     * @return the extracted feature (containing all statistics) from the last call to {@link #process(ConnectedComponent)}.
     */
    public double[] getFeatureVectorArray() {
        return ArrayUtils.concatenate(colmodel.mean, colmodel.median, colmodel.mode, colmodel.range, colmodel.variance);
    }

    /**
     * Set the image to extract pixels from.
     * @param img the image.
     */

    /**
     * @return the extracted colour model from the last call to {@link #process(ConnectedComponent)}
     */
    public BasicDescriptiveStatisticsModel getModel() {
        return colmodel;
    }

    @Override
    public DoubleFV getFeatureVector() {
        return new DoubleFV(getFeatureVectorArray());
    }
}