Java Code Examples for gnu.trove.TObjectIntHashMap#put()

The following examples show how to use gnu.trove.TObjectIntHashMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageCounter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public synchronized void increment(@Nonnull String groupName,
                                   @Nonnull NotificationSource source,
                                   @Nonnull NotificationCategory category,
                                   @Nonnull ProjectSystemId projectSystemId) {

  final TObjectIntHashMap<NotificationCategory> counter =
          ContainerUtil.getOrCreate(
                  ContainerUtil.getOrCreate(
                          ContainerUtil.getOrCreate(
                                  map,
                                  projectSystemId,
                                  ContainerUtil.<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>>newHashMap()),
                          groupName,
                          ContainerUtil.<NotificationSource, TObjectIntHashMap<NotificationCategory>>newHashMap()
                  ),
                  source,
                  new TObjectIntHashMap<NotificationCategory>()
          );
  if (!counter.increment(category)) counter.put(category, 1);
}
 
Example 2
Source File: ControlDependencies.java    From whyline with MIT License 5 votes vote down vote up
private TObjectIntHashMap<Instruction> visitPostOrderIterative(Instruction start, ArrayList<Instruction> instructionsInPostOrderTraversalOfReverseControlFlowGraph) {
	
	TObjectIntHashMap<Instruction>postOrderNumbers = new TObjectIntHashMap<Instruction>();
	
	ArrayList<Instruction> stack = new ArrayList<Instruction>();
	TIntHashSet visitedIndices = new TIntHashSet(code.getNumberOfInstructions());
	TIntHashSet processedIndices = new TIntHashSet(code.getNumberOfInstructions());
	
	stack.add(start);
	while(stack.size() > 0) {
		Instruction top = stack.get(stack.size() - 1);
		if(visitedIndices.contains(top.getIndex())) {
			stack.remove(stack.size() - 1);
			if(!processedIndices.contains(top.getIndex())) {
				processedIndices.add(top.getIndex());
				
				instructionsInPostOrderTraversalOfReverseControlFlowGraph.add(0, top);
				postOrderNumbers.put(top, instructionsInPostOrderTraversalOfReverseControlFlowGraph.size());

			}
		}
		// Remember that we were here, then add the predecessors in reverse order to the stack.
		else {
			visitedIndices.add(top.getIndex());
			int insertionIndex = 0;
			for(Instruction predecessor : top.getOrderedPredecessors()) {
				if(!visitedIndices.contains(predecessor.getIndex())) {
					stack.add(stack.size() - insertionIndex, predecessor);
					insertionIndex++;
				}
			}
		}

	}

	return postOrderNumbers;
	
}
 
Example 3
Source File: ExpandedSupModel.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static TObjectIntHashMap<String> getReverseMap(TIntObjectHashMap<String> map) {
	TObjectIntHashMap<String> rMap = new TObjectIntHashMap<String>();
	int[] keys = map.keys();
	for (int i = 0; i < keys.length; i++) {
		rMap.put(map.get(keys[i]), keys[i]);
	}
	return rMap;
}
 
Example 4
Source File: ConvertGraphToSerObj.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static int indexString(String string, TObjectIntHashMap<String> map, ArrayList<String> list) {
	if (map.contains(string)) {
		return map.get(string);
	} else {
		int size = map.size();
		map.put(string, size);
		list.add(string);
		return size;
	}
}
 
Example 5
Source File: ListFocusTraversalPolicy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <X> TObjectIntHashMap<X> indexMap(@Nonnull X[] array) {
  TObjectIntHashMap<X> map = new TObjectIntHashMap<>(array.length);
  for (X x : array) {
    if (!map.contains(x)) {
      map.put(x, map.size());
    }
  }
  map.compact();
  return map;
}
 
Example 6
Source File: SeverityRegistrar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static OrderMap fromList(@Nonnull List<HighlightSeverity> orderList) {
  TObjectIntHashMap<HighlightSeverity> map = new TObjectIntHashMap<HighlightSeverity>();
  for (int i = 0; i < orderList.size(); i++) {
    HighlightSeverity severity = orderList.get(i);
    map.put(severity, i);
  }
  return new OrderMap(map);
}
 
Example 7
Source File: ExternalSystemTasksTreeModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void ensureSubProjectsStructure(@Nonnull ExternalProjectPojo topLevelProject, @Nonnull Collection<ExternalProjectPojo> subProjects) {
  ExternalSystemNode<ExternalProjectPojo> topLevelProjectNode = ensureProjectNodeExists(topLevelProject);
  Map<String/*config path*/, ExternalProjectPojo> toAdd = ContainerUtilRt.newHashMap();
  for (ExternalProjectPojo subProject : subProjects) {
    toAdd.put(subProject.getPath(), subProject);
  }
  toAdd.remove(topLevelProject.getPath());

  final TObjectIntHashMap<Object> taskWeights = new TObjectIntHashMap<>();
  for (int i = 0; i < topLevelProjectNode.getChildCount(); i++) {
    ExternalSystemNode<?> child = topLevelProjectNode.getChildAt(i);
    Object childElement = child.getDescriptor().getElement();
    if (childElement instanceof ExternalTaskExecutionInfo) {
      taskWeights.put(childElement, subProjects.size() + i);
      continue;
    }
    if (toAdd.remove(((ExternalProjectPojo)childElement).getPath()) == null) {
      removeNodeFromParent(child);
      //noinspection AssignmentToForLoopParameter
      i--;
    }
  }
  if (!toAdd.isEmpty()) {
    for (Map.Entry<String, ExternalProjectPojo> entry : toAdd.entrySet()) {
      ExternalProjectPojo element = new ExternalProjectPojo(entry.getValue().getName(), entry.getValue().getPath());
      insertNodeInto(new ExternalSystemNode<>(descriptor(element, myUiAware.getProjectIcon())), topLevelProjectNode);
    }
  }
}
 
Example 8
Source File: KShortestPathsFinder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void computeDistancesToTarget() {
  myNonTreeEdges = new MultiMap<Node, GraphEdge<Node>>();
  mySortedNodes = new ArrayList<Node>();
  myNextNodes = new HashMap<Node, Node>();
  TObjectIntHashMap<Node> distances = new TObjectIntHashMap<Node>();
  Deque<Node> nodes = new ArrayDeque<Node>();
  nodes.addLast(myFinish);
  distances.put(myFinish, 0);
  while (!nodes.isEmpty()) {
    myProgressIndicator.checkCanceled();
    Node node = nodes.removeFirst();
    mySortedNodes.add(node);
    int d = distances.get(node) + 1;
    Iterator<Node> iterator = myGraph.getIn(node);
    while (iterator.hasNext()) {
      Node prev = iterator.next();
      if (distances.containsKey(prev)) {
        int dPrev = distances.get(prev);
        myNonTreeEdges.putValue(prev, new GraphEdge<Node>(prev, node, d - dPrev));
        continue;
      }
      distances.put(prev, d);
      myNextNodes.put(prev, node);
      nodes.addLast(prev);
    }
  }
}
 
Example 9
Source File: SimpleGraphInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <CommitId> TObjectIntHashMap<CommitId> reverseCommitIdMap(PermanentCommitsInfo<CommitId> permanentCommitsInfo, int size) {
  TObjectIntHashMap<CommitId> result = new TObjectIntHashMap<>();
  for (int i = 0; i < size; i++) {
    result.put(permanentCommitsInfo.getCommitId(i), i);
  }
  return result;
}
 
Example 10
Source File: ArrangementEngine.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static <E extends ArrangementEntry> void sortByName(@Nonnull List<E> entries) {
  if (entries.size() < 2) {
    return;
  }
  final TObjectIntHashMap<E> weights = new TObjectIntHashMap<E>();
  int i = 0;
  for (E e : entries) {
    weights.put(e, ++i);
  }
  ContainerUtil.sort(entries, new Comparator<E>() {
    @Override
    public int compare(E e1, E e2) {
      String name1 = e1 instanceof NameAwareArrangementEntry ? ((NameAwareArrangementEntry)e1).getName() : null;
      String name2 = e2 instanceof NameAwareArrangementEntry ? ((NameAwareArrangementEntry)e2).getName() : null;
      if (name1 != null && name2 != null) {
        return name1.compareTo(name2);
      }
      else if (name1 == null && name2 == null) {
        return weights.get(e1) - weights.get(e2);
      }
      else if (name2 == null) {
        return -1;
      }
      else {
        return 1;
      }
    }
  });
}
 
Example 11
Source File: VarModality.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a hash code using the given map from vars to ints.
 */
public int hashCode(TObjectIntHashMap varMap) {
	// see if this already in map
	if (varMap.containsKey(this))
		return varMap.get(this);
	// otherwise add it
	int next = varMap.size() + 1;
	varMap.put(this, next);
	return next;
}
 
Example 12
Source File: GFeatVar.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a hash code using the given map from vars to ints.
 */
public int hashCode(TObjectIntHashMap varMap) {
	// see if this already in map
	if (varMap.containsKey(this))
		return varMap.get(this);
	// otherwise add it
	int next = varMap.size() + 1;
	varMap.put(this, next);
	return next;
}
 
Example 13
Source File: OfflineViewParseUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Map<String, Set<OfflineProblemDescriptor>> parse(VirtualFile file) {
  final TObjectIntHashMap<String> fqName2IdxMap = new TObjectIntHashMap<>();
  final Map<String, Set<OfflineProblemDescriptor>> package2Result = new THashMap<>();
  try {
    Element rootElement = JDOMUtil.load(VfsUtil.virtualToIoFile(file));
    for (Element problemElement : rootElement.getChildren()) {
      final OfflineProblemDescriptor descriptor = new OfflineProblemDescriptor();
      boolean added = false;

      for (Element childElement : problemElement.getChildren()) {
        String chilName = childElement.getName();

        switch (chilName) {
          case SmartRefElementPointerImpl.ENTRY_POINT:
            descriptor.setType(childElement.getAttributeValue(SmartRefElementPointerImpl.TYPE_ATTR));
            final String fqName = childElement.getAttributeValue(SmartRefElementPointerImpl.FQNAME_ATTR);
            descriptor.setFQName(fqName);

            if (!fqName2IdxMap.containsKey(fqName)) {
              fqName2IdxMap.put(fqName, 0);
            }
            int idx = fqName2IdxMap.get(fqName);
            descriptor.setProblemIndex(idx);
            fqName2IdxMap.put(fqName, idx + 1);

            final List<String> parentTypes = new ArrayList<>();
            final List<String> parentNames = new ArrayList<>();

            for (Element element : childElement.getChildren()) {
              parentTypes.add(element.getAttributeValue(SmartRefElementPointerImpl.TYPE_ATTR));
              parentNames.add(element.getAttributeValue(SmartRefElementPointerImpl.FQNAME_ATTR));
            }

            if (!parentTypes.isEmpty() && !parentNames.isEmpty()) {
              descriptor.setParentType(ArrayUtil.toStringArray(parentTypes));
              descriptor.setParentFQName(ArrayUtil.toStringArray(parentNames));
            }
            break;
          case DESCRIPTION:
            descriptor.setDescription(childElement.getText());
            break;
          case LINE:
            descriptor.setLine(Integer.parseInt(childElement.getText()));
            break;
          case MODULE:
            descriptor.setModule(childElement.getText());
            break;
          case HINTS:
            for (Element hintElement : childElement.getChildren()) {
              List<String> hints = descriptor.getHints();
              if (hints == null) {
                hints = new ArrayList<>();
                descriptor.setHints(hints);
              }
              hints.add(hintElement.getAttributeValue("value"));
            }
            break;
          case PACKAGE:
            appendDescriptor(package2Result, childElement.getText(), descriptor);
            added = true;
            break;
          default:
            for (Element nextElement : childElement.getChildren()) {
              if (PACKAGE.equals(nextElement.getName())) {
                appendDescriptor(package2Result, nextElement.getText(), descriptor);
                added = true;
              }
            }
            break;
        }
      }

      if (!added) appendDescriptor(package2Result, "", descriptor);
    }
  }
  catch (Exception e) {
    LOGGER.error(e);
  }
  return package2Result;
}