Search in sources :

Example 31 with ArrayList

use of java.util.ArrayList in project antlrworks by antlr.

the class GDOTImporterDOT method parseControlPoints.

public Vector2D[] parseControlPoints(String s) throws IOException {
    // e,56,216 51,34 43,44 33,58 29,72 15,118 20,134 36,180 39,190 45,199 50,208
    List<Vector2D> points = new ArrayList<Vector2D>();
    Vector2D endPoint = null;
    String[] pts = parseTokens(s);
    int index = -1;
    while (++index < pts.length) {
        if (pts[index].equals("e")) {
            // Arrow at the end
            if (index + 2 >= pts.length) {
                System.err.println(String.format("Expected x arrow position at %d but reached the end at %d", index + 2, pts.length));
                continue;
            }
            if (index + 4 >= pts.length) {
                System.err.println(String.format("Expected y arrow position at %d but reached the end at %d", index + 4, pts.length));
                continue;
            }
            String x = pts[index += 2];
            String y = pts[index += 2];
            endPoint = new Vector2D(Float.parseFloat(x), height - Float.parseFloat(y));
        } else if (isFloatString(pts[index]) && index + 2 < pts.length && isFloatString(pts[index + 2])) {
            // Assume pair of numbers
            if (index + 2 >= pts.length) {
                System.err.println(String.format("Expected y position at %d but reached the end at %d", index + 2, pts.length));
                continue;
            }
            String x = pts[index];
            String y = pts[index += 2];
            points.add(new Vector2D(Float.parseFloat(x), height - Float.parseFloat(y)));
        }
    }
    if (endPoint != null)
        points.add(endPoint);
    Vector2D[] p = new Vector2D[points.size()];
    for (int i = 0; i < points.size(); i++) {
        p[i] = points.get(i);
    }
    return p;
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D) ArrayList(java.util.ArrayList)

Example 32 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class ProducerCache method prepareInternalProcessor.

protected CamelInternalProcessor prepareInternalProcessor(Producer producer, Processor resultProcessor) {
    // if we have a result processor then wrap in pipeline to execute both of them in sequence
    Processor target;
    if (resultProcessor != null) {
        List<Processor> processors = new ArrayList<Processor>(2);
        processors.add(producer);
        processors.add(resultProcessor);
        target = Pipeline.newInstance(getCamelContext(), processors);
    } else {
        target = producer;
    }
    // wrap in unit of work
    CamelInternalProcessor internal = new CamelInternalProcessor(target);
    internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(null));
    return internal;
}
Also used : CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) Processor(org.apache.camel.Processor) AsyncProcessor(org.apache.camel.AsyncProcessor) ArrayList(java.util.ArrayList)

Example 33 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class RouteService method doWarmUp.

protected synchronized void doWarmUp() throws Exception {
    if (endpointDone.compareAndSet(false, true)) {
        // and whatnot, thus their lifecycle is to start once, and only to stop when Camel shutdown
        for (Route route : routes) {
            // ensure endpoint is started first (before the route services, such as the consumer)
            ServiceHelper.startService(route.getEndpoint());
        }
    }
    if (warmUpDone.compareAndSet(false, true)) {
        for (Route route : routes) {
            try (MDCHelper mdcHelper = new MDCHelper(route.getId())) {
                // warm up the route first
                route.warmUp();
                LOG.debug("Starting services on route: {}", route.getId());
                List<Service> services = route.getServices();
                // callback that we are staring these services
                route.onStartingServices(services);
                // gather list of services to start as we need to start child services as well
                Set<Service> list = new LinkedHashSet<Service>();
                for (Service service : services) {
                    list.addAll(ServiceHelper.getChildServices(service));
                }
                // split into consumers and child services as we need to start the consumers
                // afterwards to avoid them being active while the others start
                List<Service> childServices = new ArrayList<Service>();
                for (Service service : list) {
                    // inject the route
                    if (service instanceof RouteAware) {
                        ((RouteAware) service).setRoute(route);
                    }
                    if (service instanceof Consumer) {
                        inputs.put(route, (Consumer) service);
                    } else {
                        childServices.add(service);
                    }
                }
                startChildService(route, childServices);
                // fire event
                EventHelper.notifyRouteAdded(camelContext, route);
            }
        }
        // ensure lifecycle strategy is invoked which among others enlist the route in JMX
        for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
            strategy.onRoutesAdd(routes);
        }
        // add routes to camel context
        camelContext.addRouteCollection(routes);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Consumer(org.apache.camel.Consumer) LifecycleStrategy(org.apache.camel.spi.LifecycleStrategy) RouteAware(org.apache.camel.RouteAware) ArrayList(java.util.ArrayList) Service(org.apache.camel.Service) Route(org.apache.camel.Route)

Example 34 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class RouteService method doGetRouteScopedErrorHandler.

/**
     * Gather the route scoped error handler from the given route
     */
private void doGetRouteScopedErrorHandler(Set<Service> services, Route route) {
    // only include error handlers if they are route scoped
    boolean includeErrorHandler = !routeDefinition.isContextScopedErrorHandler(route.getRouteContext().getCamelContext());
    List<Service> extra = new ArrayList<Service>();
    if (includeErrorHandler) {
        for (Service service : services) {
            if (service instanceof Channel) {
                Processor eh = ((Channel) service).getErrorHandler();
                if (eh != null && eh instanceof Service) {
                    extra.add((Service) eh);
                }
            }
        }
    }
    if (!extra.isEmpty()) {
        services.addAll(extra);
    }
}
Also used : Processor(org.apache.camel.Processor) Channel(org.apache.camel.Channel) ArrayList(java.util.ArrayList) Service(org.apache.camel.Service)

Example 35 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class MappedEndpointConfiguration method toUriString.

@Override
public String toUriString(UriFormat format) {
    Set<Map.Entry<String, Object>> entries = params.entrySet();
    List<String> queryParams = new ArrayList<String>();
    String scheme = null;
    String schemeSpecificPart = null;
    String authority = null;
    String path = null;
    String fragment = null;
    TypeConverter converter = getCamelContext().getTypeConverter();
    // Separate URI values from query parameters
    for (Map.Entry<String, Object> entry : entries) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key.equals(EndpointConfiguration.URI_SCHEME)) {
            scheme = converter.convertTo(String.class, value);
        } else if (key.equals(EndpointConfiguration.URI_SCHEME_SPECIFIC_PART)) {
            schemeSpecificPart = converter.convertTo(String.class, value);
        } else if (key.equals(EndpointConfiguration.URI_AUTHORITY)) {
            authority = converter.convertTo(String.class, value);
        } else if (key.equals(EndpointConfiguration.URI_USER_INFO)) {
        // ignore, part of authority
        } else if (key.equals(EndpointConfiguration.URI_HOST)) {
        // ignore, part of authority
        } else if (key.equals(EndpointConfiguration.URI_PORT)) {
        // ignore, part of authority
        } else if (key.equals(EndpointConfiguration.URI_PATH)) {
            path = converter.convertTo(String.class, value);
        } else if (key.equals(EndpointConfiguration.URI_QUERY)) {
        // ignore, but this should not be the case, may be a good idea to log...
        } else if (key.equals(EndpointConfiguration.URI_FRAGMENT)) {
            fragment = converter.convertTo(String.class, value);
        } else {
            // convert to "param=value" format here, order will be preserved
            if (value instanceof List) {
                for (Object item : (List<?>) value) {
                    queryParams.add(key + "=" + UnsafeUriCharactersEncoder.encode(item.toString()));
                }
            } else {
                queryParams.add(key + "=" + UnsafeUriCharactersEncoder.encode(value.toString()));
            }
        }
    }
    queryParams.sort(null);
    String q = "";
    for (String entry : queryParams) {
        q += q.length() == 0 ? "" : "&";
        q += entry;
    }
    StringBuilder u = new StringBuilder(64);
    if (scheme != null) {
        // SHOULD NOT be null
        u.append(scheme);
        u.append(":");
    }
    if (authority != null) {
        u.append("//");
        u.append(authority);
        u.append(path);
        if (q.length() > 0) {
            u.append("?");
            u.append(q);
        }
        if (fragment != null) {
            u.append("#");
            u.append(fragment);
        }
    } else {
        // add leading // if not provided
        if (!schemeSpecificPart.startsWith("//")) {
            u.append("//");
        }
        u.append(schemeSpecificPart);
    }
    return u.toString();
}
Also used : TypeConverter(org.apache.camel.TypeConverter) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611