Search in sources :

Example 41 with Nullable

use of javax.annotation.Nullable in project storm by apache.

the class TestExprSemantic method testJDBCNumericFunctions.

@Test
public void testJDBCNumericFunctions() throws Exception {
    Values v = testExpr(Lists.newArrayList("{fn POWER(3, 2)}", "{fn ABS(-10)}", "{fn MOD(10, 3)}", "{fn MOD(-10, 3)}"));
    assertEquals(new Values(9.0d, 10, 1, -1), v);
    // Belows are floating numbers so comparing this with literal is tend to be failing...
    // Picking int value and compare
    Values v2 = testExpr(Lists.newArrayList("{fn LOG(16)}", "{fn LOG10(10000)}", "{fn EXP(10)}"));
    List<Object> v2m = Lists.transform(v2, new Function<Object, Object>() {

        @Nullable
        @Override
        public Object apply(@Nullable Object o) {
            // only takes int value
            return ((Number) o).intValue();
        }
    });
    // 2.7725, 4.0, 22026.465794
    assertEquals(new Values(2, 4, 22026), v2m);
}
Also used : Values(org.apache.storm.tuple.Values) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 42 with Nullable

use of javax.annotation.Nullable in project Store by NYTimes.

the class BreadthFirstFileTreeIterator method findNextFile.

/**
     * Find the next file.
     *
     * @return The next file
     */
@Nullable
protected File findNextFile() {
    while (currentIndex < currentList.length) {
        if (currentList[currentIndex].isDirectory()) {
            directories.push(currentList[currentIndex]);
            currentIndex++;
        } else {
            File file = currentList[currentIndex];
            currentIndex++;
            return file;
        }
    }
    while (!directories.empty()) {
        File directory = directories.remove(0);
        currentList = directory.listFiles();
        currentIndex = 0;
        File file = findNextFile();
        if (file != null) {
            return file;
        }
    }
    endOfTree = true;
    return null;
}
Also used : File(java.io.File) Nullable(javax.annotation.Nullable)

Example 43 with Nullable

use of javax.annotation.Nullable in project MinecraftForge by MinecraftForge.

the class ModelBlockAnimation method getPartTransform.

@Nullable
public TRSRTransformation getPartTransform(IModelState state, BlockPart part, int i) {
    ImmutableCollection<MBJointWeight> infos = getJoint(i);
    if (!infos.isEmpty()) {
        Matrix4f m = new Matrix4f(), tmp;
        float weight = 0;
        for (MBJointWeight info : infos) {
            if (info.getWeights().containsKey(i)) {
                ModelBlockAnimation.MBJoint joint = new ModelBlockAnimation.MBJoint(info.getName(), part);
                Optional<TRSRTransformation> trOp = state.apply(Optional.of(joint));
                if (trOp.isPresent() && trOp.get() != TRSRTransformation.identity()) {
                    float w = info.getWeights().get(i)[0];
                    tmp = trOp.get().getMatrix();
                    tmp.mul(w);
                    m.add(tmp);
                    weight += w;
                }
            }
        }
        if (weight > 1e-5) {
            m.mul(1f / weight);
            return new TRSRTransformation(m);
        }
    }
    return null;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4f(javax.vecmath.Matrix4f) Nullable(javax.annotation.Nullable)

Example 44 with Nullable

use of javax.annotation.Nullable in project MinecraftForge by MinecraftForge.

the class FluidUtil method getFluidHandler.

/**
     * Helper method to get an IFluidHandler for at a block position.
     *
     * Returns null if there is no valid fluid handler.
     */
@Nullable
public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) {
    IBlockState state = world.getBlockState(blockPos);
    Block block = state.getBlock();
    if (block.hasTileEntity(state)) {
        TileEntity tileEntity = world.getTileEntity(blockPos);
        if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
            return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        }
    } else if (block instanceof IFluidBlock) {
        return new FluidBlockWrapper((IFluidBlock) block, world, blockPos);
    } else if (block instanceof BlockLiquid) {
        return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) Block(net.minecraft.block.Block) Nullable(javax.annotation.Nullable)

Example 45 with Nullable

use of javax.annotation.Nullable in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method requestTicket.

/**
     * Request a chunkloading ticket of the appropriate type for the supplied mod
     *
     * @param mod The mod requesting a ticket
     * @param world The world in which it is requesting the ticket
     * @param type The type of ticket
     * @return A ticket with which to register chunks for loading, or null if no further tickets are available
     */
@Nullable
public static Ticket requestTicket(Object mod, World world, Type type) {
    ModContainer container = getContainer(mod);
    if (container == null) {
        FMLLog.log(Level.ERROR, "Failed to locate the container for mod instance %s (%s : %x)", mod, mod.getClass().getName(), System.identityHashCode(mod));
        return null;
    }
    String modId = container.getModId();
    if (!callbacks.containsKey(modId)) {
        FMLLog.severe("The mod %s has attempted to request a ticket without a listener in place", modId);
        throw new RuntimeException("Invalid ticket request");
    }
    int allowedCount = getMaxTicketLengthFor(modId);
    if (tickets.get(world).get(modId).size() >= allowedCount) {
        if (!warnedMods.contains(modId)) {
            FMLLog.info("The mod %s has attempted to allocate a chunkloading ticket beyond it's currently allocated maximum : %d", modId, allowedCount);
            warnedMods.add(modId);
        }
        return null;
    }
    Ticket ticket = new Ticket(modId, type, world);
    tickets.get(world).put(modId, ticket);
    return ticket;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)3188 List (java.util.List)363 IOException (java.io.IOException)307 Map (java.util.Map)294 ArrayList (java.util.ArrayList)284 Nonnull (javax.annotation.Nonnull)264 File (java.io.File)225 Collectors (java.util.stream.Collectors)175 Arrays (java.util.Arrays)165 HashMap (java.util.HashMap)161 Test (org.junit.Test)137 Layer (com.simiacryptus.mindseye.lang.Layer)116 Tensor (com.simiacryptus.mindseye.lang.Tensor)116 ItemStack (net.minecraft.item.ItemStack)115 Logger (org.slf4j.Logger)113 LoggerFactory (org.slf4j.LoggerFactory)113 ImmutableList (com.google.common.collect.ImmutableList)111 Set (java.util.Set)107 Result (com.simiacryptus.mindseye.lang.Result)104 Function (com.google.common.base.Function)100