use of org.apache.flink.shaded.guava30.com.google.common.collect.Lists in project sonar-java by SonarSource.
the class SonarComponentsTest method creation_of_both_types_test_checks.
@Test
public void creation_of_both_types_test_checks() {
JavaCheck expectedCheck = new CustomCheck();
JavaCheck expectedTestCheck = new CustomTestCheck();
CheckRegistrar expectedRegistrar = registrarContext -> registrarContext.registerClassesForRepository(REPOSITORY_NAME, Lists.<Class<? extends JavaCheck>>newArrayList(CustomCheck.class), Lists.<Class<? extends JavaCheck>>newArrayList(CustomTestCheck.class));
when(this.checks.all()).thenReturn(Lists.newArrayList(expectedCheck)).thenReturn(Lists.newArrayList(expectedTestCheck));
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, null, null, null, checkFactory, new CheckRegistrar[] { expectedRegistrar });
sonarComponents.setSensorContext(context);
JavaCheck[] visitors = sonarComponents.checkClasses();
assertThat(visitors).hasSize(1);
assertThat(visitors[0]).isEqualTo(expectedCheck);
Collection<JavaCheck> testChecks = sonarComponents.testCheckClasses();
assertThat(testChecks).hasSize(1);
assertThat(testChecks.iterator().next()).isEqualTo(expectedTestCheck);
assertThat(sonarComponents.checks()).hasSize(2);
postTestExecutionChecks();
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.Lists in project alien4cloud by alien4cloud.
the class PolicyMatchingReplaceModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
super.process(topology, context);
for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
String policyImplMeta = TagUtil.getTagValue(policyType.getTags(), "a4c_policy_impl");
if (policyImplMeta == null) {
context.log().warn("Matched policy {} for {} does not define an alien topology modifier implementation, it may not be taken in account.", policyTemplate.getType(), policyTemplate.getName());
continue;
}
String[] policyImpl = policyImplMeta.split(":");
if (policyImpl.length != 3) {
context.log().error("Matched policy {} for policy {} defines an invalid modifier implementation {}, format should be policy_plugin_id:policy_plugin_bean:injection_phase", policyTemplate.getType(), policyTemplate.getName(), policyImplMeta);
}
try {
ITopologyModifier modifier = pluginModifierRegistry.getPluginBean(policyImpl[0], policyImpl[1]);
List<ITopologyModifier> phaseModifiers = (List<ITopologyModifier>) context.getExecutionCache().computeIfAbsent(policyImpl[2], s -> Lists.<ITopologyModifier>newArrayList());
// No need to add a modifier more than once for a phase
if (!phaseModifiers.contains(modifier)) {
phaseModifiers.add(modifier);
}
} catch (MissingPluginException e) {
context.log().error("Implementation specified for policy type {} that refers to plugin bean {}, {} cannot be found.", policyTemplate.getType(), policyImpl[0], policyImpl[1]);
}
}
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.Lists in project NetherEx by LogicTechCorp.
the class TradeListManager method init.
public static void init(File directory) {
for (TradeCareer.EnumType career : TradeCareer.EnumType.values()) {
offerLists.put(career, Maps.newHashMap());
}
try {
LOGGER.info("Copying the Trade List Directory to the config folder.");
if (NetherEx.IS_DEV_ENV) {
FileUtils.copyDirectory(new File(NetherEx.class.getResource("/assets/nex/trade_lists").getFile()), directory);
} else {
FileUtil.extractFromJar("/assets/nex/trade_lists", directory.getPath());
}
} catch (IOException e) {
LOGGER.fatal("The attempt to copy the Trade List Directory to the config folder was unsuccessful.");
LOGGER.fatal(e);
}
try {
Gson gson = new Gson();
List<File> tradeFiles = Lists.newArrayList(directory.listFiles());
for (File tradeFile : tradeFiles) {
String jsonText = Files.toString(tradeFile, Charsets.UTF_8);
TradeList tradeList = gson.fromJson(jsonText, TradeList.class);
LOGGER.info("Adding trades from the " + tradeList.getName() + ".");
for (TradeProfession profession : tradeList.getProfessions()) {
for (TradeCareer career : profession.getCareers()) {
for (TradeOffer offer : career.getTrades()) {
ItemStack outputStack;
TradeOffer.Output output = offer.getOutput();
String outputId = output.getName();
int outputMeta = output.getMeta();
TradeOffer.Amount outputAmount = output.getAmount();
List<TradeOffer.Enchantment> outputEnchantments = output.getEnchantments();
TradeOffer.Display outputDisplay = output.getDisplay();
if (Item.getByNameOrId(outputId) != null) {
outputStack = new ItemStack(Item.getByNameOrId(outputId), 1, outputMeta);
} else if (Block.getBlockFromName(outputId) != null) {
outputStack = new ItemStack(Block.getBlockFromName(outputId), 1, outputMeta);
} else {
continue;
}
if (outputEnchantments == null) {
outputEnchantments = Lists.newArrayList();
}
if (outputDisplay != null) {
if (!Strings.isNullOrEmpty(outputDisplay.getName())) {
outputStack.setStackDisplayName(outputDisplay.getName());
}
if (outputDisplay.getLore().size() > 0) {
NBTUtil.setTag(outputStack);
NBTTagList loreList = new NBTTagList();
for (String lore : outputDisplay.getLore()) {
loreList.appendTag(new NBTTagString(lore));
}
NBTTagCompound displayCompound = new NBTTagCompound();
displayCompound.setTag("Lore", loreList);
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("display", displayCompound);
NBTUtil.setTag(outputStack, compound);
}
}
ItemStack inputStackA;
TradeOffer.Input inputA = offer.getInputA();
String inputAId = inputA.getName();
int inputAMeta = inputA.getMeta();
TradeOffer.Amount inputAAmount = inputA.getAmount();
if (Item.getByNameOrId(inputAId) != null) {
inputStackA = new ItemStack(Item.getByNameOrId(inputAId), 1, inputAMeta);
} else if (Block.getBlockFromName(inputAId) != null) {
inputStackA = new ItemStack(Block.getBlockFromName(inputAId), 1, inputAMeta);
} else {
continue;
}
ItemStack inputStackB;
TradeOffer.Input inputB = offer.getInputB();
if (inputB == null) {
inputB = new TradeOffer.Input("minecraft:air", 0, new TradeOffer.Amount(1, 1));
}
String inputBId = inputB.getName();
int inputBMeta = inputB.getMeta();
TradeOffer.Amount inputBAmount = inputB.getAmount();
if (Item.getByNameOrId(inputBId) != null) {
inputStackB = new ItemStack(Item.getByNameOrId(inputBId), 1, inputBMeta);
} else if (Block.getBlockFromName(inputBId) != null) {
inputStackB = new ItemStack(Block.getBlockFromName(inputBId), 1, inputBMeta);
} else {
continue;
}
TradeOffer.Amount offerAmount = offer.getAmount();
Trade trade = new Trade(outputStack, outputAmount, inputStackA, inputAAmount, inputStackB, inputBAmount, offerAmount, outputEnchantments);
offerLists.get(TradeCareer.EnumType.fromCareer(career)).computeIfAbsent(offer.getLevel(), k -> Lists.newArrayList()).add(trade);
}
}
}
}
} catch (IOException e) {
LOGGER.fatal("NetherEx was unable to read the Trade lists.");
LOGGER.fatal(e);
}
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.Lists in project mica2 by obiba.
the class CartController method lists.
@GetMapping("/lists")
public ModelAndView lists() {
MicaConfig config = micaConfigService.getConfig();
if (!config.isCartEnabled()) {
return new ModelAndView("redirect:/");
}
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
Optional<DocumentSet> tentative = variableSetService.getAllCurrentUser().stream().filter(DocumentSet::hasName).findFirst();
return tentative.map(documentSet -> new ModelAndView("redirect:/list/" + documentSet.getId())).orElseGet(() -> new ModelAndView("redirect:/search"));
} else {
return new ModelAndView("redirect:signin?redirect=" + micaConfigService.getContextPath() + "/lists");
}
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.Lists in project JavaSpecial by FrankZuozuo.
the class AboutOptional method test.
private static void test() {
String foo = "foo", foobar, fb;
List<String> list = Lists.newArrayList("f", "o", "o", null, "b", "a", "r");
Optional<String> optional = Optional.of(foo);
Optional<List<String>> optionalStringList = Optional.of(list);
// 如果存在值,则打印
optional.ifPresent(Print::echo);
// 进行安全的操作
foobar = optionalStringList.filter(s -> s.size() > 5).map(s -> s.get(3)).map(String::toUpperCase).orElse(null);
Print.echo(foobar);
// 等价于
if (list != null) {
if (list.size() > 5) {
String s = list.get(3);
if (s != null) {
fb = s.toUpperCase();
} else {
fb = null;
}
} else {
fb = null;
}
} else {
fb = null;
}
Print.echo(fb);
// 进行安全的操作 - 使用函数
foobar = optionalStringList.filter(s -> s.size() > 5).map(s -> s.get(3)).map(String::toUpperCase).orElseGet(AboutOptional::getDefaultFromDB);
Print.echo(foobar);
Print.echo("optional 是否有值 : " + optional.isPresent());
// 如果值存在, 则调用指定的Consumer 方法
optional.ifPresent(Print::echo);
// 创建一个可能为null的Optional
Optional empty = Optional.ofNullable(null);
// 返回Optional.empty
Print.echo(empty);
// 获取Optional 的值
Print.echo(optional.get());
String s = optionalStringList.map(strings -> strings.get(6)).orElseThrow(IndexOutOfBoundsException::new);
Print.echo(s);
// flatMap : 与map相当,不同的是需要通过Optional来构建值
String b = optionalStringList.filter(lists -> lists.size() > 6).flatMap(a -> Optional.of(a.get(0))).orElse(null);
Print.echo(b);
}
Aggregations