当前位置: 首页>>代码示例>>Java>>正文


Java Map.compute方法代码示例

本文整理汇总了Java中java.util.Map.compute方法的典型用法代码示例。如果您正苦于以下问题:Java Map.compute方法的具体用法?Java Map.compute怎么用?Java Map.compute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Map的用法示例。


在下文中一共展示了Map.compute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkSpamCharacters

import java.util.Map; //导入方法依赖的package包/类
private boolean checkSpamCharacters(String channelName, String content)
{
    if(!Config.getContains(EConfigs.CHANNEL_SPAM_CHARACTERS_BLACKLIST, channelName)) return false;
    if(content.length() <= 10) return false;

    //Count all the characters in the message
    Map<Character, Integer> characterCount = new HashMap<>();
    for(char c : content.toCharArray())
        characterCount.compute(c, (character, integer) -> integer == null ? 1 : integer + 1);

    //Add up all of the major repeated characters
    int spamCharCount = 0;
    for(int charCount : characterCount.values())
        if(charCount > (int) Math.ceil((float) content.length() * 0.2f))
            spamCharCount += charCount;

    return spamCharCount > (int) Math.ceil((float) content.length() * 0.6f);
}
 
开发者ID:thebrightspark,项目名称:MDC-Discord-Bot,代码行数:19,代码来源:AutomodListener.java

示例2: testLogLevel

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogLevel() throws Exception {
  logger.setLevel(Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);

  logger.trace("trace!");
  logger.debug("debug!");
  logger.info("info!");
  logger.warn("warn!");
  logger.error("error!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:17,代码来源:LogbackInstrumentationTest.java

示例3: findLHS

import java.util.Map; //导入方法依赖的package包/类
public int findLHS(int[] nums) {
    int result = 0;

    Map<Integer, Integer> map = new HashMap<>();

    for (int num : nums) {
        map.compute(num, (key, value) -> value == null ? 1 : value + 1);
    }

    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
        if (map.containsKey(entry.getKey() + 1)) {
            result = Math.max(result, entry.getValue() + map.get(entry.getKey() + 1));
        }
    }

    return result;
}
 
开发者ID:viatsko,项目名称:hack,代码行数:18,代码来源:LongestHarmoniousSubsequence.java

示例4: testLogLevel

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogLevel() throws Exception {
  setLogLevel(logger, Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 2);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);
  expectedCounts.compute("fatal", (s, aLong) -> aLong + 1);

  logger.trace("trace!");
  logger.debug("debug!");
  logger.info("info!");
  logger.warn("warn!");
  logger.error("error!");
  logger.fatal("fatal!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:19,代码来源:Log4J2InstrumentationTest.java

示例5: findPairs

import java.util.Map; //导入方法依赖的package包/类
public int findPairs(int[] nums, int k) {
    Map<Integer, Integer> map = new HashMap<>();

    for (int num : nums) {
        map.compute(num, (key, value) -> value == null ? 1 : value + 1);
    }

    int result = 0;

    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
        if ((k > 0 && map.get(entry.getKey() + k) != null) || (k == 0 && entry.getValue() >= 2)) {
            result++;
        }
    }

    return result;
}
 
开发者ID:viatsko,项目名称:hack,代码行数:18,代码来源:KDiffPairsInAnArray.java

示例6: testLogLevel

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogLevel() throws Exception {
  logger.setLevel(Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 2);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);
  expectedCounts.compute("fatal", (s, aLong) -> aLong + 1);

  logger.trace("trace!");
  logger.debug("debug!");
  logger.info("info!");
  logger.warn("warn!");
  logger.error("error!");
  logger.fatal("fatal!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:19,代码来源:Log4JInstrumentationTest.java

示例7: testLoggerReconfiguration

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLoggerReconfiguration() throws Exception {
  logger.setLevel(Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);

  Properties properties = new Properties();
  properties.setProperty("log4j.rootCategory", "INFO,TestLog");
  properties.setProperty("log4j.appender.TestLog", "org.apache.log4j.ConsoleAppender");
  properties.setProperty("log4j.appender.TestLog.layout", "org.apache.log4j.PatternLayout");
  PropertyConfigurator.configure(properties);

  logger.error("error!");
  assertEquals(expectedCounts, getCurrentCounts());

}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:19,代码来源:Log4JInstrumentationTest.java

示例8: generateTestJar

import java.util.Map; //导入方法依赖的package包/类
public static Path generateTestJar(Pair<String, byte[]>... files) {
    Path jarFile;
    try {
        jarFile = Files.createTempFile("testjar", ".jar");
        try(ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(jarFile))) {
            Map<String, List<Pair<String, byte[]>>> filesMap = new HashMap<>();
            for (Pair<String, byte[]> file : files) {
                filesMap.compute(file.getKey(), (k, data) -> {
                    List<Pair<String, byte[]>> fileData = data != null ? data : new ArrayList<>();
                    fileData.add(new Pair<>(file.getKey(), compress(file.getValue())));
                    return fileData;
                });
            }

            filesMap.forEach((path, data) -> {
                putPath(Paths.get(path).getParent().toString(), zos);
                data.forEach(file -> putFile(file.getKey(), file.getValue(), zos));
            });

            zos.closeEntry();
            zos.finish();
        }
    } catch (Throwable e) {
        SneakyThrow.throwException(e);
        return null;
    }
    //jarFile.toFile().deleteOnExit();
    return jarFile;
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:30,代码来源:Utils.java

示例9: testLogTrace

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogTrace() throws Exception {
  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("trace", (s, aLong) -> aLong + 1);

  logger.trace("TRACE!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:11,代码来源:LogbackInstrumentationTest.java

示例10: testLogWarn

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogWarn() throws Exception {
  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("warn", (s, aLong) -> aLong + 1);

  logger.warn("WARN!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:11,代码来源:Log4J2InstrumentationTest.java

示例11: testLogInfo

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogInfo() throws Exception {
  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("info", (s, aLong) -> aLong + 1);

  logger.info("INFO!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:11,代码来源:Log4J2InstrumentationTest.java

示例12: testLogError

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLogError() throws Exception {
  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);

  logger.error("ERROR!");

  assertEquals(expectedCounts, getCurrentCounts());
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:11,代码来源:LogbackInstrumentationTest.java

示例13: testLoggerReconfiguration

import java.util.Map; //导入方法依赖的package包/类
@Test
public void testLoggerReconfiguration() throws Exception {
  setLogLevel(logger, Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);

  Properties properties = new Properties();
  properties.setProperty("name", "PropertiesConfig");
  properties.setProperty("appenders", "console");
  properties.setProperty("appender.console.type", "Console");
  properties.setProperty("appender.console.name", "STDOUT");
  properties.setProperty("rootLogger.level", "debug");
  properties.setProperty("rootLogger.appenderRefs", "stdout");
  properties.setProperty("rootLogger.appenderRefs", "stdout");
  properties.setProperty("rootLogger.appenderRef.stdout.ref", "STDOUT");
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  properties.store(baos, null);
  ConfigurationSource source = new ConfigurationSource(
      new ByteArrayInputStream(baos.toByteArray()));

  PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  PropertiesConfiguration configuration = factory.getConfiguration(context, source);
  configuration.start();
  context.updateLoggers(configuration);

  logger.error("error!");
  assertEquals(expectedCounts, getCurrentCounts());

}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:33,代码来源:Log4J2InstrumentationTest.java

示例14: transform

import java.util.Map; //导入方法依赖的package包/类
@Override
public ResourcePool transform(ResourcePool inResources, ResourcePoolBuilder outResources) {
    if (!isPrevisitCalled) {
        throw new AssertionError("Previsit was not called");
    }
    CustomStringTable table = (CustomStringTable)((ResourcePoolImpl)inResources).getStringTable();
    if (table.size() == 0) {
        throw new AssertionError("Table is empty");
    }
    Map<String, Integer> count = new HashMap<>();
    for (int i = 0; i < table.size(); ++i) {
        String s = table.getString(i);
        Optional<ResourcePoolEntry> e = inResources.findEntry(s);
        if (e.isPresent()) {
            throw new AssertionError();
        }
        count.compute(s, (k, c) -> 1 + (c == null ? 0 : c));
    }
    count.forEach((k, v) -> {
        if (v != 1) {
            throw new AssertionError("Expected one entry in the table, got: " + v + " for " + k);
        }
    });
    inResources.entries().forEach(r -> {
        outResources.add(r);
    });

    return outResources.build();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:PrevisitorTest.java

示例15: addToAggregate

import java.util.Map; //导入方法依赖的package包/类
private void addToAggregate(Map<String, Map<String, String>> aggregateRawProfiles, ProfileFile file) {
    Map<String, Profile> profiles = file.profiles();
    for (Map.Entry<String, Profile> profile : profiles.entrySet()) {
        aggregateRawProfiles.compute(profile.getKey(), (k, current) -> {
            if (current == null) {
                return new HashMap<>(profile.getValue().properties());
            } else {
                current.putAll(profile.getValue().properties());
                return current;
            }
        });
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:14,代码来源:ProfileFile.java


注:本文中的java.util.Map.compute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。