Example usage for java.lang Iterable iterator

List of usage examples for java.lang Iterable iterator

Introduction

In this page you can find the example usage for java.lang Iterable iterator.

Prototype

Iterator<T> iterator();

Source Link

Document

Returns an iterator over elements of type T .

Usage

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void defaultMemberIterator() {
    Iterable<Class<?>> classIterable = new ClassCriteria().getIterable(Object.class);
    Iterable<Member> iterable = memberCriteria.getIterable(classIterable);
    assertNotNull(iterable);// ww w . ja  va  2 s  .c o  m
    Iterator<Member> iterator = iterable.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    Member next = iterator.next();
    assertNotNull(next);

}

From source file:me.cybermaxke.merchants.v16r3.SMerchant.java

@Override
public void removeOffers(Iterable<MerchantOffer> offers) {
    checkNotNull(offers, "offers");

    // Only update if necessary
    if (!offers.iterator().hasNext()) {
        return;//from  w w  w . j a v a2s  .c o m
    }

    if (this.offers.removeAll(Lists.newArrayList(offers))) {
        // Unlink the offers
        for (MerchantOffer offer : offers) {
            ((SMerchantOffer) offer).remove(this);
        }

        // Send the new offer list
        this.sendUpdate();
    }
}

From source file:akka.systemActors.ActorSupervisor.java

private void askChildrenLogic(List<ActorRef> actorTrace) throws Exception {

    List<Future<Object>> childrenResponseList = new ArrayList<Future<Object>>();

    for (ActorRef child : getContext().getChildren()) {
        //System.out.println("Request: "+ new BasicRequest(timeStep, actorTrace, null));
        childrenResponseList.add(ask(child, new BasicRequest(GlobalTime.currentTimeStep, actorTrace, null),
                GridArchitectConfiguration.rootActorResponseTime));
        //System.out.println("Supervisor: ASK A CHILD");
    }//  w  w  w  . j a  v a  2  s .co m

    //System.out.println("-------------------------");        

    Future<Iterable<Object>> childrenFuturesIterable = sequence(childrenResponseList,
            getContext().system().dispatcher());
    Iterable<Object> childrenResponsesIterable = Await.result(childrenFuturesIterable,
            Duration.create(GridArchitectConfiguration.rootActorResponseTime, TimeUnit.MILLISECONDS));

    this.receivedAllStates = true;
    for (Iterator<Object> i = childrenResponsesIterable.iterator(); i.hasNext();) {
        BasicAnswer response = (BasicAnswer) i.next();

        this.receivedAllStates = this.receivedAllStates && response.sane;
        //System.out.println(response);
        if (response.upstreamActorTrace.size() > 0) {
            responseTraceMap.put(response.upstreamActorTrace.get(response.upstreamActorTrace.size() - 1),
                    response.upstreamActorTrace);
        }

        for (ActorRef actor : response.upstreamActorTrace)
            this.responseTrace.add(actor);
    }

    this.reportToMonitor();
}

From source file:com.orientechnologies.orient.graph.blueprints.GraphTest.java

@Test
public void testIndexCollate() {
    OrientGraph g = new OrientGraph(URL, "admin", "admin");

    OrientVertexType vCollate = g.createVertexType("VCollate");

    vCollate.createProperty("name", OType.STRING);

    g.createKeyIndex("name", Vertex.class, new Parameter<String, String>("class", "VCollate"),
            new Parameter<String, String>("type", "UNIQUE"),
            new Parameter<String, OType>("keytype", OType.STRING),
            new Parameter<String, String>("collate", "ci"));
    OrientVertex vertex = g.addVertex("class:VCollate", new Object[] { "name", "Enrico" });

    g.commit();//from   ww w .j a  v a2s .  c o m

    Iterable<Vertex> enrico = g.getVertices("VCollate.name", "ENRICO");

    Assert.assertEquals(true, enrico.iterator().hasNext());

}

From source file:me.cybermaxke.merchants.v16r3.SMerchant.java

@Override
public void addOffers(Iterable<MerchantOffer> offers) {
    checkNotNull(offers, "offers");

    // Only update if necessary
    if (!offers.iterator().hasNext()) {
        return;/*from   w w  w . ja  v a  2 s. co m*/
    }

    // Add and link the offers
    for (MerchantOffer offer : offers) {
        if (this.offers.contains(offer)) {
            continue;
        }
        this.offers.add(offer);
        ((SMerchantOffer) offer).add(this);
    }

    // Send the new offer list
    this.sendUpdate();
}

From source file:com.infinities.nova.securitygroups.api.DaseinSecurityGroupsApi.java

/**
 * @param securityGroup/*from  w  w  w  .  jav  a  2  s .  c o m*/
 * @return
 * @throws InternalException
 * @throws CloudException
 * @throws ConcurrentException
 * @throws ExecutionException
 * @throws InterruptedException
 */
private SecurityGroup toSecurityGroup(OpenstackRequestContext context, Firewall firewall, String projectId)
        throws CloudException, InternalException, ConcurrentException, InterruptedException,
        ExecutionException {
    SecurityGroup securityGroup = new SecurityGroup();
    securityGroup.setDescription(firewall.getDescription());
    securityGroup.setId(firewall.getProviderFirewallId());
    securityGroup.setName(firewall.getName());
    securityGroup.setTenantId(getTenantId(projectId));
    List<Rule> rules = new ArrayList<Rule>();
    Collection<FirewallRule> firewallRules = firewall.getRules();
    Iterable<FirewallRule> iterable = firewallRules;
    if (firewallRules == null || firewallRules.isEmpty()) {
        iterable = this.getSupport(context.getProjectId()).getRules(firewall.getProviderFirewallId()).get();
    }
    Iterator<FirewallRule> iterator = iterable.iterator();
    while (iterator.hasNext()) {
        FirewallRule firewallRule = iterator.next();
        rules.add(toRule(firewallRule, firewall, projectId));
    }
    securityGroup.setRules(rules);
    return securityGroup;
}

From source file:com.epam.reportportal.extension.bugtracking.jira.JiraStrategy.java

@Override
public List<PostFormField> getTicketFields(final String ticketType, ExternalSystem details) {
    List<PostFormField> result = new ArrayList<>();
    try (JiraRestClient client = getClient(details.getUrl(), details.getUsername(),
            simpleEncryptor.decrypt(details.getPassword()))) {
        Project jiraProject = getProject(client, details);
        Optional<IssueType> issueType = StreamSupport.stream(jiraProject.getIssueTypes().spliterator(), false)
                .filter(input -> ticketType.equalsIgnoreCase(input.getName())).findFirst();
        GetCreateIssueMetadataOptions options = new GetCreateIssueMetadataOptionsBuilder()
                .withExpandedIssueTypesFields().withProjectKeys(jiraProject.getKey()).build();
        Iterable<CimProject> projects = client.getIssueClient().getCreateIssueMetadata(options).claim();
        CimProject project = projects.iterator().next();
        CimIssueType cimIssueType = EntityHelper.findEntityById(project.getIssueTypes(),
                issueType.get().getId());
        for (String key : cimIssueType.getFields().keySet()) {
            List<String> defValue = null;
            CimFieldInfo issueField = cimIssueType.getFields().get(key);
            // Field ID for next JIRA POST ticket requests
            String fieldID = issueField.getId();
            String fieldType = issueField.getSchema().getType();
            List<AllowedValue> allowed = new ArrayList<>();
            // Field NAME for user friendly UI output (for UI only)
            String fieldName = issueField.getName();

            if (fieldID.equalsIgnoreCase(IssueFieldId.COMPONENTS_FIELD.id)) {
                for (BasicComponent component : jiraProject.getComponents()) {
                    allowed.add(new AllowedValue(String.valueOf(component.getId()), component.getName()));
                }/*  w ww  .  j  a  v  a2 s.com*/
            }
            if (fieldID.equalsIgnoreCase(IssueFieldId.FIX_VERSIONS_FIELD.id)) {
                for (Version version : jiraProject.getVersions()) {
                    allowed.add(new AllowedValue(String.valueOf(version.getId()), version.getName()));
                }
            }
            if (fieldID.equalsIgnoreCase(IssueFieldId.AFFECTS_VERSIONS_FIELD.id)) {
                for (Version version : jiraProject.getVersions()) {
                    allowed.add(new AllowedValue(String.valueOf(version.getId()), version.getName()));
                }
            }
            if (fieldID.equalsIgnoreCase(IssueFieldId.PRIORITY_FIELD.id)) {
                if (null != cimIssueType.getField(IssueFieldId.PRIORITY_FIELD)) {
                    Iterable<Object> allowedValuesForPriority = cimIssueType
                            .getField(IssueFieldId.PRIORITY_FIELD).getAllowedValues();
                    for (Object singlePriority : allowedValuesForPriority) {
                        BasicPriority priority = (BasicPriority) singlePriority;
                        allowed.add(new AllowedValue(String.valueOf(priority.getId()), priority.getName()));
                    }
                }
            }
            if (fieldID.equalsIgnoreCase(IssueFieldId.ISSUE_TYPE_FIELD.id)) {
                defValue = Lists.newArrayList(BUG);
            }
            if (fieldID.equalsIgnoreCase(IssueFieldId.ASSIGNEE_FIELD.id)) {
                allowed = getJiraProjectAssignee(jiraProject);
            }

            //@formatter:off
            // Skip project field as external from list
            // Skip attachment cause we are not providing this functionality now
            // Skip timetracking field cause complexity. There are two fields with Original Estimation and Remaining Estimation.
            // Skip Story Link as greenhopper plugin field.
            // Skip Sprint field as complex one.
            //@formatter:on
            if ("project".equalsIgnoreCase(fieldID) || "attachment".equalsIgnoreCase(fieldID)
                    || "timetracking".equalsIgnoreCase(fieldID) || "Epic Link".equalsIgnoreCase(fieldName)
                    || "Sprint".equalsIgnoreCase(fieldName))
                continue;

            result.add(new PostFormField(fieldID, fieldName, fieldType, issueField.isRequired(), defValue,
                    allowed));
        }
        return result;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new ArrayList<>();
    }

}

From source file:arena.dao.DAOSupport.java

public int insert(Iterable<T> valueobjects) {
    Iterable<T> actuallyInsert = valueobjects;
    if (this.insertListeners != null) {
        for (DAOInsertListener<T> pre : this.insertListeners) {
            actuallyInsert = pre.preInsert(actuallyInsert);
        }/*w w w .  j  av  a 2s  .co  m*/
    }
    if (actuallyInsert == null) {
        log.debug("No rows to insert - aborting");
        return 0;
    }
    int retVal = doInsert(actuallyInsert.iterator());

    // We only have post insert VOs if we sent at least one
    if (this.insertListeners != null) {
        for (DAOInsertListener<T> post : this.insertListeners) {
            post.postInsert(actuallyInsert);
        }
    }
    return retVal;
}

From source file:SuperStuffTest.java

/**
 * Prueba para registrar un producto//  w  w  w.  ja v  a  2s  .c  o m
 */
@Test
public void registrarProductoTest() {
    Pais p1 = new Pais("Colombia", "COL", "ESPAOL", Pais.SIHAYCOBERTURA);
    Pais p2 = new Pais("Colombia", "COL", "ESPAOL", Pais.SIHAYCOBERTURA);

    Set<Lugar> newPlaces = new LinkedHashSet<>();
    newPlaces.add(new Lugar(p1, "Bogot", "Cedritos"));
    newPlaces.add(new Lugar(p1, "Bogota", "Las Orquideas"));

    p1.setLugares(newPlaces);
    repositorioPaises.save(p1);
    repositorioPaises.save(p2);

    List<Lugar> lugares = (List<Lugar>) repositorioLugares.findAll();

    repositorioCategorias.save(new Categoria(1, "Frutas", "Categoria que agrupa las frutas"));
    repositorioCategorias.save(new Categoria(100, "Alcohol", "Categoria que agrupa Bebidas Alcoholicas"));
    repositorioDescuentos.save(new Descuento(0, new Date(), new Date(), "Esto es un descuento del 0%"));
    repositorioDescuentos.save(new Descuento(100, new Date(), new Date(), "Esto es un descuento del 10%"));

    superStuff.crearNuevoProveedor(new Proveedor(1, lugares.get(0), "Licorera El Tio Moe", "Calle Falsa 123",
            "3044463405", "www.eltiomoe.com", "eltiomoe@mail.com", "p1", "1234"));
    superStuff.crearNuevoProveedor(new Proveedor(2, lugares.get(0), "Jabones Mr. Chispa", "Calle Falsa 121",
            "3044463404", "www.mrchispa.com", "mrchispa@mail.com", "p2", "1234"));
    superStuff.crearNuevoProveedor(new Proveedor(3, lugares.get(0), "Alpina", "Calle Falsa 124", "3045463402",
            "www.prueba.com", "prueba@mail.com", "p3", "1234"));
    superStuff.crearNuevoProveedor(new Proveedor(4, lugares.get(0), "Ramo", "Calle Falsa 125", "3045463403",
            "www.prueba.com", "prueba@mail.com", "p4", "1234"));
    superStuff.crearNuevoProveedor(new Proveedor(5, lugares.get(0), "Telas ECI", "Calle Falsa 126",
            "3045463404", "www.prueba.com", "prueba@mail.com", "p5", "1234"));
    superStuff.crearNuevoProveedor(new Proveedor(6, lugares.get(0), "Lacteos ECI", "Calle Falsa 127",
            "3045463405", "www.prueba.com", "prueba@mail.com", "p6", "1234"));

    Proveedor p = repositorioProveedores.findOne(1);
    Categoria c1 = repositorioCategorias.findOne(100);
    Iterable<Descuento> d1 = repositorioDescuentos.findAll();
    Producto pd = new Producto(c1, d1.iterator().next(), p, "Jack Daniels Whiskey Old Time", 1000000, null);
    int id = superStuff.registrarProducto(pd);
    Producto producto = repositorioProductos.findOne(id);

    assertEquals("Ha cargado la descripcion del producto?", "Jack Daniels Whiskey Old Time",
            producto.getDescripcion());
    assertNotNull("La categoria del producto no debe ser nula", producto.getCategoria());
    assertNotNull("El descuento del producto no debe ser nulo", producto.getDescuentos());
    assertNotNull("El proveedor del producto no debe ser nulo", producto.getProveedores());
    assertEquals("El precio del producto es 1000000?", 1000000, producto.getPrecioLista());
}

From source file:com.netflix.hystrix.contrib.javanica.cache.CacheInvocationContext.java

/**
 * Constructor to create CacheInvocationContext based on passed parameters.
 *
 * @param cacheAnnotation the caching annotation, like {@link com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult}
 * @param cacheKeyMethod  the method to generate cache key
 * @param target          the current instance of intercepted method
 * @param method          the method annotated with on of caching annotations
 * @param args            the method arguments
 *//*w  w w. j a v a  2 s. c  o m*/
public CacheInvocationContext(A cacheAnnotation, MethodExecutionAction cacheKeyMethod, Object target,
        Method method, Object... args) {
    this.method = method;
    this.target = target;
    this.cacheKeyMethod = cacheKeyMethod;
    this.cacheAnnotation = cacheAnnotation;
    Class<?>[] parametersTypes = method.getParameterTypes();
    Annotation[][] parametersAnnotations = method.getParameterAnnotations();
    int parameterCount = parametersTypes.length;
    if (parameterCount > 0) {
        ImmutableList.Builder<CacheInvocationParameter> parametersBuilder = ImmutableList.builder();
        for (int pos = 0; pos < parameterCount; pos++) {
            Class<?> paramType = parametersTypes[pos];
            Object val = args[pos];
            parametersBuilder
                    .add(new CacheInvocationParameter(paramType, val, parametersAnnotations[pos], pos));
        }
        parameters = parametersBuilder.build();
        // get key parameters
        Iterable<CacheInvocationParameter> filtered = Iterables.filter(parameters,
                new Predicate<CacheInvocationParameter>() {
                    @Override
                    public boolean apply(CacheInvocationParameter input) {
                        return input.hasCacheKeyAnnotation();
                    }
                });
        if (filtered.iterator().hasNext()) {
            keyParameters = ImmutableList.<CacheInvocationParameter>builder().addAll(filtered).build();
        } else {
            keyParameters = parameters;
        }
    }
}