Example usage for com.google.common.collect Iterables indexOf

List of usage examples for com.google.common.collect Iterables indexOf

Introduction

In this page you can find the example usage for com.google.common.collect Iterables indexOf.

Prototype

public static <T> int indexOf(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns the index in iterable of the first element that satisfies the provided predicate , or -1 if the Iterable has no such elements.

Usage

From source file:com.btmatthews.atlas.core.common.PagingBuilder.java

/**
 * Toggle the direction of the sort ordering.
 *
 * @param field The field name./*w ww  .ja v  a 2 s. c om*/
 * @return Always returns the {@link PagingBuilder} object.
 */
public PagingBuilder toggleOrdering(final String field) {
    final int index = Iterables.indexOf(sortOrderings, findOrdering(field));
    if (index == -1) {
        addOrdering(field, SortDirection.ASCENDING);
    } else {
        if (sortOrderings.get(index).getSortDirection() == SortDirection.ASCENDING) {
            sortOrderings.set(index, new Ordering(field, SortDirection.DESCENDING));
        } else {
            sortOrderings.set(index, new Ordering(field, SortDirection.ASCENDING));
        }
    }
    return this;
}

From source file:com.github.buzztaiki.jenova.InterfaceMethod.java

public List<JCTree.JCExpression> getParamTypes(List<JCTree.JCExpression> typeArgs) {
    Preconditions.checkArgument(typeArgs.size() == clazz.getTypeParameters().size(),
            "typeArgs length for %s should be %s but takes %s", getClazz(), clazz.getTypeParameters().size(),
            typeArgs.size());/*w ww.  j av  a  2 s. c  o  m*/

    Iterable<Type> typeParams = types(clazz.getTypeParameters());
    Equivalence<Type> sameType = sameType(types);
    ListBuffer<JCTree.JCExpression> res = new ListBuffer<JCTree.JCExpression>();
    for (Type type : types(method.getParameters())) {
        int i = Iterables.indexOf(typeParams, sameType.equivalentTo(type));
        res.append(i >= 0 ? typeArgs.get(i) : maker.Type(type));
    }
    return res.toList();
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java

@SuppressWarnings("unchecked")
public T sample() {

    Preconditions.checkState(!_entriesToLogProbs.isEmpty(), "No entries in the CDF");
    Preconditions.checkState(!Double.isInfinite(_logCumulativeProb), "No cumulative probability in CDF");

    if (_entriesToLogProbs.size() == 1) {
        return Iterables.getOnlyElement(_entriesToLogProbs.keySet());
    }/*  www.j a v  a  2 s  .com*/

    if (_emd == null) {
        initializeDistribution();
    }

    _emd.setNumTrials(1);
    final Vector sampleRes = _emd.sample(threadLocalRng.get());
    final int newIdx = Iterables.indexOf(sampleRes, new Predicate<VectorEntry>() {
        @Override
        public boolean apply(VectorEntry input) {
            return Double.compare(input.getValue(), 0.0) >= 1;
        }
    });

    // final double u = threadLocalRng.get().nextDouble();
    // final int newIdx = (int) emd.inverseF(u);

    return (T) _entries[_objIdx.get(newIdx)];
}

From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.JGraphTab.java

private Color selectTabBackGroundColor(final int seed) {

    final int insertionPosition = Iterables.indexOf(moduleIdCount.keySet(), Predicates.equalTo(seed));

    switch (insertionPosition) {
    case 0:/*from   ww w .  j av a2s .  c  o  m*/
        return Color.getHSBColor((float) 0.55, (float) 0.2, (float) 0.8);
    case 1:
        return Color.getHSBColor((float) 0.6, (float) 0.2, (float) 0.8);
    case 2:
        return Color.getHSBColor((float) 0.65, (float) 0.2, (float) 0.8);
    case 3:
        return Color.getHSBColor((float) 0.7, (float) 0.2, (float) 0.8);
    case 4:
        return Color.getHSBColor((float) 0.75, (float) 0.2, (float) 0.8);
    case 5:
        return Color.getHSBColor((float) 0.8, (float) 0.2, (float) 0.8);
    case 6:
        return Color.getHSBColor((float) 0.85, (float) 0.2, (float) 0.8);
    case 7:
        return Color.getHSBColor((float) 0.9, (float) 0.2, (float) 0.8);
    case 8:
        return Color.getHSBColor((float) 0.95, (float) 0.2, (float) 0.8);
    case 9:
        return Color.getHSBColor(1, (float) 0.2, (float) 0.8);
    case 10:
        return Color.getHSBColor((float) 0.05, (float) 0.2, (float) 0.8);
    case 11:
        return Color.getHSBColor((float) 0.1, (float) 0.2, (float) 0.8);
    case 12:
        return Color.getHSBColor((float) 0.15, (float) 0.2, (float) 0.8);
    case 13:
        return Color.getHSBColor((float) 0.2, (float) 0.2, (float) 0.8);
    case 14:
        return Color.getHSBColor((float) 0.25, (float) 0.2, (float) 0.8);
    case 15:
        return Color.getHSBColor((float) 0.3, (float) 0.2, (float) 0.8);
    case 16:
        return Color.getHSBColor((float) 0.35, (float) 0.2, (float) 0.8);
    case 17:
        return Color.getHSBColor((float) 0.4, (float) 0.2, (float) 0.8);
    case 18:
        return Color.getHSBColor((float) 0.45, (float) 0.2, (float) 0.8);
    case 19:
        return Color.getHSBColor((float) 0.5, (float) 0.2, (float) 0.8);
    default:
        return Color.WHITE;
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractBox.java

@Override
public int indexOf(Component child) {
    return Iterables.indexOf(ownComponents, c -> c == child);
}

From source file:com.haulmont.cuba.desktop.gui.data.TreeModelAdapter.java

@Override
public int getIndexOfChild(Object parent, Object child) {
    if (parent == null || child == null)
        return -1;

    Collection<Object> childrenIds;
    if (parent == rootNode) {
        childrenIds = datasource.getRootItemIds();
    } else {//from www  .  j av a2  s  . c  o m
        Entity entity = ((Node) parent).getEntity();
        childrenIds = datasource.getChildren(entity.getId());
    }
    final Entity childEntity = ((Node) child).getEntity();
    return Iterables.indexOf(childrenIds, id -> childEntity.getId().equals(id));
}

From source file:org.splevo.ui.dashboard.ConfigurationTab.java

private Group buildFeatureModelBuilderGroup(Composite composite) {

    Group group = new Group(composite, SWT.FILL);
    group.setText("FeatureModel Builders");
    group.setLayout(new GridLayout(columnNum, true));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    Label configLabel = new Label(group, SWT.NONE);
    configLabel.setText("Feature Model Builder:");
    //configLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    gridData.horizontalSpan = columnNum - 1;

    final Combo fmBuilderCombo = new Combo(group, SWT.READ_ONLY | SWT.DROP_DOWN);
    fmBuilderCombo.setLayoutData(gridData);
    for (FeatureModelBuilder<?> fmBuilder : FeatureModelBuilderRegistry.getInstance().getElements()) {
        fmBuilderCombo.add(fmBuilder.getLabel());
    }/*from ww  w  . ja v  a  2s.  c o  m*/

    FeatureModelBuilder<Object> firstFmBuilderInRegistry = Iterables
            .getFirst(FeatureModelBuilderRegistry.getInstance().getElements(), null);
    FeatureModelBuilder<Object> defaultFMBuilderInProject = FeatureModelBuilderRegistry.getInstance()
            .getElementById(getSPLevoProject().getFmBuilderId());
    final FeatureModelBuilder<Object> activeFmBuilder = defaultFMBuilderInProject == null
            ? firstFmBuilderInRegistry
            : defaultFMBuilderInProject;
    if (activeFmBuilder != null) {
        int index = Iterables.indexOf(Lists.newArrayList(fmBuilderCombo.getItems()), new Predicate<String>() {
            @Override
            public boolean apply(String itemLabel) {
                return itemLabel.equals(activeFmBuilder.getLabel());
            }
        });
        fmBuilderCombo.select(index);
        getSPLevoProject().setFmBuilderId(activeFmBuilder.getId());
    }

    fmBuilderCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            String fmBuilderId = FeatureModelBuilderRegistry.getInstance()
                    .getIdByLabel(fmBuilderCombo.getText());
            if (fmBuilderId != null && !getSPLevoProject().getFmBuilderId().equals(fmBuilderId)) {
                getSPLevoProject().setFmBuilderId(fmBuilderId);
                getSplevoProjectEditor().markAsDirty();
            }
        }
    });

    return group;
}

From source file:dagger.internal.codegen.BindingDeclarationFormatter.java

private String formatSubcomponentDeclaration(SubcomponentDeclaration subcomponentDeclaration) {
    ImmutableList<TypeMirror> moduleSubcomponents = getModuleSubcomponents(
            subcomponentDeclaration.moduleAnnotation());
    int index = Iterables.indexOf(moduleSubcomponents,
            MoreTypes.equivalence().equivalentTo(subcomponentDeclaration.subcomponentType().asType()));
    StringBuilder annotationValue = new StringBuilder();
    if (moduleSubcomponents.size() != 1) {
        annotationValue.append("{");
    }/*from w  w  w. j a v  a 2  s. com*/
    annotationValue.append(formatArgumentInList(index, moduleSubcomponents.size(),
            subcomponentDeclaration.subcomponentType().getQualifiedName() + ".class"));
    if (moduleSubcomponents.size() != 1) {
        annotationValue.append("}");
    }

    return String.format("@%s(subcomponents = %s) for %s",
            simpleName(subcomponentDeclaration.moduleAnnotation()), annotationValue,
            subcomponentDeclaration.contributingModule().get());
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopScrollBoxLayout.java

@Override
public int indexOf(Component child) {
    return Iterables.indexOf(components, c -> c == child);
}

From source file:info.magnolia.configuration.app.overview.data.DefinitionRawViewId.java

private String resolveName() {
    String name = super.getName();
    if (name == null && getValue().getKind() == DefinitionRawView.Kind.subBean) {
        final Optional<DefinitionRawView.Property> propertyOptional = Iterables
                .tryFind(tryGetProperties(getValue().getSubRawView()), new NamePropertyPredicate());

        if (propertyOptional.isPresent()) {
            name = propertyOptional.get().getSimpleValue();
        } else {// ww  w  .  jav a  2s.c  o m
            final Id parent = getParent();
            if (parent instanceof DefinitionRawViewId) {
                final DefinitionRawViewId parentRawViewId = (DefinitionRawViewId) parent;
                if (parentRawViewId.getValue().getKind() == DefinitionRawView.Kind.collection) {
                    final int index = Iterables.indexOf(parentRawViewId.getValue().getCollection(),
                            new IsCurrentRawViewValue());
                    name = Noun.singularOf(parentRawViewId.getName()) + (index + 1);
                }
            }
        }
    }
    return name;
}