List of usage examples for com.google.common.collect Iterables getLast
public static <T> T getLast(Iterable<T> iterable)
From source file:com.google.security.zynamics.reil.yfileswrap.algorithms.mono2.common.instructiongraph.CReilInstructionGraph.java
public CReilInstructionGraph(final ReilGraph graph) { final HashMap<ReilBlock, Node> firstNodeMapping = new HashMap<ReilBlock, Node>(); final HashMap<ReilBlock, Node> lastNodeMapping = new HashMap<ReilBlock, Node>(); for (final ReilBlock block : graph) { Node lastNode = null;// w w w . j av a 2 s. co m final ReilInstruction lastInstruction = Iterables.getLast(block.getInstructions()); for (final ReilInstruction instruction : block) { final Node currentNode = createInstructionNode(instruction); if (instruction == lastInstruction) { lastNodeMapping.put(block, currentNode); } if (!firstNodeMapping.containsKey(block)) { firstNodeMapping.put(block, currentNode); } if (lastNode != null) { createInstructionEdge(lastNode, currentNode, true); } lastNode = currentNode; } } for (final ReilBlock block : graph) { for (final ReilEdge edge : block.getOutgoingEdges()) { createInstructionEdge(lastNodeMapping.get(block), firstNodeMapping.get(edge.getTarget()), EdgeType.isTrueEdge(edge.getType())); } } // Add edges from the entry node to all nodes of in degree zero, // and edges to the exit nodes to all nodes of out degree zero. final NodeCursor nodeCursor = m_internalGraph.nodes(); final List<Node> entryNodes = new ArrayList<Node>(); final List<Node> exitNodes = new ArrayList<Node>(); while (nodeCursor.ok()) { if (((Node) nodeCursor.current()).inDegree() == 0) { entryNodes.add((Node) nodeCursor.current()); } if (((Node) nodeCursor.current()).outDegree() == 0) { exitNodes.add((Node) nodeCursor.current()); } nodeCursor.next(); } m_entryNode = createInstructionNode(ReilHelpers.createNop(0)); m_exitNode = createInstructionNode(ReilHelpers.createNop(0xFFFFFF00)); for (final Node entryNode : entryNodes) { createInstructionEdge(m_entryNode, entryNode, true); } for (final Node exitNode : exitNodes) { createInstructionEdge(exitNode, m_exitNode, true); } }
From source file:net.holmes.core.business.streaming.airplay.controlpoint.CommandResponse.java
/** * Decode content parameters./* w w w . j av a 2s .c o m*/ * * @param content content */ public void decodeContentParameters(String content) { for (String line : Splitter.on(EOL).split(content)) { Iterable<String> it = Splitter.on(PARAMETER_SEPARATOR).trimResults().split(line); if (Iterables.size(it) > 1) { contentParameters.put(Iterables.get(it, 0), Iterables.getLast(it)); } } }
From source file:com.fusionx.lightirc.ui.ChannelFragment.java
@OnClick(R.id.auto_complete_button) public void onAutoCompleteClick(final ImageButton autoComplete) { if (isPopupShown) { mPopupMenu.dismiss();//from w w w .j a v a 2 s . com } else { // TODO - this needs to be synchronized properly final Collection<WorldUser> users = getChannel().getUsers(); final List<WorldUser> sortedList = new ArrayList<>(users.size()); final String message = mMessageBox.getText().toString(); final String finalWord = Iterables.getLast(IRCUtils.splitRawLine(message, false)); for (final WorldUser user : users) { if (StringUtils.startsWithIgnoreCase(user.getNick(), finalWord)) { sortedList.add(user); } } if (sortedList.size() == 1) { changeLastWord(Iterables.getLast(sortedList).getNick()); } else if (sortedList.size() > 1) { if (mPopupMenu == null) { mPopupMenu = new PopupMenu(getActivity(), autoComplete); mPopupMenu.setOnDismissListener(this); mPopupMenu.setOnMenuItemClickListener(this); } final Menu innerMenu = mPopupMenu.getMenu(); innerMenu.clear(); Collections.sort(sortedList, new IRCUserComparator(getChannel())); for (final WorldUser user : sortedList) { innerMenu.add(user.getNick()); } mPopupMenu.show(); } } }
From source file:com.pressassociation.pr.ast.visitor.FindFieldsVisitor.java
private Field getEnd() { // we know this is safe because all of the Fields have been expanded return (Field) Iterables.getLast(result).getNext(); }
From source file:com.google.template.soy.passes.ConditionalBranches.java
/** * Checks if the list of branches contains a "default" conditional branch (i.e., a {@code * IfElseNode} or a {@code SwitchDefaultNode} at the end of the list). * * <p>If this is true, we will try to match {@code TagName} for all branches. *//*w w w . j a v a 2 s .c o m*/ private boolean hasDefaultCond() { if (branches.isEmpty()) { return false; } return Iterables.getLast(branches).condition().isDefaultCond(); }
From source file:com.confighub.api.repository.user.files.GetFilePreview.java
@POST @Path("/{account}/{repository}") @Produces("application/json") public Response add(@PathParam("account") String account, @PathParam("repository") String repositoryName, @HeaderParam("Authorization") String token, MultivaluedMap<String, String> formParams, @FormParam("ts") Long ts, @FormParam("tag") String tagLabel, @FormParam("context") String contextString, @FormParam("fileContent") String fileContent, @FormParam("password") String password) { JsonObject json = new JsonObject(); Gson gson = new Gson(); Store store = new Store(); try {//from www. jav a2s . c o m int status = validate(account, repositoryName, token, store); if (0 != status) return Response.status(status).build(); Date dateObj = DateTimeUtils.dateFromTsOrTag( Utils.isBlank(tagLabel) ? null : store.getTag(repository.getId(), tagLabel), ts, repository.getCreateDate()); Collection<CtxLevel> ctx = ContextParser.parseAndCreate(contextString, repository, store, user, dateObj); Context context = new Context(store, repository, ctx, dateObj, false); if (!context.isFullContext()) throw new ConfigException(Error.Code.PARTIAL_CONTEXT); Map<PropertyKey, Collection<Property>> keyListMap = context.resolve(); Map<String, Property> keyValueMap = new HashMap<>(); if (null != keyListMap) { for (PropertyKey key : keyListMap.keySet()) keyValueMap.put(key.getKey(), Iterables.getLast(keyListMap.get(key))); } json.addProperty("content", FileUtils.previewFile(context, fileContent, keyValueMap, formParams)); json.addProperty("success", true); return Response.ok(gson.toJson(json), MediaType.APPLICATION_JSON).build(); } catch (ConfigException e) { json.addProperty("success", false); json.addProperty("message", e.getMessage()); json.add("culprit", e.getJson()); return Response.ok(gson.toJson(json), MediaType.APPLICATION_JSON).build(); } finally { store.close(); } }
From source file:com.github.fge.jsonpatch.operation.AddOperation.java
protected JsonNode addToArray(final JsonPointer path, final JsonNode node) throws JsonPatchException { final JsonNode ret = node.deepCopy(); final ArrayNode target = (ArrayNode) path.parent().get(ret); final TokenResolver<JsonNode> token = Iterables.getLast(path); if (token.getToken().equals(LAST_ARRAY_ELEMENT)) { target.add(value);/*from www .j a va 2 s . c om*/ return ret; } final int size = target.size(); final int index; try { index = Integer.parseInt(token.toString()); } catch (NumberFormatException ignored) { throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.notAnIndex")); } if (index < 0 || index > size) throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchIndex")); target.insert(index, value); return ret; }
From source file:org.sonar.java.checks.ObjectFinalizeOverridenCallsSuperFinalizeCheck.java
private static boolean isLastStatement(@Nullable BlockTree blockTree, MethodInvocationTree lastStatementTree) { if (blockTree != null) { StatementTree last = Iterables.getLast(blockTree.body()); if (last.is(Kind.EXPRESSION_STATEMENT)) { return lastStatementTree.equals(((ExpressionStatementTree) last).expression()); } else if (last.is(Kind.TRY_STATEMENT)) { return isLastStatement(((TryStatementTree) last).finallyBlock(), lastStatementTree); }/*from w w w . j a v a2 s.com*/ } return false; }
From source file:com.willwinder.universalgcodesender.gcode.processors.ArcExpander.java
@Override public List<String> processCommand(String command, GcodeState state) throws GcodeParserException { if (state.currentPoint == null) throw new GcodeParserException(Localization.getString("parser.processor.arc.start-error")); List<String> results = new ArrayList<>(); List<GcodeMeta> commands = GcodeParser.processCommand(command, 0, state); // If this is not an arc, there is nothing to do. Code c = hasArcCommand(commands);//from www . j a v a 2s. c o m if (c == null) { return Collections.singletonList(command); } SplitCommand sc = GcodePreprocessorUtils.extractMotion(c, command); if (sc.remainder.length() > 0) { results.add(sc.remainder); } GcodeMeta arcMeta = Iterables.getLast(commands); PointSegment ps = arcMeta.point; Position start = state.currentPoint; Position end = arcMeta.point.point(); List<Position> points = GcodePreprocessorUtils.generatePointsAlongArcBDring(start, end, ps.center(), ps.isClockwise(), ps.getRadius(), 0, this.length, new PlaneFormatter(ps.getPlaneState())); // That function returns the first and last points. Exclude the first // point because the previous gcode command ends there already. points.remove(0); if (convertToLines) { // Tack the speed onto the first line segment in case the arc also // changed the feed value. String feed = "F" + arcMeta.point.getSpeed(); for (Position point : points) { results.add( GcodePreprocessorUtils.generateLineFromPoints(G1, start, point, state.inAbsoluteMode, df) + feed); start = point; feed = ""; } } else { // TODO: Generate arc segments. throw new UnsupportedOperationException("I have not implemented this."); } return results; }
From source file:com.google.api.tools.framework.aspects.http.validators.HttpConfigAspectValidator.java
private void checkQueryParameterConstraints(Method method, HttpAttribute binding) { checkHttpQueryParameterConstraints(method, FluentIterable.from(binding.getParamSelectors()).transform(new Function<FieldSelector, Field>() { @Override// w w w.ja va 2s . c om public Field apply(FieldSelector selector) { return Iterables.getLast(selector.getFields()); } }), Sets.<MessageType>newHashSet()); }