Java Code Examples for com.intellij.util.containers.ContainerUtil#getOrCreate()

The following examples show how to use com.intellij.util.containers.ContainerUtil#getOrCreate() . 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: HaskellParserWrapper.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Increases how many synthetic rbraces the remapper should consume.
 */
boolean increaseRbraceDebt(int offset) {
    if (maxRbraceDebt < 1) return false;

    Pair<Integer,Integer> oldValue = ContainerUtil.getOrCreate(debtPoints, offset, INIT_KEY);
    Pair<Integer,Integer> newValue;

    Integer snd = oldValue.getSecond();

    if (oldValue.getFirst() == 0) {
        newValue = Pair.create(maxRbraceDebt, maxRbraceDebt - 1);
    } else {
        newValue = Pair.create(oldValue.getFirst(), --snd);
    }
    rbraceDebt++;
    maxRbraceDebt--;
    debtPoints.put(offset, newValue);
    return true;
}
 
Example 2
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 3
Source File: MessageCounter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public synchronized void remove(@Nullable final String groupName,
                                @Nonnull final NotificationSource notificationSource,
                                @Nonnull final ProjectSystemId projectSystemId) {
  final Map<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>> groupMap =
          ContainerUtil.getOrCreate(
                  map,
                  projectSystemId,
                  ContainerUtil.<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>>newHashMap());
  if (groupName != null) {
    final TObjectIntHashMap<NotificationCategory> counter = ContainerUtil.getOrCreate(
            ContainerUtil.getOrCreate(
                    groupMap,
                    groupName,
                    ContainerUtil.<NotificationSource, TObjectIntHashMap<NotificationCategory>>newHashMap()
            ),
            notificationSource,
            new TObjectIntHashMap<NotificationCategory>()
    );
    counter.clear();
  }
  else {
    for (Map<NotificationSource, TObjectIntHashMap<NotificationCategory>> sourceMap : groupMap.values()) {
      sourceMap.remove(notificationSource);
    }
  }
}
 
Example 4
Source File: ProjectInfo.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to get a distribution by target type.
 */
public Map<String, Integer> getTargetsDistribution() {
  final Map<String, Integer> result = new HashMap<>();
  for (TargetInfo targetInfo : targets.values()) {
    for (TargetAddressInfo addressInfo : targetInfo.getAddressInfos()) {
      final String type = addressInfo.getInternalPantsTargetType();
      final int currentValue = ContainerUtil.getOrCreate(result, type, 0);
      result.put(type, currentValue + 1);
    }
  }
  return result;
}
 
Example 5
Source File: CSharpPartialElementManager.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
public CSharpTypeDeclaration getOrCreateCompositeType(@Nonnull final GlobalSearchScope scope, @Nonnull final String vmQName, @Nonnull final Collection<CSharpTypeDeclaration> typeDeclarations)
{
	Map<String, CSharpTypeDeclaration> scopeMap = ContainerUtil.getOrCreate(myCache, scope, (Factory<Map<String, CSharpTypeDeclaration>>) ContainerUtil::createConcurrentWeakValueMap);

	return ContainerUtil.getOrCreate(scopeMap, vmQName, (Factory<CSharpTypeDeclaration>) () -> new CSharpCompositeTypeDeclaration(myProject, scope, ContainerUtil.toArray(typeDeclarations,
			CSharpTypeDeclaration.ARRAY_FACTORY)));
}
 
Example 6
Source File: PostfixTemplatesSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void disableTemplate(PostfixTemplate template, String langForProvider) {
  Set<String> state = ContainerUtil.getOrCreate(myLangToDisabledTemplates, langForProvider, (Factory<Set<String>>)ContainerUtil::newHashSet);
  state.add(template.getKey());
}
 
Example 7
Source File: PostfixTemplatesSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void enableTemplate(PostfixTemplate template, String langForProvider) {
  Set<String> state = ContainerUtil.getOrCreate(myLangToDisabledTemplates, langForProvider, (Factory<Set<String>>)ContainerUtil::newHashSet);
  state.remove(template.getKey());
}