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


Java Trie类代码示例

本文整理汇总了Java中org.apache.commons.collections4.Trie的典型用法代码示例。如果您正苦于以下问题:Java Trie类的具体用法?Java Trie怎么用?Java Trie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: create

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
private TelNoNormalizer create() {
	try {
		Trie<String, Integer> trie = new PatriciaTrie<>();
		trie.putAll(parse("soumu/000124070.xls"));
		trie.putAll(parse("soumu/000124071.xls"));
		trie.putAll(parse("soumu/000124072.xls"));
		trie.putAll(parse("soumu/000124073.xls"));
		trie.putAll(parse("soumu/000124074.xls"));
		trie.putAll(parse("soumu/000124075.xls"));
		trie.putAll(parse("soumu/000124076.xls"));
		trie.putAll(parse("soumu/000124077.xls"));
		TelNoNormalizerImpl impl = new TelNoNormalizerImpl();
		impl.setAreaCodeTable(trie);
		return impl;
	} catch (InvalidFormatException | IOException ex) {
		throw new IllegalStateException(ex);
	}
}
 
开发者ID:agwlvssainokuni,项目名称:sqlapp,代码行数:19,代码来源:TelNoNormalizerImplTest.java

示例2: test

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
@Test
public void test() throws Exception {

	List<Resource> resources = new ArrayList<>(9);
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124070.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124071.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124072.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124073.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124074.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124075.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124076.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124077.xls"));
	resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124078.xls"));
	AreaCodeTableFactory factory = new AreaCodeTableFactory();
	factory.setSoumuExcelParser(new SoumuExcelParser());
	factory.setResources(resources);

	Trie<String, Integer> trie = factory.getObject();
	SortedMap<String, Integer> map = trie.prefixMap("042");
	assertEquals(790, map.size());
	assertEquals(new TreeSet<Integer>(asList(2, 3, 4)), new TreeSet<>(map.values()));

	assertEquals(4554 + 5683 + 3400 + 5343 + 5307 + 3000 + 5548 + 4526 + 5330, trie.size());
	assertEquals(Trie.class, factory.getObjectType());
	assertFalse(factory.isSingleton());
}
 
开发者ID:agwlvssainokuni,项目名称:springapp,代码行数:27,代码来源:AreaCodeTableFactoryTest.java

示例3: processContainers

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
private void processContainers(List<ContainerInfo> containersToProcess,
    List<ContainerInfo> containersToRemove,
    Map<String, ContainerInfo> seenContainerPathToContainerInfo,
    Trie<String, MetadataNode> sanitisedRootSearchIndex) {
  // Lets remove references to files that are no longer present in classpath
  containersToRemove.forEach(
      container -> removeReferences(seenContainerPathToContainerInfo, sanitisedRootSearchIndex,
          container));

  for (ContainerInfo containerInfo : containersToProcess) {
    // lets remove existing references from search index, as these files are modified, so that we can rebuild index
    if (seenContainerPathToContainerInfo.containsKey(containerInfo.getContainerPath())) {
      removeReferences(seenContainerPathToContainerInfo, sanitisedRootSearchIndex, containerInfo);
    }

    String metadataFilePath = containerInfo.getPath();
    try (InputStream inputStream = containerInfo.getMetadataFile().getInputStream()) {
      SpringConfigurationMetadata springConfigurationMetadata = new Gson()
          .fromJson(new BufferedReader(new InputStreamReader(inputStream)),
              SpringConfigurationMetadata.class);
      buildMetadataHierarchy(sanitisedRootSearchIndex, containerInfo,
          springConfigurationMetadata);

      seenContainerPathToContainerInfo.put(containerInfo.getContainerPath(), containerInfo);
    } catch (IOException e) {
      log.error("Exception encountered while processing metadata file: " + metadataFilePath, e);
      removeReferences(seenContainerPathToContainerInfo, sanitisedRootSearchIndex, containerInfo);
    }
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:31,代码来源:SuggestionIndexServiceImpl.java

示例4: reindexModule

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
private void reindexModule(List<ContainerInfo> newProjectSourcesToProcess,
    List<ContainerInfo> projectContainersToRemove, Module module) {
  Map<String, ContainerInfo> moduleSeenContainerPathToSeenContainerInfo =
      moduleNameToSeenContainerPathToContainerInfo
          .computeIfAbsent(module.getName(), k -> new HashMap<>());

  Trie<String, MetadataNode> moduleSanitisedRootSearchIndex =
      moduleNameToSanitisedRootSearchIndex.get(module.getName());
  if (moduleSanitisedRootSearchIndex == null) {
    moduleSanitisedRootSearchIndex = new PatriciaTrie<>();
    moduleNameToSanitisedRootSearchIndex.put(module.getName(), moduleSanitisedRootSearchIndex);
  }

  OrderEnumerator moduleOrderEnumerator = OrderEnumerator.orderEntries(module);

  List<ContainerInfo> newModuleContainersToProcess =
      computeNewContainersToProcess(moduleOrderEnumerator,
          moduleSeenContainerPathToSeenContainerInfo);
  newModuleContainersToProcess.addAll(newProjectSourcesToProcess);

  List<ContainerInfo> moduleContainersToRemove = computeContainersToRemove(moduleOrderEnumerator,
      moduleSeenContainerPathToSeenContainerInfo);
  moduleContainersToRemove.addAll(projectContainersToRemove);

  processContainers(newModuleContainersToProcess, moduleContainersToRemove,
      moduleSeenContainerPathToSeenContainerInfo, moduleSanitisedRootSearchIndex);
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:28,代码来源:SuggestionIndexServiceImpl.java

示例5: removeReferences

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
private void removeReferences(Map<String, ContainerInfo> containerPathToContainerInfo,
    Trie<String, MetadataNode> sanitisedRootSearchIndex, ContainerInfo containerInfo) {
  debug(() -> log.debug("Removing references to " + containerInfo));
  String containerPath = containerInfo.getContainerPath();
  containerPathToContainerInfo.remove(containerPath);

  Iterator<String> searchIndexIterator = sanitisedRootSearchIndex.keySet().iterator();
  while (searchIndexIterator.hasNext()) {
    MetadataNode root = sanitisedRootSearchIndex.get(searchIndexIterator.next());
    boolean removeTree = root.removeRef(containerInfo.getContainerPath());
    if (removeTree) {
      searchIndexIterator.remove();
    }
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:16,代码来源:SuggestionIndexServiceImpl.java

示例6: UnmodifiableTrie

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
/**
 * Constructor that wraps (not copies).
 *
 * @param trie  the trie to decorate, must not be null
 * @throws NullPointerException if trie is null
 */
public UnmodifiableTrie(final Trie<K, ? extends V> trie) {
    if (trie == null) {
        throw new NullPointerException("Trie must not be null");
    }
    @SuppressWarnings("unchecked") // safe to upcast
    final Trie<K, V> tmpTrie = (Trie<K, V>) trie;
    this.delegate = tmpTrie;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:15,代码来源:UnmodifiableTrie.java

示例7: testDecorateFactory

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
public void testDecorateFactory() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testDecorateFactory");
    final Trie<java.lang.String, V> trie = makeFullMap();
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6355,trie);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6357,null,6356,org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(trie));
    try {
        org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(null);
    } catch (final IllegalArgumentException ex) {
    }
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:UnmodifiableTrieTest.java

示例8: testDecorateFactory_add1999

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
@org.junit.Test(timeout = 1000)
public void testDecorateFactory_add1999() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testDecorateFactory_add1999");
    final Trie<java.lang.String, V> trie = makeFullMap();
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6355,trie);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6357,null,6356,org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(trie));
    try {
        org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(null);
        org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(null);
    } catch (final IllegalArgumentException ex) {
    }
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:14,代码来源:UnmodifiableTrieTest.java

示例9: getObject

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
/**
 * 局番割当データ (キー「局番 (6桁)」、値「市外局番の長さ」のマップ) を取得する。
 * 
 * @return 局番割当データ (キー「局番 (6桁)」、値「市外局番の長さ」のマップ)。
 * @throws InvalidFormatException 局番割当ファイルの形式が不正。
 * @throws IOException 局番割当ファイルの読込み異常。
 */
@Override
public Trie<String, Integer> getObject() throws InvalidFormatException, IOException {
	Trie<String, Integer> trie = new PatriciaTrie<>();
	for (Resource r : resources) {
		try (InputStream in = r.getInputStream()) {
			Map<String, Pair<String, String>> map = soumuExcelParser.parse(in);
			for (Map.Entry<String, Pair<String, String>> entry : map.entrySet()) {
				trie.put(entry.getKey(), entry.getValue().getLeft().length());
			}
		}
	}
	return trie;
}
 
开发者ID:agwlvssainokuni,项目名称:sqlapp,代码行数:21,代码来源:AreaCodeTableFactory.java

示例10: canProvideSuggestions

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
@Override
public boolean canProvideSuggestions(Project project, Module module) {
  Trie<String, MetadataNode> sanitisedRootSearchIndex =
      moduleNameToSanitisedRootSearchIndex.get(module.getName());
  return sanitisedRootSearchIndex != null && sanitisedRootSearchIndex.size() != 0;
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:7,代码来源:SuggestionIndexServiceImpl.java

示例11: computeSuggestions

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
private List<LookupElementBuilder> computeSuggestions(
    Trie<String, MetadataNode> sanitisedRootSearchIndex, ClassLoader classLoader,
    @Nullable List<String> ancestralKeys, String queryString) {
  debug(() -> log.debug("Search requested for " + queryString));
  StopWatch timer = new StopWatch();
  timer.start();
  try {
    String sanitizedQueryString = MetadataNode.sanitize(queryString);
    String[] querySegments = toPathSegments(sanitizedQueryString);
    Set<Suggestion> suggestions = null;
    if (ancestralKeys != null) {
      String[] pathSegments =
          ancestralKeys.stream().flatMap(element -> stream(toPathSegments(element)))
              .toArray(String[]::new);
      MetadataNode searchStartNode =
          sanitisedRootSearchIndex.get(MetadataNode.sanitize(pathSegments[0]));
      if (searchStartNode != null) {
        if (pathSegments.length > 1) {
          searchStartNode = searchStartNode.findDeepestMatch(pathSegments, 1, true);
        }
        if (searchStartNode != null) {
          if (!searchStartNode.isLeaf()) {
            suggestions =
                searchStartNode.findChildSuggestions(querySegments, 0, 0, classLoader, false);

            // since we don't have any matches at the root level, may be a subset of intermediary nodes might match the entered string
            if (suggestions == null) {
              suggestions =
                  searchStartNode.findChildSuggestions(querySegments, 0, 0, classLoader, true);
            }
          } else {
            // if the start node is a leaf, this means, the user is looking for values for the given key, lets find the suggestions for values
            suggestions = searchStartNode.getSuggestionValues(classLoader);
          }
        }
      }
    } else {
      String sanitisedQuerySegment = MetadataNode.sanitize(querySegments[0]);
      SortedMap<String, MetadataNode> topLevelQueryResults =
          sanitisedRootSearchIndex.prefixMap(sanitisedQuerySegment);
      Collection<MetadataNode> childNodes = topLevelQueryResults.values();
      suggestions = getSuggestions(classLoader, querySegments, childNodes, 1, 1, false);

      // since we don't have any matches at the root level, may be a subset of intermediary nodes might match the entered string
      if (suggestions == null) {
        Collection<MetadataNode> nodesToSearchWithin = sanitisedRootSearchIndex.values();
        suggestions = getSuggestions(classLoader, querySegments, nodesToSearchWithin, 1, 0, true);
      }
    }

    if (suggestions != null) {
      return toLookupElementBuilders(suggestions, classLoader);
    }
    return null;
  } finally {
    timer.stop();
    debug(() -> log.debug("Search took " + timer.toString()));
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:60,代码来源:SuggestionIndexServiceImpl.java

示例12: buildMetadataHierarchy

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
private void buildMetadataHierarchy(Trie<String, MetadataNode> sanitisedRootSearchIndex,
    ContainerInfo containerInfo, SpringConfigurationMetadata springConfigurationMetadata) {
  debug(() -> log.debug("Adding container to index " + containerInfo));
  String containerPath = containerInfo.getContainerPath();
  // populate groups
  List<SpringConfigurationMetadataGroup> groups = springConfigurationMetadata.getGroups();
  if (groups != null) {
    groups.sort(comparing(SpringConfigurationMetadataGroup::getName));
    for (SpringConfigurationMetadataGroup group : groups) {
      String[] pathSegments = toPathSegments(group.getName());
      MetadataNode closestMetadata =
          findDeepestMatch(sanitisedRootSearchIndex, pathSegments, false);
      if (closestMetadata == null) {
        String firstSegment = pathSegments[0];
        closestMetadata = MetadataNode.newInstance(firstSegment, null, containerPath);
        boolean noMoreSegmentsLeft = pathSegments.length == 1;
        if (noMoreSegmentsLeft) {
          closestMetadata.setGroup(group);
        }
        String sanitizedFirstSegment = MetadataNode.sanitize(firstSegment);
        sanitisedRootSearchIndex.put(sanitizedFirstSegment, closestMetadata);
      }
      closestMetadata.addChildren(group, pathSegments, containerPath);
    }
  }

  // populate properties
  List<SpringConfigurationMetadataProperty> properties =
      springConfigurationMetadata.getProperties();
  properties.sort(comparing(SpringConfigurationMetadataProperty::getName));
  for (SpringConfigurationMetadataProperty property : properties) {
    String[] pathSegments = toPathSegments(property.getName());
    MetadataNode closestMetadata =
        findDeepestMatch(sanitisedRootSearchIndex, pathSegments, false);
    if (closestMetadata == null) {
      String firstSegment = pathSegments[0];
      closestMetadata = MetadataNode.newInstance(firstSegment, null, containerPath);
      boolean noMoreSegmentsLeft = pathSegments.length == 1;
      if (noMoreSegmentsLeft) {
        closestMetadata.setProperty(property);
      }
      String sanitizedFirstSegment = MetadataNode.sanitize(firstSegment);
      sanitisedRootSearchIndex.put(sanitizedFirstSegment, closestMetadata);
    }
    closestMetadata.addChildren(property, pathSegments, containerPath);
  }

  // update hints
  List<SpringConfigurationMetadataHint> hints = springConfigurationMetadata.getHints();
  if (hints != null) {
    hints.sort(comparing(SpringConfigurationMetadataHint::getName));
    for (SpringConfigurationMetadataHint hint : hints) {
      String[] pathSegments = toPathSegments(hint.getName());
      MetadataNode closestMetadata =
          findDeepestMatch(sanitisedRootSearchIndex, pathSegments, true);
      if (closestMetadata != null && closestMetadata.getDepth() == pathSegments.length) {
        assert closestMetadata.getProperty() != null;
        closestMetadata.getProperty().setHint(hint);
      }
    }
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:63,代码来源:SuggestionIndexServiceImpl.java

示例13: makeObject

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
@Override
public Trie<java.lang.String, V> makeObject() {
    return org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(new PatriciaTrie<V>());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:UnmodifiableTrieTest.java

示例14: makeFullMap

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
@Override
public Trie<java.lang.String, V> makeFullMap() {
    final Trie<java.lang.String, V> m = new PatriciaTrie<V>();
    addSampleMappings(m);
    return org.apache.commons.collections4.trie.UnmodifiableTrie.unmodifiableTrie(m);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:7,代码来源:UnmodifiableTrieTest.java

示例15: setAreaCodeTable

import org.apache.commons.collections4.Trie; //导入依赖的package包/类
public void setAreaCodeTable(Trie<String, Integer> areaCodeTable) {
	this.areaCodeTable = areaCodeTable;
}
 
开发者ID:agwlvssainokuni,项目名称:sqlapp,代码行数:4,代码来源:TelNoNormalizerImpl.java


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