Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

In this page you can find the example usage for java.util List clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:com.conversantmedia.mapreduce.tool.RunJob.java

/**
 * Outputs the driver's list/*from  ww  w  .  j  a va 2s  .  co m*/
 * 
 * @param driversMap   map of driver metadata to output to console
 */
protected static void outputDriversTable(Map<String, DriverMeta> driversMap) {

    String[] colNames = new String[] { "Name", "Description", "Ver", "Class" };
    String[] aligns = new String[] { "-", "-", "-", "-" };
    int maxDescriptionWidth = 48;
    int widths[] = new int[colNames.length];
    for (int i = 0; i < colNames.length; i++) {
        widths[i] = colNames[i].length();
    }
    int padding = 2;
    for (Entry<String, DriverMeta> e : driversMap.entrySet()) {
        if (!e.getValue().hidden) {
            int i = 0;
            widths[i] = Math.max(e.getKey().length(), widths[i]);
            widths[i + 1] = Math.min(Math.max(e.getValue().description.length(), widths[i + 1]),
                    maxDescriptionWidth);
            widths[i + 2] = Math.max(e.getValue().version.length(), widths[i + 2]);
            widths[i + 3] = Math.max(e.getValue().driverClass.getName().length(), widths[i + 3]);
        }
    }

    // sum widths
    int width = padding * widths.length - 1;
    for (int w : widths) {
        width += w;
    }

    String sep = StringUtils.repeat("=", width);
    System.out.println(sep);
    System.out.println(StringUtils.center("A V A I L A B L E    D R I V E R S", width));
    System.out.println(sep);
    String[] underscores = new String[colNames.length];
    StringBuilder headersFormatSb = new StringBuilder();
    StringBuilder valuesFormatSb = new StringBuilder();
    for (int i = 0; i < widths.length; i++) {
        headersFormatSb.append("%-").append(widths[i] + padding).append("s");
        valuesFormatSb.append("%").append(aligns[i]).append(widths[i] + padding).append("s");
        underscores[i] = StringUtils.repeat("-", widths[i]);
    }
    String format = headersFormatSb.toString();
    System.out.format(format, (Object[]) colNames);
    System.out.println();
    System.out.format(format, (Object[]) underscores);
    System.out.println();

    format = valuesFormatSb.toString();
    List<String> descriptionLines = new ArrayList<>();
    for (Entry<String, DriverMeta> e : driversMap.entrySet()) {
        if (!e.getValue().hidden) {
            descriptionLines.clear();
            String description = e.getValue().description;
            if (description.length() > maxDescriptionWidth) {
                splitLine(descriptionLines, description, maxDescriptionWidth);
                description = descriptionLines.remove(0);
            }
            System.out.format(format, e.getKey(), description,
                    StringUtils.center(e.getValue().version, widths[2]), e.getValue().driverClass.getName());
            System.out.println();
            while (!descriptionLines.isEmpty()) {
                System.out.format(format, "", descriptionLines.remove(0), "", "");
                System.out.println();
            }
        }
    }
}

From source file:Main.java

/**
 * Move an object in List up/*from w w  w . j ava 2  s.c o  m*/
 * 
 * @param list
 * @param key
 * @param keyMapper
 * @return
 */
public static <T, K> boolean moveUp(List<T> list, K key, Function<T, K> keyMapper, int n) {
    ArrayList<T> newList = new ArrayList<T>();
    boolean changed = false;
    for (int i = 0; i < list.size(); i++) {
        T item = list.get(i);

        if (i > 0 && key.equals(keyMapper.apply(item))) {
            int posi = i - n;
            if (posi < 0)
                posi = 0;
            newList.add(posi, item);
            changed = true;
        } else
            newList.add(item);
    }

    if (changed) {
        list.clear();
        list.addAll(newList);
        return true;
    }
    return false;
}

From source file:com.validation.manager.core.tool.Tool.java

public static void removeDuplicates(List list) {
    Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = list.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (set.add(element)) {
            newList.add(element);//  w  w  w  . ja  v a 2  s. c  om
        }
    }
    list.clear();
    list.addAll(newList);
}

From source file:com.wolvereness.overmapped.lib.WellOrdered.java

public static <T, C extends List<? super T>> C process(final C out, final Iterable<? extends T> in,
        final Informer<T> informer) throws WellOrderedException {
    Validate.notNull(out, "Collection out cannot be null");
    Validate.notNull(in, "Token in cannot be null");
    Validate.notNull(informer, "Informer cannot be null");

    final Map<T, Collection<T>> preceding = newHashMap();
    final Map<T, Collection<T>> required = newHashMap();
    final Set<T> pending = newLinkedHashSet(in);

    { // Preprocessing of information from specified informer
        final List<T> buffer = newArrayList();
        for (final T token : pending) {

            // Preferred preceding elements
            informer.addPrecedingPreferencesTo(token, buffer);
            addToAsLinkedList(token, preceding, buffer);
            buffer.clear();

            // Required preceding elements
            informer.addPrecedingTo(token, buffer);
            if (!pending.containsAll(buffer))
                throw new UnmetPrecedingTokenException(token + " cannot be proceded by one of " + buffer
                        + " with only " + pending + " available");
            addToAsLinkedList(token, required, buffer);
            buffer.clear();//w w  w  .j a  v a2  s. com

            // Preferred proceeding elements
            informer.addProceedingPreferencesTo(token, buffer);
            addToAllLinkedLists(buffer, preceding, token);
            buffer.clear();
        }
    }

    int size = pending.size();
    while (size != 0) {

        { // Start normal processing
            final Iterator<T> tokenIterator = pending.iterator();
            while (tokenIterator.hasNext()) {
                final T token = tokenIterator.next();
                if (
                // Use preceding as primary/first check;
                // required is covered by the fall-back
                handleTokens(token, preceding, pending) && handleTokens(token, required, pending)) {
                    tokenIterator.remove();
                    out.add(token);
                }
            }
        }

        if (size == (size = pending.size())) {
            // Fall-back situation when we can't find a token that's ready
            final Iterator<T> tokenIterator = pending.iterator();
            while (tokenIterator.hasNext()) {
                final T token = tokenIterator.next();
                // At this point, we ignore preferences
                if (handleTokens(token, required, pending)) {
                    tokenIterator.remove();
                    preceding.remove(token);
                    out.add(token);
                    break;
                }
            }

            if (size == (size = pending.size())) {
                // We made no progress; it's circular
                break;
            }
        }
    }

    if (size != 0)
        throw new CircularOrderException("Failed to resolve circular preceding requirements in " + required);

    return out;
}

From source file:org.waarp.gateway.kernel.HttpJsonDefinition.java

protected static HttpPage loadHttpConfiguration(ConfigHttpPage cpage) throws InvalidArgumentException,
        ClassNotFoundException, InstantiationException, IllegalAccessException {
    List<ConfigHttpField> list = cpage.FIELD;
    LinkedHashMap<String, AbstractHttpField> linkedHashMap = new LinkedHashMap<String, AbstractHttpField>(
            list.size());/* www  .j a  v  a  2 s.c  o m*/
    // Now read the configuration
    for (ConfigHttpField fieldValue : list) {
        AbstractHttpField field = loadHttpPage(fieldValue);
        linkedHashMap.put(field.fieldname, field);
    }
    list.clear();
    list = null;
    return new HttpPage(cpage.PAGENAME, cpage.FILEFORM, cpage.HEADER, cpage.FOOTER, cpage.BEGINFORM,
            cpage.ENDFORM, cpage.NEXTINFORM, cpage.URI, cpage.PAGEROLE, cpage.ERRORPAGE, cpage.CLASSNAME,
            linkedHashMap);
}

From source file:com.fluidops.iwb.luxid.LuxidExtractor.java

/**
 * performs LUXID text extraction to the string passed as input. Puts the parsed and extended RDF to the global repository.
 * additionally returns a set of Key-Value-pairs which are inteded to be used as Metadata tags for Atmos
 * /*from   ww  w. ja va  2s .  c  om*/
 * @param input
 * @param token
 * @param annotationPlan
 * @param id
 * @param c
 * @param f
 * @return
 * @throws Exception
 */
public static List<Pair<String, String>> extractRDFWithLuxid(String input, String token, String annotationPlan,
        String id, Context c, File f) throws Exception {
    ReadWriteDataManager dm = ReadWriteDataManagerImpl.openDataManager(Global.repository);
    Set<Resource> entities = new HashSet<Resource>();
    List<Pair<String, String>> atmosTags = new ArrayList<Pair<String, String>>();

    List<Statement> stmts = retrieveLuxidStatements(input, token, annotationPlan, id, dm, entities);
    dm.addToContext(stmts, c);
    stmts.clear();
    int personCounter = 0;
    int companyCounter = 0;
    int locationCounter = 0;

    // STEP 3: generate Atmos metadata tags
    for (Resource entity : entities) {
        String stringValue = entity.stringValue();
        if (entity instanceof URI && stringValue.contains("Person"))
            atmosTags.add(new Pair<String, String>("Person_" + personCounter++,
                    stringValue.substring(stringValue.lastIndexOf("/") + 1)));
        else if (entity instanceof URI && stringValue.contains("Company"))
            atmosTags.add(new Pair<String, String>("Company_" + companyCounter++,
                    stringValue.substring(stringValue.lastIndexOf("/") + 1)));
        else if (entity instanceof URI && stringValue.contains("Location"))
            atmosTags.add(new Pair<String, String>("Location_" + locationCounter++,
                    stringValue.substring(stringValue.lastIndexOf("/") + 1)));
    }
    dm.addToContext(stmts, c);
    dm.close();
    dm.calculateVoIDStatistics(c.getURI());

    return atmosTags;
}

From source file:org.web4thejob.print.CsvPrinter.java

private static void writeLine(CSVWriter csv, ConversionService conversionService, Entity entity,
        RenderScheme renderScheme) {/*from   www .  ja  v  a 2 s .c  o  m*/
    List<String> line = new ArrayList<String>();
    if (renderScheme.getSchemeType() == SchemeType.ENTITY_SCHEME) {
        for (RenderElement item : renderScheme.getElements()) {
            if (item.getPropertyPath().getLastStep().isBlobType())
                continue;

            line.clear();
            line.add(item.getFriendlyName());
            Object value = item.getPropertyPath().getValue(entity);
            if (value != null) {
                if (item.getPropertyPath().getLastStep().isAnnotatedWith(HtmlHolder.class)) {
                    line.add(getActualTextFromHtml(value.toString()));
                } else {
                    line.add(conversionService.convert(value, String.class));
                }
            } else {
                line.add("");
            }
            csv.writeNext(line.toArray(new String[line.size()]));
        }
    } else {
        line.clear();
        for (RenderElement item : renderScheme.getElements()) {
            if (item.getPropertyPath().getLastStep().isBlobType())
                continue;

            Object value = item.getPropertyPath().getValue(entity);
            if (value != null) {
                if (item.getPropertyPath().getLastStep().isAnnotatedWith(HtmlHolder.class)) {
                    line.add(getActualTextFromHtml(value.toString()));
                } else {
                    line.add(conversionService.convert(value, String.class));
                }
            } else {
                line.add("");
            }
        }
        csv.writeNext(line.toArray(new String[line.size()]));
    }
}

From source file:Main.java

/**
 * Move an object in List down//from   w  w w  .  j  a  v  a 2s.c  om
 * 
 * @param list
 * @param key
 * @param keyMapper
 * @return
 */
public static <T, K> boolean moveDown(List<T> list, K key, Function<T, K> keyMapper, int n) {
    ArrayList<T> newList = new ArrayList<T>();
    boolean changed = false;
    int start = list.size() - 1;
    for (int i = start; i >= 0; i--) {
        T item = list.get(i);

        if (i != start && key.equals(keyMapper.apply(item))) {
            int posi = n;
            if (newList.size() < posi)
                posi = newList.size();
            newList.add(posi, item);
            changed = true;
        } else
            newList.add(0, item);
    }

    if (changed) {
        list.clear();
        list.addAll(newList);
        return true;
    }
    return false;
}

From source file:ffx.potential.parameters.PolarizeType.java

public static void assignPolarizationGroups(Atom atoms[], int ip11[][], int ip12[][], int ip13[][]) {
    /**/*  www .j a va2s. c  o m*/
     * Find directly connected group members for each atom.
     */
    List<Integer> group = new ArrayList<>();
    List<Integer> polarizationGroup = new ArrayList<>();
    //int g11 = 0;
    for (Atom ai : atoms) {
        group.clear();
        polarizationGroup.clear();
        Integer index = ai.getXYZIndex() - 1;
        group.add(index);
        polarizationGroup.add(ai.getType());
        PolarizeType polarizeType = ai.getPolarizeType();
        if (polarizeType != null) {
            if (polarizeType.polarizationGroup != null) {
                for (int i : polarizeType.polarizationGroup) {
                    if (!polarizationGroup.contains(i)) {
                        polarizationGroup.add(i);
                    }
                }
                growGroup(polarizationGroup, group, ai);
                Collections.sort(group);
                ip11[index] = new int[group.size()];
                int j = 0;
                for (int k : group) {
                    ip11[index][j++] = k;
                }
            } else {
                ip11[index] = new int[group.size()];
                int j = 0;
                for (int k : group) {
                    ip11[index][j++] = k;
                }
            }
            //g11 += ip11[index].length;
            //System.out.println(format("%d %d", index + 1, g11));
        } else {
            String message = "The polarize keyword was not found for atom " + (index + 1) + " with type "
                    + ai.getType();
            logger.severe(message);
        }
    }
    /**
     * Find 1-2 group relationships.
     */
    int nAtoms = atoms.length;
    int mask[] = new int[nAtoms];
    List<Integer> list = new ArrayList<>();
    List<Integer> keep = new ArrayList<>();
    for (int i = 0; i < nAtoms; i++) {
        mask[i] = -1;
    }
    for (int i = 0; i < nAtoms; i++) {
        list.clear();
        for (int j : ip11[i]) {
            list.add(j);
            mask[j] = i;
        }
        keep.clear();
        for (int j : list) {
            Atom aj = atoms[j];
            ArrayList<Bond> bonds = aj.getBonds();
            for (Bond b : bonds) {
                Atom ak = b.get1_2(aj);
                int k = ak.getXYZIndex() - 1;
                if (mask[k] != i) {
                    keep.add(k);
                }
            }
        }
        list.clear();
        for (int j : keep) {
            for (int k : ip11[j]) {
                list.add(k);
            }
        }
        Collections.sort(list);
        ip12[i] = new int[list.size()];
        int j = 0;
        for (int k : list) {
            ip12[i][j++] = k;
        }
    }
    /**
     * Find 1-3 group relationships.
     */
    for (int i = 0; i < nAtoms; i++) {
        mask[i] = -1;
    }
    for (int i = 0; i < nAtoms; i++) {
        for (int j : ip11[i]) {
            mask[j] = i;
        }
        for (int j : ip12[i]) {
            mask[j] = i;
        }
        list.clear();
        for (int j : ip12[i]) {
            for (int k : ip12[j]) {
                if (mask[k] != i) {
                    if (!list.contains(k)) {
                        list.add(k);
                    }
                }
            }
        }
        ip13[i] = new int[list.size()];
        Collections.sort(list);
        int j = 0;
        for (int k : list) {
            ip13[i][j++] = k;
        }
    }
}

From source file:forge.quest.BoosterUtils.java

private static List<Predicate<CardRules>> getColorFilters(final StartingPoolPreferences userPrefs,
        final List<PaperCard> cardPool) {

    final List<Predicate<CardRules>> colorFilters = new ArrayList<>();

    if (userPrefs != null) {

        boolean includeArtifacts = userPrefs.includeArtifacts();

        final List<Byte> preferredColors = userPrefs.getPreferredColors();

        switch (userPrefs.getPoolType()) {

        case RANDOM_BALANCED:
            preferredColors.clear();
            int numberOfColors = COLOR_COUNT_PROBABILITIES[(int) (Math.random()
                    * COLOR_COUNT_PROBABILITIES.length)];
            if (numberOfColors < 6) {
                Collections.shuffle(possibleColors);
                for (int i = 0; i < numberOfColors; i++) {
                    preferredColors.add(possibleColors.get(i));
                }/*from w  ww  .  ja va2  s.c o m*/
            } else {
                preferredColors.addAll(possibleColors);
            }
            includeArtifacts = Math.random() < 0.5;
        case BALANCED:
            populateBalancedFilters(colorFilters, preferredColors, cardPool, includeArtifacts);
            break;
        case RANDOM:
            populateRandomFilters(colorFilters);
            break;

        }

    }

    return colorFilters;

}