Search in sources :

Example 11 with Range

use of controlP5.Range in project TechReborn by TechReborn.

the class BuiltContainer method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(final EntityPlayer player, final int index) {
    ItemStack originalStack = ItemStack.EMPTY;
    final Slot slot = this.inventorySlots.get(index);
    if (slot != null && slot.getHasStack()) {
        final ItemStack stackInSlot = slot.getStack();
        originalStack = stackInSlot.copy();
        boolean shifted = false;
        for (final Range<Integer> range : this.playerSlotRanges) if (range.contains(index)) {
            if (this.shiftToTile(stackInSlot))
                shifted = true;
            break;
        }
        if (!shifted)
            for (final Range<Integer> range : this.tileSlotRanges) if (range.contains(index)) {
                if (this.shiftToPlayer(stackInSlot))
                    shifted = true;
                break;
            }
        slot.onSlotChange(stackInSlot, originalStack);
        if (stackInSlot.getCount() <= 0)
            slot.putStack(ItemStack.EMPTY);
        else
            slot.onSlotChanged();
        if (stackInSlot.getCount() == originalStack.getCount())
            return ItemStack.EMPTY;
        slot.onTake(player, stackInSlot);
    }
    return originalStack;
}
Also used : ItemStack(net.minecraft.item.ItemStack) Range(org.apache.commons.lang3.Range)

Example 12 with Range

use of controlP5.Range in project libSBOLj by SynBioDex.

the class SequenceAnnotationTest method test_locationMethods.

@Test
public void test_locationMethods() throws SBOLValidationException {
    Cut promoter_cut = promoter_SA.addCut("promoter_cut", 1);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("promoter_SA").getLocation("promoter_cut").equals(promoter_cut));
    promoter_cut.unsetOrientation();
    assertNull(promoter_cut.getOrientation());
    Location test = promoter_cut;
    assertNotNull(test.toString());
    Cut terminator_cut = terminator_SA.addCut("terminator_cut", 100);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("terminator_SA").getLocation("terminator_cut").equals(terminator_cut));
    Cut gene_cut = gene_SA.addCut("gene_cut", 50, OrientationType.INLINE);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("gene_SA").getLocation("gene_cut").equals(gene_cut));
    gene_SA.removeLocation(gene_cut);
    assertNull(gene_SA.getLocation("gene_cut"));
    Range gene_range = gene_SA.addRange("gene_range", 50, 99);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("gene_SA").getLocation("gene_range").equals(gene_range));
    gene_range.unsetOrientation();
    assertNull(gene_range.getOrientation());
    promoter_SA.removeLocation(promoter_cut);
    assertNull(promoter_SA.getLocation(promoter_cut.getIdentity()));
    GenericLocation promoter_glocation = promoter_SA.addGenericLocation("promoter_glocation");
    assertTrue(gRNA_b_gene.getSequenceAnnotation("promoter_SA").getLocation("promoter_glocation").equals(promoter_glocation));
    terminator_SA.removeLocation(terminator_cut);
    assertNull(terminator_SA.getLocation("terminator_cut"));
    GenericLocation terminator_glocation = terminator_SA.addGenericLocation("terminator_glocation", OrientationType.INLINE);
    assertTrue(gRNA_b_gene.getSequenceAnnotation("terminator_SA").getLocation("terminator_glocation").equals(terminator_glocation));
}
Also used : Cut(org.sbolstandard.core2.Cut) GenericLocation(org.sbolstandard.core2.GenericLocation) Range(org.sbolstandard.core2.Range) GenericLocation(org.sbolstandard.core2.GenericLocation) Location(org.sbolstandard.core2.Location) Test(org.junit.Test)

Example 13 with Range

use of controlP5.Range in project metron by apache.

the class WindowProcessorTest method testDenseWindow.

@Test
public void testDenseWindow() {
    for (String text : new String[] { "from 2 hours ago to 30 minutes ago", "starting from 2 hours until 30 minutes", "starting from 2 hours ago until 30 minutes ago", "starting from 30 minutes ago until 2 hours ago", "from 30 minutes ago to 2 hours ago " }) {
        Window w = WindowProcessor.process(text);
        /*
    A dense window starting 2 hour ago and continuing until 30 minutes ago
     */
        Date now = new Date();
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(1, intervals.size());
        assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
        assertTimeEquals(now.getTime() - TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
    }
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 14 with Range

use of controlP5.Range in project metron by apache.

the class WindowProcessorTest method testRepeatWithConflictingExclusionInclusion.

@Test
public void testRepeatWithConflictingExclusionInclusion() {
    Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago including saturdays excluding weekends");
    Date now = new Date();
    // avoid DST impacts if near Midnight
    now.setHours(6);
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    assertEquals(0, intervals.size());
}
Also used : Range(org.apache.commons.lang3.Range) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 15 with Range

use of controlP5.Range in project metron by apache.

the class WindowProcessorTest method testDateDaySpecifier.

@Test
public void testDateDaySpecifier() throws ParseException {
    for (String text : new String[] { "30 minute window every 24 hours from 14 days ago including date:20171225:yyyyMMdd", "30 minute window every 24 hours from 14 days ago including date:2017-12-25:yyyy-MM-dd", "30 minute window every 24 hours from 14 days ago including date:2017/12/25" }) {
        Window w = WindowProcessor.process(text);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date now = sdf.parse("2017/12/26 12:00");
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(1, intervals.size());
        Date includedDate = new Date(intervals.get(0).getMinimum());
        SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
        assertEquals("20171225", equalityFormat.format(includedDate));
    }
    {
        Window w = WindowProcessor.process("30 minute window every 24 hours from 14 days ago excluding date:2017/12/25");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date now = sdf.parse("2017/12/26 12:00");
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(13, intervals.size());
    }
    {
        Window w = WindowProcessor.process("30 minute window every 24 hours from 14 days ago including date:2017/12/25, date:2017/12/24");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date now = sdf.parse("2017/12/26 12:00");
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        assertEquals(2, intervals.size());
        {
            Date includedDate = new Date(intervals.get(0).getMinimum());
            SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
            assertEquals("20171224", equalityFormat.format(includedDate));
        }
        {
            Date includedDate = new Date(intervals.get(1).getMinimum());
            SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
            assertEquals("20171225", equalityFormat.format(includedDate));
        }
    }
}
Also used : List(java.util.List) Range(org.apache.commons.lang3.Range) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Range (org.apache.commons.lang3.Range)11 Date (java.util.Date)9 Test (org.junit.jupiter.api.Test)9 Range (controlP5.Range)3 Slider (controlP5.Slider)3 Toggle (controlP5.Toggle)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ControllerStyle (controlP5.ControllerStyle)1 Group (controlP5.Group)1 Label (controlP5.Label)1 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 ProfilePeriod (org.apache.metron.profiler.ProfilePeriod)1 StellarProcessor (org.apache.metron.stellar.common.StellarProcessor)1 DefaultVariableResolver (org.apache.metron.stellar.dsl.DefaultVariableResolver)1 Test (org.junit.Test)1 Assertions (org.junit.jupiter.api.Assertions)1 Cut (org.sbolstandard.core2.Cut)1 GenericLocation (org.sbolstandard.core2.GenericLocation)1 Location (org.sbolstandard.core2.Location)1