Example usage for java.util List indexOf

List of usage examples for java.util List indexOf

Introduction

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

Prototype

int indexOf(Object o);

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:org.geonode.security.LayersGrantedAuthority.java

public int compareTo(Object o) {
    if (!(o instanceof LayersGrantedAuthority)) {
        return 0;
    }//from ww  w  . j  a v a 2  s.  c o  m

    LayersGrantedAuthority that = (LayersGrantedAuthority) o;

    if (this.accessMode != that.accessMode) {
        List<LayerMode> modes = Arrays.asList(LayerMode.values());
        return modes.indexOf(this.accessMode) - modes.indexOf(that.accessMode);
    }

    if (this.layerNames.size() != that.layerNames.size()) {
        return this.layerNames.size() - that.layerNames.size();
    } else {
        for (int i = 0; i < this.layerNames.size(); i++) {
            int comparison = this.layerNames.get(i).compareTo(that.layerNames.get(i));
            if (comparison != 0)
                return comparison;
        }
    }

    return 0;
}

From source file:acmi.l2.clientmod.xdat.Controller.java

private static List<PropertySheetItem> loadProperties(Object obj) {
    Class<?> objClass = obj.getClass();
    List<PropertySheetItem> list = new ArrayList<>();
    while (objClass != Object.class) {
        try {//from   ww w . j a v  a 2s .  c o m
            List<String> names = Arrays.stream(objClass.getDeclaredFields())
                    .map(field -> field.getName().replace("Prop", "")).collect(Collectors.toList());
            BeanInfo beanInfo = Introspector.getBeanInfo(objClass, objClass.getSuperclass());
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            Arrays.sort(propertyDescriptors,
                    (pd1, pd2) -> Integer.compare(names.indexOf(pd1.getName()), names.indexOf(pd2.getName())));
            for (PropertyDescriptor descriptor : propertyDescriptors) {
                if ("metaClass".equals(descriptor.getName()))
                    continue;

                if (Collection.class.isAssignableFrom(descriptor.getPropertyType()))
                    continue;

                AnnotatedElement getter = descriptor.getReadMethod();
                if (getter.isAnnotationPresent(Deprecated.class) || getter.isAnnotationPresent(Hide.class))
                    continue;

                String description = "";
                if (getter.isAnnotationPresent(Description.class))
                    description = getter.getAnnotation(Description.class).value();
                Class<? extends PropertyEditor<?>> propertyEditorClass = null;
                if (descriptor.getPropertyType() == Boolean.class
                        || descriptor.getPropertyType() == Boolean.TYPE) {
                    propertyEditorClass = BooleanPropertyEditor.class;
                } else if (getter.isAnnotationPresent(Tex.class)) {
                    propertyEditorClass = TexturePropertyEditor.class;
                } else if (getter.isAnnotationPresent(Sysstr.class)) {
                    propertyEditorClass = SysstringPropertyEditor.class;
                }
                BeanProperty property = new BeanProperty(descriptor, objClass.getSimpleName(), description,
                        propertyEditorClass);
                list.add(property);
            }
        } catch (IntrospectionException e) {
            e.printStackTrace();
        }
        objClass = objClass.getSuperclass();
    }
    return list;
}

From source file:gda.device.detector.mythen.data.MythenSrsFileLoader.java

protected String[] read(BufferedReader br) throws IOException {

    // skip through header
    String line = br.readLine();/*from  w w  w .  j  a  v a 2 s.c om*/
    while (line != null && !line.contains("&END")) {
        line = br.readLine();
    }

    if (line == null) {
        throw new IOException("Reached end of file without seeing &END line");
    }

    // read data header; find column containing Mythen filenames
    String headerLine = br.readLine();
    if (!StringUtils.hasText(headerLine)) {
        throw new IOException("Didn't find column list");
    }
    List<String> headers = Arrays.asList(headerLine.split("\t"));
    int mythenColumn = headers.indexOf("mythen");
    if (mythenColumn == -1) {
        throw new IOException("Couldn't find 'mythen' column");
    }

    // read rest of data file; extract Mythen filename from each line
    List<String> filenames = new Vector<String>();
    while ((line = br.readLine()) != null) {
        String[] values = line.split("\t");
        String filenameValue = values[mythenColumn];
        filenames.add(filenameValue);
    }

    br.close();

    return filenames.toArray(new String[filenames.size()]);
}

From source file:jeplus.EPlusWinTools.java

public static boolean updateVersion(String startversion, String targetversion, String binfolder,
        String listfile, boolean backup, boolean keepversions, PrintStream logstream) {

    boolean ok = true;
    // Get files to be converted
    List<String> files = getFilesToBeConverted(listfile);
    // Get installed versions
    List<String> installed = getInstalledTransitionVersions(binfolder);

    // Find start and end points
    int start = installed.indexOf(startversion);
    int end = installed.indexOf(targetversion);

    if (start >= 0 && end >= 0 && end > start) {
        // Create backup if required. The backup files will be put in a bak/ folder next to the original files
        if (backup) {
            for (String file : files) {
                File thisfile = new File(file);
                if (thisfile.exists()) {
                    fileCopy(thisfile.getAbsolutePath(), thisfile.getAbsolutePath() + ".ori");
                }//from  w ww .ja va2s.  c  o  m
            }
        }
        // Start conversion
        for (int i = start; i < end; i++) {
            // Store interim version if required
            if (keepversions) {
                for (String file : files) {
                    File thisfile = new File(file);
                    if (thisfile.exists()) {
                        fileCopy(thisfile.getAbsolutePath(),
                                thisfile.getAbsolutePath() + "." + installed.get(i));
                    }
                }
            }
            // Call converter
            ok &= runVersionTransition(installed.get(i), installed.get(i + 1), binfolder, listfile, logstream);
        }
        // remove temporary files
        for (String file : files) {
            File thisfile = new File(file + "_transition.audit");
            if (thisfile.exists()) {
                thisfile.delete();
            }
            thisfile = new File(file + "old");
            if (thisfile.exists()) {
                thisfile.delete();
            }
            thisfile = new File(file + "new");
            if (thisfile.exists()) {
                thisfile.delete();
            }
        }
    } else {
        // Some error message
        logger.error(
                "Either the start or the target version is wrong. Please make sure the relevant transition files are available, and the target version is higher than the start version");
        ok = false;
    }

    return ok;
}

From source file:com.autentia.common.util.web.jsf.ObjectFromListConverter.java

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
    log.trace("Entering");

    final List<?> objs = getAlloweValues(component);
    final int index = objs.indexOf(value);

    if (index == -1) {
        log.warn("Cannot get index of: " + value);
        return "-1";
    }//www.java  2s  .  co  m
    final String indexAsString = String.valueOf(index);

    if (log.isTraceEnabled()) {
        log.trace("Converted as String, object: " + value + ", index: " + indexAsString);
        log.trace("Exiting");
    }
    return indexAsString;
}

From source file:net.jforum.services.CategoryService.java

/**
 * Changes the order of the specified category, adding it
 * one level or one level down/*from  w w  w . j  ava  2 s  .c  om*/
 * @param up if true, sets the category one level up. If false, one level down
 * @param categoryId the id of the category to change
 */
private void processOrdering(boolean up, int categoryId) {
    Category toChange = this.repository.get(categoryId);
    List<Category> categories = this.repository.getAllCategories();

    int index = categories.indexOf(toChange);

    if (index > -1 && (up && index > 0) || (!up && index + 1 < categories.size())) {
        Category otherCategory = up ? categories.get(index - 1) : categories.get(index + 1);

        int oldOrder = toChange.getDisplayOrder();

        toChange.setDisplayOrder(otherCategory.getDisplayOrder());
        otherCategory.setDisplayOrder(oldOrder);

        this.repository.update(toChange);
        this.repository.update(otherCategory);
    }
}

From source file:net.jforum.services.ForumService.java

/**
 * Changes the order of the specified forum, adding it one level or one level down
 * @param up if true, sets the forum one level up. If false, one level down
 * @param forumId the id of the category to change
 *//* w w w. j av a2 s. c  o m*/
private void processOrdering(boolean up, int forumId) {
    Forum toChange = this.repository.get(forumId);
    List<Forum> forums = toChange.getCategory().getForums();

    int index = forums.indexOf(toChange);

    if (index > -1 && (up && index > 0) || (!up && index + 1 < forums.size())) {
        Forum otherForum = up ? forums.get(index - 1) : forums.get(index + 1);

        int oldOrder = toChange.getDisplayOrder();

        toChange.setDisplayOrder(otherForum.getDisplayOrder());
        otherForum.setDisplayOrder(oldOrder);

        this.repository.update(toChange);
        this.repository.update(otherForum);
    }
}

From source file:org.meruvian.yama.webapi.interceptor.CurrentUserFilter.java

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    UriInfo uriInfo = requestContext.getUriInfo();
    MultivaluedMap<String, String> parameters = uriInfo.getPathParameters();
    List<String> usernames = parameters.get("username");

    if (usernames == null)
        return;/*  w w  w.  j a v a  2s  .co  m*/

    if (usernames.contains("me")) {
        usernames.set(usernames.indexOf("me"), SessionCredentials.getCurrentUsername());
    }
}

From source file:io.servicecomb.swagger.generator.pojo.PojoSwaggerGeneratorContext.java

protected void replaceBodyBasedParameter(OperationGenerator operationGenerator, Parameter bodyBasedParameter) {
    if (ParamUtils.isRealBodyParameter(bodyBasedParameter)) {
        return;//from ww w  .java2 s  . c o m
    }

    List<Parameter> swaggerParameters = operationGenerator.getSwaggerParameters();
    int idx = swaggerParameters.indexOf(bodyBasedParameter);
    String bodyParamName = bodyBasedParameter.getName();
    BodyParameter bodyParameter = ((PendingBodyParameter) bodyBasedParameter)
            .createBodyParameter(bodyParamName);
    swaggerParameters.set(idx, bodyParameter);
}

From source file:com.formkiq.core.webflow.dialect.LayoutFieldClassAttrProcessor.java

/**
 * Get Number of Occurrences in a row.//from  ww w  .j a  va 2 s . c  o m
 * @param section {@link FormJSONSection}
 * @param field {@link FormJSONField}
 * @return int
 */
private int getOccurrences(final FormJSONSection section, final FormJSONField field) {

    int occurs = 1;
    List<FormJSONField> fields = section.getFields();
    int pos = fields.indexOf(field);

    if (pos != -1) {
        occurs += getOccurrences(fields, field.getType(), pos, true);
        occurs += getOccurrences(fields, field.getType(), pos, false);
    }

    return occurs;
}