use of javax.annotation.Nonnull in project blueocean-plugin by jenkinsci.
the class BlueOceanWebURLBuilder method getTryBlueOceanURLs.
/**
* Get the {@link TryBlueOceanURLs} instance for the {@link ModelObject}
* associated with the current Stapler request.
*
* @return The {@link TryBlueOceanURLs} instance for the current classic
* Jenkins page. The URL to the Blue Ocean homepage is returned if a more
* appropriate URL is not found.
*/
@Nonnull
public static TryBlueOceanURLs getTryBlueOceanURLs() {
StaplerRequest staplerRequest = Stapler.getCurrentRequest();
List<Ancestor> list = staplerRequest.getAncestors();
// Blue Ocean page we can link onto.
for (int i = list.size() - 1; i >= 0; i--) {
Ancestor ancestor = list.get(i);
Object object = ancestor.getObject();
if (object instanceof ModelObject) {
String blueUrl = toBlueOceanURL((ModelObject) object);
if (blueUrl != null) {
if (object instanceof Item) {
return new TryBlueOceanURLs(blueUrl, ((Item) object).getUrl());
} else if (object instanceof Run) {
return new TryBlueOceanURLs(blueUrl, ((Run) object).getUrl());
} else {
return new TryBlueOceanURLs(blueUrl);
}
} else if (object instanceof Item) {
return new TryBlueOceanURLs(getBlueHome(), ((Item) object).getUrl());
}
}
}
// Otherwise just return Blue Ocean home.
return new TryBlueOceanURLs(getBlueHome());
}
use of javax.annotation.Nonnull in project jsonschema2pojo by joelittlejohn.
the class IncludeJsr305AnnotationsIT method validateNullableField.
private static void validateNullableField(Field nonnullField) {
Nonnull nonnullAnnotation = nonnullField.getAnnotation(Nonnull.class);
Nullable nullableAnnotation = nonnullField.getAnnotation(Nullable.class);
assertNull("Unexpected @Nonnull annotation found.", nonnullAnnotation);
assertNotNull("Expected @Nullable annotation is missing.", nullableAnnotation);
}
use of javax.annotation.Nonnull in project blueocean-plugin by jenkinsci.
the class CredentialsUtils method findOrCreateDomain.
@Nonnull
private static Domain findOrCreateDomain(@Nonnull CredentialsStore store, @Nonnull String domainName, @Nonnull List<DomainSpecification> domainSpecifications) throws IOException {
Domain domain = store.getDomainByName(domainName);
if (domain == null) {
//create new one
boolean result = store.addDomain(new Domain(domainName, domainName + " to store credentials by BlueOcean", domainSpecifications));
if (!result) {
throw new ServiceException.BadRequestExpception("Failed to create credential domain: " + domainName);
}
domain = store.getDomainByName(domainName);
if (domain == null) {
throw new ServiceException.UnexpectedErrorException("Domain %s created but not found");
}
}
return domain;
}
use of javax.annotation.Nonnull in project Store by NYTimes.
the class GetRefreshingTest method setUp.
@Before
public void setUp() {
networkCalls = new AtomicInteger(0);
store = StoreBuilder.<Integer>barcode().fetcher(new Fetcher<Integer, BarCode>() {
@Nonnull
@Override
public Observable<Integer> fetch(@Nonnull BarCode barCode) {
return Observable.fromCallable(new Callable<Integer>() {
@Override
public Integer call() {
return networkCalls.incrementAndGet();
}
});
}
}).persister(persister).open();
}
use of javax.annotation.Nonnull in project MinecraftForge by MinecraftForge.
the class FluidUtil method tryPlaceFluid.
/**
* Tries to place a fluid in the world in block form and drains the container.
* Makes a fluid emptying sound when successful.
* Honors the amount of fluid contained by the used container.
* Checks if water-like fluids should vaporize like in the nether.
*
* Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
*
* @param player Player who places the fluid. May be null for blocks like dispensers.
* @param world World to place the fluid in
* @param pos The position in the world to place the fluid block
* @param container The fluid container holding the fluidStack to place
* @param resource The fluidStack to place
* @return the container's ItemStack with the remaining amount of fluid if the placement was successful, null otherwise
*/
@Nonnull
public static FluidActionResult tryPlaceFluid(@Nullable EntityPlayer player, World world, BlockPos pos, @Nonnull ItemStack container, FluidStack resource) {
if (world == null || resource == null || pos == null) {
return FluidActionResult.FAILURE;
}
Fluid fluid = resource.getFluid();
if (fluid == null || !fluid.canBePlacedInWorld()) {
return FluidActionResult.FAILURE;
}
// check that we can place the fluid at the destination
IBlockState destBlockState = world.getBlockState(pos);
Material destMaterial = destBlockState.getMaterial();
boolean isDestNonSolid = !destMaterial.isSolid();
boolean isDestReplaceable = destBlockState.getBlock().isReplaceable(world, pos);
if (!world.isAirBlock(pos) && !isDestNonSolid && !isDestReplaceable) {
// Non-air, solid, unreplacable block. We can't put fluid here.
return FluidActionResult.FAILURE;
}
if (world.provider.doesWaterVaporize() && fluid.doesVaporize(resource)) {
fluid.vaporize(player, world, pos, resource);
return tryEmptyContainer(container, new VoidFluidHandler(), Integer.MAX_VALUE, player, true);
} else {
if (!world.isRemote && (isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid()) {
world.destroyBlock(pos, true);
}
// Defer the placement to the fluid block
// Instead of actually "filling", the fluid handler method replaces the block
Block block = fluid.getBlock();
IFluidHandler handler;
if (block instanceof IFluidBlock) {
handler = new FluidBlockWrapper((IFluidBlock) block, world, pos);
} else if (block instanceof BlockLiquid) {
handler = new BlockLiquidWrapper((BlockLiquid) block, world, pos);
} else {
handler = new BlockWrapper(block, world, pos);
}
FluidActionResult result = tryEmptyContainer(container, handler, Integer.MAX_VALUE, player, true);
if (result.isSuccess()) {
SoundEvent soundevent = fluid.getEmptySound(resource);
world.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return result;
}
}
Aggregations