/** * Return a new position that is the addition of this position and that supplied. * * @param position the position to add to this object; may not be null * @return the combined position */ public Position add( Position position ) { if (this.getIndexInContent() < 0) { return position.getIndexInContent() < 0 ? EMPTY_CONTENT_POSITION : position; } if (position.getIndexInContent() < 0) { return this; } int index = this.getIndexInContent() + position.getIndexInContent(); int line = position.getLine() + this.getLine() - 1; int column = this.getLine() == 1 ? this.getColumn() + position.getColumn() : this.getColumn(); return new Position(index, line, column); } }
private int combinedIndex( int firstIndex, int secondIndex ) { Position first = new Position(firstIndex, 1, 0); Position second = new Position(secondIndex, 1, 0); int firstPlusSecond = first.add(second).getIndexInContent(); int secondPlusFirst = second.add(first).getIndexInContent(); assertThat(firstPlusSecond, is(secondPlusFirst)); return firstPlusSecond; }
private static final double WGS84_RADIUS = 6370997.0; private static double EarthCircumFence = 2* WGS84_RADIUS * Math.PI; private static Position getPosition(Position sourcePosition, double mEastWest, double mNorthSouth){ double degreesPerMeterForLat = EarthCircumFence/360.0; double shrinkFactor = Math.cos((sourcePosition.getLat()*Math.PI/180)); double degreesPerMeterForLon = degreesPerMeterForLat * shrinkFactor; double newLat = sourcePosition.getLat() + mNorthSouth * (1/degreesPerMeterForLat); double newLng = sourcePosition.getLng() + mEastWest * (1/degreesPerMeterForLon); return new Position(newLat, newLng); }
protected BindVariableName parseBindVariableName( TokenStream tokens, TypeSystem typeSystem ) { // The variable name must conform to a valid prefix, which is defined as a valid NCName ... String value = tokens.consume(); if (!XmlCharacters.isValidNcName(value)) { Position pos = tokens.previousPosition(); String msg = GraphI18n.bindVariableMustConformToNcName.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return bindVariableName(value); }
statementNode.setProperty(DDL_EXPRESSION, source); statementNode.setProperty(DDL_LENGTH, source.length()); statementNode.setProperty(DDL_START_LINE_NUMBER, currentMarkedPosition.getLine()); statementNode.setProperty(DDL_START_CHAR_INDEX, currentMarkedPosition.getIndexInContent()); statementNode.setProperty(DDL_START_COLUMN_NUMBER, currentMarkedPosition.getColumn());
var p = new Position({ capital: 10000, tolerableRiskInPercentOfCapitalPerTrade: 2, direction: Direction.LONG, pricePerUnit: 25, stopLossPricePerUnit: 24 });
@Test public void shouldParseMultiLineString() { printTest("shouldParseMultiLineString()"); String content = "ALTER DATABASE \n" + "DO SOMETHING; \n" + "ALTER DATABASE \n" + " SET DEFAULT BIGFILE TABLESPACE;"; DdlTokenStream tokens = getTokens(content); // Do the work tokens.start(); tokens.consume(); // LINE tokens.consume(); // ONE tokens.consume(); // DO tokens.consume(); // SOMETHING tokens.consume(); // ; assertThat(tokens.nextPosition().getIndexInContent(), is(31)); assertThat(tokens.nextPosition().getColumn(), is(1)); tokens.consume(); // ALTER assertThat(tokens.nextPosition().getIndexInContent(), is(37)); assertThat(tokens.nextPosition().getColumn(), is(7)); }
private boolean solveMaze(Position p){ if(!p.isOnMaze(this)) { return false; } if(p.equals(goal)) { return true; } if(!map[p.getRow()][p.getColumn()].equals(MazeSymbol.OPEN)) { // See NOTE 1 return false; } map[p.getRow()][p.getColumn()] = MazeSymbol.PATH; solutionPath.add(p); if(solveMaze(p.positionAbove())) return true; // See NOTE 2 if(solveMaze(p.positionLeft())) return true; if(solveMaze(p.positionBelow())) return true; if(solveMaze(p.positionRight())) return true; solutionPath.remove(solutionPath.size() - 1); // See NOTE 3 map[p.getRow()][p.getColumn()] = MazeSymbol.DEAD_END; return false; }
/** * Gets the content string starting at the first position (inclusive) and continuing up to the end position (exclusive). * * @param starting the position marking the beginning of the desired content string. * @param end the position located directly after the returned content string; can be null, which means end of content * @return the content string; never null */ public String getContentBetween( Position starting, Position end ) { CheckArg.isNotNull(starting, "starting"); int startIndex = starting.getIndexInContent(); int endIndex = inputString.length(); if (end != null) { endIndex = end.getIndexInContent(); } if (startIndex >= endIndex) { throw new IllegalArgumentException(CommonI18n.endPositionMustBeGreaterThanStartingPosition.text(startIndex, endIndex)); } return inputString.substring(startIndex, endIndex); }
return getJdbcTemplate.query(sql, new RowMapper<Position>() { public Position mapRow(ResultSet rs, int row) throws SQLException, DataAccessException { Position p = new Position(); p.setId(rs.getString("id")); p.setPositionName(rs.getString("position_name")); p.setDescription(rs.getString("description")); return p; }, id); }
Position wrapCircle(Circle circle, int width, int height) { final int radius = circle.getRadius(); final Position pos = circle.getPosition(); final int oldX = pos.getX(); final int x = (oldX > width + radius) ? -radius : ( (oldX < -radius) ? (width + radius) : oldX); final int y = // similar return new Position(x, y); } circle.setPosition(wrapCircle(circle, width, height));
protected Term parseFullTextSearchExpression( String expression, Position startOfExpression ) { try { return new FullTextSearchParser().parse(expression); } catch (ParsingException e) { // Convert the position in the exception into a position in the query. Position queryPos = startOfExpression.add(e.getPosition()); throw new ParsingException(queryPos, e.getMessage()); } }
protected BindVariableName parseBindVariableName( TokenStream tokens, TypeSystem typeSystem ) { // The variable name must conform to a valid prefix, which is defined as a valid NCName ... String value = tokens.consume(); if (!XmlCharacters.isValidNcName(value)) { Position pos = tokens.previousPosition(); String msg = GraphI18n.bindVariableMustConformToNcName.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return bindVariableName(value); }
statementNode.setProperty(DDL_EXPRESSION, source); statementNode.setProperty(DDL_LENGTH, source.length()); statementNode.setProperty(DDL_START_LINE_NUMBER, currentMarkedPosition.getLine()); statementNode.setProperty(DDL_START_CHAR_INDEX, currentMarkedPosition.getIndexInContent()); statementNode.setProperty(DDL_START_COLUMN_NUMBER, currentMarkedPosition.getColumn());
while (!cJoin.isAfterLast()) { Position p = new Position(); p.mLat = cJoin.getString(1); p.mLon = cJoin.getString(0); latLon[index++] = p; }
@Test public void shouldParseMultiLineString() { makeCaseInsensitive(); String content = "ALTER DATABASE \n" + "DO SOMETHING; \n" + "ALTER DATABASE \n" + " SET DEFAULT BIGFILE TABLESPACE;"; tokens = new TokenStream(content, tokenizer, true); tokens.start(); tokens.consume(); // LINE tokens.consume(); // ONE tokens.consume(); // DO tokens.consume(); // SOMETHING tokens.consume(); // ; assertThat(tokens.nextPosition().getIndexInContent(), is(31)); assertThat(tokens.nextPosition().getColumn(), is(1)); tokens.consume(); // ALTER assertThat(tokens.nextPosition().getIndexInContent(), is(37)); assertThat(tokens.nextPosition().getColumn(), is(7)); } }
/** * Gets the content string starting at the first position (inclusive) and continuing up to the end position (exclusive). * * @param starting the position marking the beginning of the desired content string. * @param end the position located directly after the returned content string; can be null, which means end of content * @return the content string; never null */ public String getContentBetween( Position starting, Position end ) { CheckArg.isNotNull(starting, "starting"); int startIndex = starting.getIndexInContent(); int endIndex = inputString.length(); if (end != null) { endIndex = end.getIndexInContent(); } if (startIndex >= endIndex) { throw new IllegalArgumentException(CommonI18n.endPositionMustBeGreaterThanStartingPosition.text(startIndex, endIndex)); } return inputString.substring(startIndex, endIndex); }