Java Code Examples for java.util.Collection

The following are top voted examples for showing how to use java.util.Collection. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: jentrata-msh   File: FileSystem.java View source code Vote up 6 votes
/**
 * Retrieves a collection of File objects from a specified directory.
 * 
 * @param c the collection into which the result will be stored.
 * @param rootDir the directory to be searched.
 * @param isRecursive true if the search should be recursive.
 * @param type the file type to be searched.
 * @param pattern the filename's pattern for filtering the result. null if
 *            no filtering should be applied.
 * @return a collection of File objects resulted from the search.
 */
private Collection getFiles(Collection c, File rootDir,
        boolean isRecursive, int type, String pattern) {
    File[] subfiles = rootDir.listFiles();
    if (subfiles == null || subfiles.length == 0) {
        return Collections.EMPTY_LIST;
    }
    else {
        if (c == null) {
            c = new ArrayList();
        }
        for (int i = 0; i < subfiles.length; i++) {
            if (subfiles[i].isDirectory()) {
                if ((TYPE_DIR & type) == TYPE_DIR) {
                    if (accept(subfiles[i], pattern)) {
                        c.add(subfiles[i]);
                    }
                }
                if (isRecursive) {
                    getFiles(c, subfiles[i], isRecursive, type, pattern);
                }
            }
            else {
                if ((TYPE_FILE & type) == TYPE_FILE) {
                    if (accept(subfiles[i], pattern)) {
                        c.add(subfiles[i]);
                    }
                }
            }
        }
        return c;
    }
}
 
Example 2
Project: jentrata-msh   File: ModuleInfoPageletAdaptor.java View source code Vote up 6 votes
private void printModuleGroups(PropertyTree dom, ModuleGroup group, String level, int position) {
    level += "module-group" + (position>1? "["+position+"]/":"/");
    Collection groups = group.getChildren();
    dom.setProperty(level+"name", group.getName());
    dom.setProperty(level+"sysmodule", group.getSystemModule()==null? "No system module":group.getSystemModule().getName());
    Iterator subgroups = groups.iterator();
    for (int i=1; subgroups.hasNext(); i++) {
        printModuleGroups(dom, (ModuleGroup) subgroups.next(), level, i);
    }
}
 
Example 3
Project: sphereMiners   File: SphereMiners2015.java View source code Vote up 6 votes
/**
 * Splits the given (own) sphere to two equally (half) sized ones. This works
 * only if the maximal amount of spheres at the same time is not already reached
 * and will not be overflown with the given map of spheres to be splitted.
 * Otherwise this will simply do nothing.
 *
 * Execution order of merging, splitting and changing direction is at first
 * mine, then merge, then split and then change directions. All steps are
 * independant and need not to be set in every turn. Also splitting can not
 * be done on just merged spheres, as well as new spheres (by splitting)
 * cannot change direction in this turn.
 *
 * @param spheres The spheres you want to split into two parts
 */
protected final void split(Collection<Sphere> spheres) {
    Stream<Sphere> tmp = spheres.stream().filter(s -> ownSpheres.contains(s));

    if (ownSpheres.size() + spheres.size() <= constants.getMaxSphereAmount()) {
        // lists cannot be changed directly therefore we need the phyiscsmanager here
        currentSplit = () -> tmp.forEach(s -> physics.split(s));
    }
}
 
Example 4
Project: jboss-dmr   File: ExpressionValueTest.java View source code Vote up 6 votes
/**
 * Find the first defined System.getenv() environment variable with a non-zero length value.
 * @return [0] = env var name prefixed with "env."
 *  [1] = env var value. If [0].length == 0, then there
 *  were no environment variables defined.
 */
private static String[] findEnvVar() {
    String[] pair = {"", null};
    Collection<String> envvars = System.getenv().keySet();
    if (envvars.isEmpty()) {
        return pair;
    }
    for(final String envvar : envvars) {
        final String envvarValue = System.getenv(envvar);
        if (envvarValue != null && envvarValue.length() > 0) {
            // Change name to env.name
            pair[0] = "env." + envvar;
            pair[1] = envvarValue;
            break;
        }
    }
    return pair;
}
 
Example 5
Project: aws-toolkit-eclipse   File: AwsAccountPreferencePageTab.java View source code Vote up 6 votes
/**
 * Set the input data for the account selector combo and also set the
 * selection to the specified AccountInfo object.
 */
private void setUpAccountSelectorItems(Collection<AccountInfo> allAccounts,
        AccountInfo selectedAccount) {
    accountSelector.setInput(allAccounts);

    // If the given account is not found, then select the first element
    if ( !allAccounts.contains(selectedAccount) ) {
        selectedAccount = allAccounts.iterator().next();
    }

    accountSelector.setSelection(new StructuredSelection(selectedAccount),
            true); // visible=true

    // TODO: copied from the existing code, not sure why it's necessary
    accountSelector.getCombo().getParent().getParent().layout();
}
 
Example 6
Project: richfaces   File: MultipartRequest25.java View source code Vote up 6 votes
public Object apply(Collection<String> input) {
    if (input.isEmpty()) {
        return null;
    }

    if (input.size() == 1) {
        return Iterables.get(input, 0);
    }

    return input.toArray(new String[input.size()]);
}
 
Example 7
Project: lettuce   File: RedisChannelHandler.java View source code Vote up 6 votes
/**
 * Register Closeable resources. Internal access only.
 * 
 * @param registry registry of closeables
 * @param closeables closeables to register
 */
public void registerCloseables(final Collection<Closeable> registry, final Closeable... closeables) {
    registry.addAll(Arrays.asList(closeables));

    addListener(new CloseEvents.CloseListener() {
        @Override
        public void resourceClosed(Object resource) {
            for (Closeable closeable : closeables) {
                if (closeable == RedisChannelHandler.this) {
                    continue;
                }

                try {
                    closeable.close();
                } catch (IOException e) {
                    logger.debug(e.toString(), e);
                }
            }

            registry.removeAll(Arrays.asList(closeables));
        }
    });
}
 
Example 8
Project: richfaces   File: SortingFilteringRowsRenderer.java View source code Vote up 6 votes
protected void decodeSorting(FacesContext context, UIDataTableBase dataTableBase, String value) {
    Set<Object> sortPriority = new LinkedHashSet<Object>();

    String[] values = value.split(SEPARATOR);
    String columnId = values[0];
    String sortOrder = values[1];
    boolean isClear = Boolean.parseBoolean(values[2]);

    if (isClear || SortMode.single.equals(dataTableBase.getSortMode())) {
        for (Iterator<UIComponent> iterator = dataTableBase.columns(); iterator.hasNext();) {
            UIComponent column = iterator.next();
            if (columnId.equals(column.getId())) {
                updateSortOrder(context, column, sortOrder);
                sortPriority.add(columnId);
            } else {
                updateAttribute(context, column, SORT_ORDER_STRING, SortOrder.unsorted);
            }
        }
    } else {
        updateSortOrder(context, dataTableBase.findComponent(columnId), sortOrder);
        Collection<?> priority = dataTableBase.getSortPriority();
        if (priority != null) {
            priority.remove(columnId);
            sortPriority.addAll(priority);
        }
        sortPriority.add(columnId);
    }
    updateAttribute(context, dataTableBase, SORT_PRIORITY_STRING, sortPriority);
    context.getPartialViewContext().getRenderIds().add(dataTableBase.getSortingAndFilteringRenderTargetId(context));
}
 
Example 9
Project: lettuce   File: ClusterNodeCommandHandler.java View source code Vote up 6 votes
/**
 * Retrieve commands within a lock to prevent concurrent modification
 */
private Collection<RedisCommand<K, V, ?>> shiftCommands(Collection<RedisCommand<K, V, ?>> source) {
    try {
        writeLock.lock();
        try {
            return Lists.newArrayList(source);
        } finally {
            source.clear();
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example 10
Project: goworks   File: SemanticHighlighter.java View source code Vote up 6 votes
@Override
protected void updateHighlights(OffsetsBag targetContainer, DocumentSnapshot sourceSnapshot, DocumentSnapshot currentSnapshot, SemanticAnalyzerListener listener) {
    List<Tuple2<OffsetRegion, AttributeSet>> intermediateContainer = new ArrayList<>();
    resolvedTokens.clear();

    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getPackageDeclarations(), packageDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getPackageUses(), packageUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getGlobalConstDeclarations(), globalConstDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getGlobalConstUses(), globalConstUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getLocalConstDeclarations(), localConstDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getLocalConstUses(), localConstUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getFuncDeclarations(), funcDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getFuncUses(), funcUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getMethodDeclarations(), methodDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getMethodUses(), methodUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getTypeDeclarations(), typeDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getTypeUses(), typeUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getStructDeclarations(), structDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getStructUses(), structUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getInterfaceDeclarations(), interfaceDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getInterfaceUses(), interfaceUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getBuiltinTypeUses(), builtinTypeUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getBuiltinConstUses(), builtinConstUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getBuiltinFunctionUses(), builtinFunctionUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getParameterDeclarations(), parameterDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getParameterUses(), parameterUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getReturnParameterDeclarations(), returnParameterDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getReturnParameterUses(), returnParameterUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getVarUses(), varUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getGlobalVarDeclarations(), globalVarDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getGlobalVarUses(), globalVarUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getFieldVarDeclarations(), fieldVarDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getFieldVarUses(), fieldVarUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getLocalVarDeclarations(), localVarDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getLocalVarUses(), localVarUseAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getLabelDeclarations(), labelDeclarationAttributes);
    addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, listener.getLabelUses(), labelUseAttributes);

    if (LOGGER.isLoggable(Level.FINE)) {
        Collection<Token> unresolved = listener.getUnresolvedIdentifiers();
        unresolved.removeAll(resolvedTokens);
        addHighlights(intermediateContainer, sourceSnapshot, currentSnapshot, unresolved, unresolvedIdentifierAttributes);
    }

    OffsetsBag container = new OffsetsBag(currentSnapshot.getVersionedDocument().getDocument());
    fillHighlights(container, intermediateContainer);
    targetContainer.setHighlights(container);
}
 
Example 11
Project: jena   File: TransformFilterPlacement.java View source code Vote up 6 votes
private Placement placeJoin(ExprList exprs, OpJoin opJoin) {
    Op left = opJoin.getLeft() ;
    Op right = opJoin.getRight() ;
    Collection<Var> leftVars = fixedVars(left) ;
    Collection<Var> rightVars = fixedVars(right) ;
    ExprList unpushed = new ExprList() ;
    ExprList pushLeft = new ExprList() ;
    ExprList pushRight = new ExprList() ;

    for (Expr expr : exprs) {
        Set<Var> vars = expr.getVarsMentioned() ;
        boolean pushed = false ;

        if ( leftVars.containsAll(vars) ) {
            pushLeft.add(expr) ;
            pushed = true ;
        }
        
        if ( pushed && ! pushRightAsWellAsLeft )
            continue ;
        // If left only, make this "else if" of left test, remove "continue" 
        if ( rightVars.containsAll(vars) ) {
            // Push right
            pushRight.add(expr) ;
            pushed = true ;
        }

        if ( !pushed )
            unpushed.add(expr) ;
    }

    if ( pushLeft.isEmpty() && pushRight.isEmpty() )
        return null ;

    Op opLeftNew = left ;
    if ( !pushLeft.isEmpty() )
        opLeftNew = transformOpAlways(pushLeft, opLeftNew) ;

    Op opRightNew = right ;
    if ( !pushRight.isEmpty() )
        opRightNew = transformOpAlways(pushRight, opRightNew) ;

    Op op = OpJoin.create(opLeftNew, opRightNew) ;
    return result(op, unpushed) ;
}
 
Example 12
Project: TinyProtocolAPI   File: PacketCover.java View source code Vote up 6 votes
public void handleAll() {
	Collection<? extends Player> players = Bukkit.getOnlinePlayers();
	synchronized (players) {
		players.forEach(this::handle);
	}
	return;
}
 
Example 13
Project: android-essentials-toolbox   File: SanityChecks.java View source code Vote up 6 votes
@Test
public void testPermissionsAreNotDocumentedAndUndocumented() {
	Collection<Permission> intersection = Permission.getAllDocumentedPermissions();
	intersection.retainAll(Permission.getAllUndocumentedPermissions());
	if(!intersection.isEmpty()){
		System.err.println("The following permissions are classified as both documented and undocumented!\n" + intersection);
	}
	assertTrue(intersection.isEmpty());
}
 
Example 14
Project: k3po   File: AstUtil.java View source code Vote up 6 votes
public static boolean equivalent(Collection<?> c, Collection<?> c2) {
    if (c != null && c.isEmpty()) {
        c = null;
    }
    if (c2 != null && c2.isEmpty()) {
        c2 = null;
    }
    return c == c2 || (c != null && c.equals(c2));
}
 
Example 15
Project: R5A   File: LogootEngine.java View source code Vote up 6 votes
@Override
public String generatePatchFromModel() {
  Collection<IOperation> patch = new ArrayList<IOperation>();

  int i = 0;
  while (i < idTable.size()) {
    IOperation op = Operation.insertOperation(idTable.get(i),
        currentText.charAt(i));
    patch.add(op);
    ++i;
  }

  return patch.toString();
}
 
Example 16
Project: VaadinUtils   File: TwinColumnSearchableSelect.java View source code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
protected void setInternalValue(Collection<C> newValue)
{
	if (newValue != null)
	{
		valueClass = newValue.getClass();
	}
	super.setInternalValue(newValue);

	beans.removeAllItems();
	if (newValue != null)
	{
		beans.addAll(newValue);
	}
	sourceValue = (Collection<C>) getConvertedValue();
	beans.sort(new Object[]
	{ listField.getName() }, new boolean[]
	{ isAscending });
}