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

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

Introduction

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

Prototype

public static <T> T getLast(Iterable<T> iterable) 

Source Link

Document

Returns the last element of iterable .

Usage

From source file:com.github.fge.jsonpatch.operation.ReplaceOperation.java

@Override
public JsonNode apply(final JsonNode node) throws JsonPatchException {
    /*// w ww  . j  a  v a  2s.c  o m
     * FIXME cannot quite be replaced by a remove + add because of arrays.
     * For instance:
     *
     * { "op": "replace", "path": "/0", "value": 1 }
     *
     * with
     *
     * [ "x" ]
     *
     * If remove is done first, the array is empty and add rightly complains
     * that there is no such index in the array.
     */
    if (path.path(node).isMissingNode())
        throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
    final JsonNode replacement = value.deepCopy();
    if (path.isEmpty())
        return replacement;
    final JsonNode ret = node.deepCopy();
    final JsonNode parent = path.parent().get(ret);
    final String rawToken = Iterables.getLast(path).getToken().getRaw();
    if (parent.isObject())
        ((ObjectNode) parent).put(rawToken, replacement);
    else
        ((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement);
    return ret;
}

From source file:org.b1.pack.cli.FsFolderContent.java

private FolderBuilder getParentBuilder(List<String> path) throws IOException {
    List<String> key = path.subList(0, path.size() - 1);
    FolderBuilder builder = builderMap.get(key);
    if (builder == null) {
        builder = getParentBuilder(key).addFolder(new FsPackEntry(Iterables.getLast(path), null));
        builderMap.put(key, builder);//w ww .  j ava2s  .  c om
    }
    return builder;
}

From source file:org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndCatalogNameToEndpoint.java

@SuppressWarnings("unchecked")
public URI apply(Object from) {
    Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
    Object org = Iterables.get(orgCatalog, 0);
    Object catalog = Iterables.get(orgCatalog, 1);
    if (org == null && catalog == null)
        return defaultCatalog.get().getHref();
    else if (org == null)
        org = defaultOrg.get().getName();

    try {//w  w  w.j a v a  2  s  .c om
        Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
        return catalog == null ? Iterables.getLast(catalogs.values()).getHref()
                : catalogs.get(catalog).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
    }
}

From source file:org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndVDCNameToEndpoint.java

@SuppressWarnings("unchecked")
public URI apply(Object from) {
    Iterable<Object> orgVdc = (Iterable<Object>) checkNotNull(from, "args");
    Object org = Iterables.get(orgVdc, 0);
    Object vdc = Iterables.get(orgVdc, 1);
    if (org == null && vdc == null)
        return defaultVDC.get().getHref();
    else if (org == null)
        org = defaultOrg.get().getName();

    try {//from  w  w w .  ja  v a2  s  . c  om
        Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
        return vdc == null ? Iterables.getLast(vdcs.values()).getHref() : vdcs.get(vdc).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVDCEndpoint.get());
    }
}

From source file:com.waratek.cloudvm.SimpleJavaApplication.java

@Override
public void init() {
    String mainClass = Iterables.getLast(Splitter.on(".").split(getConfig(MAIN_CLASS)));

    addChild(EntitySpec.create(WaratekApplicationCluster.class)
            .displayName("Waratek " + mainClass + " Application")
            .configure(DynamicCluster.INITIAL_SIZE, getConfig(INITIAL_SIZE))
            .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(WaratekJavaApplication.class)
                    .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true)
                    .configure(DynamicCluster.ZONE_PLACEMENT_STRATEGY, new WaratekNodePlacementStrategy())
                    .configure(UsesJmx.USE_JMX, Boolean.FALSE)
                    .configure(WaratekJavaApplication.ARGS, getConfig(ARGS))
                    .configure(WaratekJavaApplication.MAIN_CLASS, getConfig(MAIN_CLASS))
                    .configure(WaratekJavaApplication.CLASSPATH, getConfig(CLASSPATH))
                    .configure(WaratekJavaApplication.JVM_DEFINES, Maps.<String, Object>newHashMap())
                    .configure(WaratekJavaApplication.JVM_XARGS, Lists.<String>newArrayList())));
}

From source file:org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndTasksListNameToEndpoint.java

@SuppressWarnings("unchecked")
public URI apply(Object from) {
    Iterable<Object> orgTasksList = (Iterable<Object>) checkNotNull(from, "args");
    Object org = Iterables.get(orgTasksList, 0);
    Object tasksList = Iterables.get(orgTasksList, 1);
    if (org == null && tasksList == null)
        return defaultTasksList.get().getHref();
    else if (org == null)
        org = defaultOrg.get().getName();

    try {//  ww  w. j  ava 2  s .c  o  m
        Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();
        return tasksList == null ? Iterables.getLast(tasksLists.values()).getHref()
                : tasksLists.get(tasksList).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get());
    }
}

From source file:jflowmap.views.flowmap.FlowMapView.java

public FlowMapView(VisualFlowMapModel model, GeoMap areaMap, MapProjection proj, IFlowMapColorScheme cs,
        ViewConfig config) {// ww  w .  jav a2s  .c om
    this.viewConfig = config;

    FlowMapGraph fmg = model.getFlowMapGraph();

    setVisualFlowMap(createVisualFlowMap(model, proj, Iterables.getLast(fmg.getEdgeWeightAttrs()), cs));
    if (areaMap != null) {
        visualFlowMap.setAreaMap(new PGeoMap(visualFlowMap, areaMap, proj));
    }
    if (cs != null) {
        setColorScheme(cs);
    }

    VisualCanvas canvas = getVisualCanvas();
    canvas.setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
    canvas.setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);

    visualFlowMap.setFlowWeightAttrLabelVisibile(
            config.getBoolOrElse(VisualFlowMapModel.VIEWCONF_SHOW_FLOW_WEIGHT_ATTR_LABEL, false));

    addDiffButton(visualFlowMap);

    controlPanel = new ControlPanel(this, fmg.getAttrSpec());

    getCamera().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName() == PCamera.PROPERTY_VIEW_TRANSFORM) {
                if (logger.isDebugEnabled()) {
                    PBounds fb = getVisualFlowMap().getVisualNodesBounds();
                    PBounds b = getCamera().getViewBounds();
                    double areap = (b.width * b.height) / (fb.width * fb.height / 100);
                    logger.debug("View transform to " + b + " (" + FlowMapView.NUMBER_FORMAT.format(areap)
                            + "% of visible area)");
                }
            }
        }
    });

    fitInView();
}

From source file:com.google.security.zynamics.reil.ReilBlock.java

@Override
public ReilInstruction getLastInstruction() {
    return Iterables.getLast(instructions);
}

From source file:org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndCatalogNameToEndpoint.java

@SuppressWarnings("unchecked")
@Override//from www. jav a2s  . c  o  m
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
    Object org = postParams.get("orgName");
    Object catalog = postParams.get("catalogName");
    if (org == null && catalog == null)
        return (R) request.toBuilder().endpoint(defaultCatalog.get().getHref()).build();
    else if (org == null)
        org = defaultOrg.get().getName();

    try {
        Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
        URI endpoint = catalog == null ? Iterables.getLast(catalogs.values()).getHref()
                : catalogs.get(catalog).getHref();
        return (R) request.toBuilder().endpoint(endpoint).build();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
    }
}

From source file:com.github.fge.jsonpatch.operation.RemoveOperation.java

@Override
public JsonNode apply(final JsonNode node) throws JsonPatchException {
    if (path.isEmpty())
        return MissingNode.getInstance();
    if (path.path(node).isMissingNode())
        throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
    final JsonNode ret = node.deepCopy();
    final JsonNode parentNode = path.parent().get(ret);
    final String raw = Iterables.getLast(path).getToken().getRaw();
    if (parentNode.isObject())
        ((ObjectNode) parentNode).remove(raw);
    else//from  www  .j ava 2  s .  c om
        ((ArrayNode) parentNode).remove(Integer.parseInt(raw));
    return ret;
}