Java Code Examples for java.util.Collection#addAll()

The following examples show how to use java.util.Collection#addAll() . 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: Code.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void visitRefs(int mode, Collection<ConstantPool.Entry> refs) {
    int verbose = getPackage().verbose;
    if (verbose > 2)
        System.out.println("Reference scan "+this);
    refs.addAll(Arrays.asList(handler_class));
    if (fixups != null) {
        fixups.visitRefs(refs);
    } else {
        // References (to a local cpMap) are embedded in the bytes.
        ConstantPool.Entry[] cpMap = getCPMap();
        for (Instruction i = instructionAt(0); i != null; i = i.next()) {
            if (verbose > 4)
                System.out.println(i);
            int cpref = i.getCPIndex();
            if (cpref >= 0) {
                refs.add(cpMap[cpref]);
            }
        }
    }
    // Handle attribute list:
    super.visitRefs(mode, refs);
}
 
Example 2
Source File: Defaults.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "MergeCases", parallel = true)
public Iterator<Object[]> mergeCasesProvider() {
    Collection<Object[]> cases = new ArrayList<>();

    cases.addAll(makeMergeTestCases());

    return cases.iterator();
}
 
Example 3
Source File: ChangeTypeRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gather constraints associated with a set of compilation units.
 * @param referringCus
 * @param pm
 * @return the constraints
 */
private Collection<ITypeConstraint> getConstraints(ICompilationUnit[] referringCus, IProgressMonitor pm) {
	pm.beginTask(RefactoringCoreMessages.ChangeTypeRefactoring_analyzingMessage, referringCus.length);
	Collection<ITypeConstraint> result= new ArrayList<ITypeConstraint>();
	for (int i= 0; i < referringCus.length; i++) {
		result.addAll(getConstraints(referringCus[i]));
		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();
	}
	pm.done();
	return result;
}
 
Example 4
Source File: DesktopTelephonySupport.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void disconnect(final ConnectionInformation client) {
    active = false;
    synchronized (listener) {
        final Collection<TelephonyListener> copy =
                new java.util.ArrayList<TelephonyListener>();
        copy.addAll(listener);
        final TelephonyEvent event = new TelephonyEvent(this,
                TelephonyEvent.HUNGUP);
        for (TelephonyListener current : copy) {
            current.telephonyCallHungup(event);
        }
    }
}
 
Example 5
Source File: Bootstrap.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
public static Collection<Operation> findAllOperations(Schema schema) {
    Collection<Operation> operations = new ArrayList<>();
    operations.addAll(schema.getQueries());
    operations.addAll(schema.getMutations());

    for (final Type value : schema.getTypes().values()) {
        operations.addAll(value.getOperations());
    }

    return operations;
}
 
Example 6
Source File: ConcurrentCollectionWrapper.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Removes 'value' from wrapped collection. Replacing this collection instance for ArrayList from
 * CompactHashSet.
 *
 * @return {@code true} if the collection was modified; {@code false} if the set collection not
 *     modified
 */
public synchronized boolean remove(T value) {

  Collection<T> collection = this.collection;
  if (collection == null) {
    // null
    return false;
  }

  int previousSize = collection.size();
  if (previousSize == 1) {
    if (collection.contains(value)) {
      // -> null
      this.collection = null;
      return true;
    } else {
      return false;
    }
  }
  // now remove the value
  if (collection.remove(value)) {
    // may need to change representation
    if (previousSize == 2) {
      // -> SingletonList
      List<T> list = Collections.singletonList(collection.iterator().next());
      this.collection = list;
      return true;
    } else if (previousSize == 1 + ARRAYLIST_THRESHOLD) {
      // -> ArrayList
      Collection<T> newArrayList = new ArrayList<>(ARRAYLIST_THRESHOLD);
      newArrayList.addAll(collection);
      this.collection = newArrayList;
      return true;
    }
    return true;
  }
  return false;
}
 
Example 7
Source File: Defaults.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Collection<Object[]> makeAllMapsWithNulls() {
    Collection<Object[]> all = new ArrayList<>();

    all.addAll(makeROMaps(true));
    all.addAll(makeRWMaps(true,true));

    return all;
}
 
Example 8
Source File: ForeachLoops.java    From swift-t with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Var> requiredVars(boolean forDeadCodeElim) {
  Collection<Var> res = new ArrayList<Var>();
  res.add(container);
  res.addAll(abstractForeachRequiredVars(forDeadCodeElim));
  return res;
}
 
Example 9
Source File: CSSTaskDetector.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method for detecting tasks in the root of a CSS AST. This is public for the HTML task detector to be able to
 * delegate to this for CSS as a sub-language.
 */
public Collection<IProblem> detectTasks(IParseRootNode rootNode, BuildContext context, IProgressMonitor monitor)
{
	if (context == null || rootNode == null)
	{
		return Collections.emptyList();
	}

	IParseNode[] comments = rootNode.getCommentNodes();
	if (ArrayUtil.isEmpty(comments))
	{
		return Collections.emptyList();
	}

	SubMonitor sub = SubMonitor.convert(monitor, comments.length);
	Collection<IProblem> tasks = new ArrayList<IProblem>(comments.length);
	try
	{
		String source = context.getContents();
		String filePath = context.getURI().toString();

		for (IParseNode commentNode : comments)
		{
			if (commentNode instanceof CSSCommentNode)
			{
				tasks.addAll(processCommentNode(filePath, source, 0, commentNode, COMMENT_ENDING));
			}
			sub.worked(1);
		}
	}
	finally
	{
		sub.done();
	}
	return tasks;
}
 
Example 10
Source File: MustFightBattle.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void unitsLostInPrecedingBattle(
    final Collection<Unit> units, final IDelegateBridge bridge, final boolean withdrawn) {
  Collection<Unit> lost = new ArrayList<>(getDependentUnits(units));
  lost.addAll(CollectionUtils.intersection(units, attackingUnits));
  // if all the amphibious attacking land units are lost, then we are no longer a naval invasion
  amphibiousLandAttackers.removeAll(lost);
  if (amphibiousLandAttackers.isEmpty()) {
    isAmphibious = false;
    bombardingUnits.clear();
  }
  attackingUnits.removeAll(lost);
  // now that they are definitely removed from our attacking list, make sure that they were not
  // already removed from
  // the territory by the previous battle's remove method
  lost = CollectionUtils.getMatches(lost, Matches.unitIsInTerritory(battleSite));
  if (!withdrawn) {
    remove(lost, bridge, battleSite, false);
  }
  if (attackingUnits.isEmpty()) {
    final IntegerMap<UnitType> costs = TuvUtils.getCostsForTuv(attacker, gameData);
    final int tuvLostAttacker =
        (withdrawn ? 0 : TuvUtils.getTuv(lost, attacker, costs, gameData));
    attackerLostTuv += tuvLostAttacker;
    whoWon = WhoWon.DEFENDER;
    if (!headless) {
      battleTracker
          .getBattleRecords()
          .addResultToBattle(
              attacker,
              battleId,
              defender,
              attackerLostTuv,
              defenderLostTuv,
              BattleRecord.BattleResultDescription.LOST,
              new BattleResults(this, gameData));
    }
    battleTracker.removeBattle(this, gameData);
  }
}
 
Example 11
Source File: DecodeThread.java    From CodeScaner with MIT License 5 votes vote down vote up
DecodeThread(CaptureActivity activity,
             Collection<BarcodeFormat> decodeFormats,
             Map<DecodeHintType,?> baseHints,
             String characterSet,
             ResultPointCallback resultPointCallback) {

  this.activity = activity;
  handlerInitLatch = new CountDownLatch(1);

  hints = new EnumMap<>(DecodeHintType.class);
  if (baseHints != null) {
    hints.putAll(baseHints);
  }

  // The prefs can't change while the thread is running, so pick them up once here.
  if (decodeFormats == null || decodeFormats.isEmpty()) {
      decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
      decodeFormats.addAll(DecodeFormatManager.PRODUCT_FORMATS);
      decodeFormats.addAll(DecodeFormatManager.INDUSTRIAL_FORMATS);
      decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
      decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
      decodeFormats.addAll(DecodeFormatManager.AZTEC_FORMATS);
      decodeFormats.addAll(DecodeFormatManager.PDF417_FORMATS);
  }
  hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

  if (characterSet != null) {
    hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  }
  hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
  Log.i("DecodeThread", "Hints: " + hints);
}
 
Example 12
Source File: BpmnMessageFlow.java    From codebase with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Collection<IDataNode> getReadWriteDocuments() {
	Collection<IDataNode> result = new ArrayList<IDataNode>();
	result.addAll(this.readDocuments);
	result.retainAll(this.writeDocuments);
	return result;
}
 
Example 13
Source File: Defaults.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Collection<Object[]> makeRWMapsNoNulls() {
    Collection<Object[]> all = new ArrayList<>();

    all.addAll(makeRWNoNullKeysMaps(false));
    all.addAll(makeRWNoNullsMaps());

    return all;
}
 
Example 14
Source File: SpawnInputExpanderTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunfilesWithTreeArtifactsInSymlinks() throws Exception {
  SpecialArtifact treeArtifact = createTreeArtifact("treeArtifact");
  assertThat(treeArtifact.isTreeArtifact()).isTrue();
  TreeFileArtifact file1 = TreeFileArtifact.createTreeOutput(treeArtifact, "file1");
  TreeFileArtifact file2 = TreeFileArtifact.createTreeOutput(treeArtifact, "file2");
  FileSystemUtils.writeContentAsLatin1(file1.getPath(), "foo");
  FileSystemUtils.writeContentAsLatin1(file2.getPath(), "bar");
  Runfiles runfiles =
      new Runfiles.Builder("workspace")
          .addSymlink(PathFragment.create("symlink"), treeArtifact)
          .build();

  ArtifactExpander artifactExpander =
      (Artifact artifact, Collection<? super Artifact> output) -> {
        if (artifact.equals(treeArtifact)) {
          output.addAll(Arrays.asList(file1, file2));
        }
      };
  RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
  FakeActionInputFileCache fakeCache = new FakeActionInputFileCache();
  fakeCache.put(file1, FileArtifactValue.createForTesting(file1));
  fakeCache.put(file2, FileArtifactValue.createForTesting(file2));

  expander.addRunfilesToInputs(inputMappings, supplier, fakeCache, artifactExpander, true);
  assertThat(inputMappings).hasSize(2);
  assertThat(inputMappings)
      .containsEntry(PathFragment.create("runfiles/workspace/symlink/file1"), file1);
  assertThat(inputMappings)
      .containsEntry(PathFragment.create("runfiles/workspace/symlink/file2"), file2);
}
 
Example 15
Source File: DoubleKeyValueMap.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public Collection<V> getAllValues() {
    Collection<V> result = null;
    Set<K1> k1Set = k1_k2V_map.keySet();
    if (k1Set != null) {
        result = new ArrayList<V>();
        for (K1 k1 : k1Set) {
            Collection<V> values = k1_k2V_map.get(k1).values();
            if (values != null) {
                result.addAll(values);
            }
        }
    }
    return result;
}
 
Example 16
Source File: CSharpNameSuggesterUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static Collection<String> getSuggestedVariableNames(final DotNetVariable variable)
{
	PsiElement parent = variable.getParent();

	Collection<String> suggestedNames = null;
	if(parent instanceof CSharpForeachStatementImpl)
	{
		DotNetExpression iterableExpression = ((CSharpForeachStatementImpl) parent).getIterableExpression();
		if(iterableExpression != null)
		{
			suggestedNames = getSuggestedNames(iterableExpression, Collections.emptyList(), variable);
		}
	}

	if(suggestedNames == null)
	{
		if(variable.toTypeRef(false) == DotNetTypeRef.AUTO_TYPE)
		{
			suggestedNames = ContainerUtil.newArrayList("v");
		}
		else
		{
			suggestedNames = getSuggestedNames(variable.toTypeRef(true), variable);
		}
	}

	DotNetExpression initializer = variable.getInitializer();
	if(initializer != null)
	{
		suggestedNames.addAll(getSuggestedNames(initializer, suggestedNames, variable));
	}

	if(variable instanceof CSharpPropertyDeclaration)
	{
		suggestedNames = ContainerUtil.map(suggestedNames, StringUtil::capitalize);
	}

	CSharpCodeGenerationSettings settings = CSharpCodeGenerationSettings.getInstance(variable.getProject());

	boolean isStatic = variable.hasModifier(DotNetModifier.STATIC);
	final String prefix;
	final String suffix;
	if(variable instanceof CSharpPropertyDeclaration)
	{
		prefix = isStatic ? settings.STATIC_PROPERTY_PREFIX : settings.PROPERTY_PREFIX;
		suffix = isStatic ? settings.STATIC_PROPERTY_SUFFIX : settings.PROPERTY_PREFIX;
	}
	else if(variable instanceof CSharpFieldDeclaration)
	{
		prefix = isStatic ? settings.STATIC_FIELD_PREFIX : settings.FIELD_PREFIX;
		suffix = isStatic ? settings.STATIC_FIELD_SUFFIX : settings.FIELD_SUFFIX;
	}
	else
	{
		prefix = null;
		suffix = null;
	}

	return ContainerUtil.map(suggestedNames, name ->
	{
		if(prefix == null && suffix == null)
		{
			return name;
		}
		if(StringUtil.isEmpty(prefix))
		{
			return name + StringUtil.notNullize(suffix);
		}
		return StringUtil.notNullize(prefix) + StringUtil.capitalize(name) + StringUtil.notNullize(suffix);
	});
}
 
Example 17
Source File: BundleClassLoader.java    From AtlasForAndroid with MIT License 4 votes vote down vote up
protected Enumeration<URL> findResources(String str) {
    String stripTrailing = stripTrailing(str);
    Collection findOwnResources = findOwnResources(stripTrailing, true);
    findOwnResources.addAll(findImportedResources(stripTrailing, true));
    return Collections.enumeration(findOwnResources);
}
 
Example 18
Source File: TypesRegistry.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public Collection<TClass> getTypeClasses() {
    Collection<TClass> result = new ArrayList<>();
    for (BundleEntry entry : bundlesByName.values())
        result.addAll(entry.typeClassByName.values());
    return result;
}
 
Example 19
Source File: AbstractPlaceDelegate.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void updateProducedMap(
    final Territory producer, final Collection<Unit> additionallyProducedUnits) {
  final Collection<Unit> newProducedUnits = getAlreadyProduced(producer);
  newProducedUnits.addAll(additionallyProducedUnits);
  produced.put(producer, newProducedUnits);
}
 
Example 20
Source File: IssuesTest.java    From scheduler with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public static void testIssue89() throws Exception {
    final Model model = new DefaultModel();
    final Mapping mapping = model.getMapping();

    final Node node0 = model.newNode(0);
    final int[] ids0 = {1, 45, 43, 40, 39, 38, 82, 80, 79, 78, 30, 75, 18, 16, 15, 14, 60, 9, 55, 54, 50, 48};
    final Node node1 = model.newNode(1);
    final int[] ids1 = {84, 83, 81, 77, 73, 71, 64, 63, 62, 57, 53, 52, 47, 46, 44, 41, 34, 31, 28, 25, 13, 8, 6, 4, 3, 0};
    final Node node2 = model.newNode(2);
    final int[] ids2 = {21, 67, 42, 36, 35, 33, 76, 74, 23, 69, 68, 20, 61, 12, 11, 10, 5, 51};
    final Node node3 = model.newNode(3);
    final int[] ids3 = {2, 66, 86, 85, 37, 32, 29, 27, 26, 72, 24, 70, 22, 19, 65, 17, 59, 58, 56, 7, 49};

    final ShareableResource cpu = new ShareableResource("cpu", 45, 1);
    final ShareableResource mem = new ShareableResource("mem", 90, 2);

    populateNodeVm(model, mapping, node0, ids0);
    populateNodeVm(model, mapping, node1, ids1);
    populateNodeVm(model, mapping, node2, ids2);
    populateNodeVm(model, mapping, node3, ids3);
    model.attach(cpu);
    model.attach(mem);

    final Collection<SatConstraint> satConstraints =
            new ArrayList<>();
    // We want to cause Node 3 to go offline to see how the VMs hosted on that
    // node will get rebalanced.
    satConstraints.add(new Offline(node3));
    final OptConstraint optConstraint = new MinMTTR();
    DefaultChocoScheduler scheduler = new DefaultChocoScheduler();
    scheduler.doOptimize(false);
    scheduler.doRepair(true);
    scheduler.setTimeLimit(60000);
    ReconfigurationPlan plan = scheduler.solve(
            model, satConstraints, optConstraint);
    System.out.println(scheduler.getStatistics());
    Assert.assertTrue(plan.isApplyable());


    satConstraints.clear();
    // This is somewhat similar to making Node 3 going offline by ensuring that
    // all VMs can no longer get hosted on that node.
    satConstraints.addAll(mapping.getAllVMs().stream().map(vm -> new Ban(vm, Collections.singletonList(node3))).collect(Collectors.toList()));

    scheduler = new DefaultChocoScheduler();
    scheduler.doOptimize(false);
    scheduler.doRepair(true);
    plan = scheduler.solve(model, satConstraints, optConstraint);
    Assert.assertTrue(plan.isApplyable());
}