Read a polyelement.

@param elementIndex is the index of the element inside the shape file
@return an object representing the creating point, depending of your implementation.
This value will be passed to {@link #postRecordReadingStage(E)}.
197279
@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
	private E readPolyElement(int elementIndex, ShapeElementType type) throws IOException {
		final boolean hasZ = type.hasZ();
		final boolean hasM = type.hasM();

		// Ignore the bounds stored inside the file
		skipBytes(8 * 4);

		// Count of parts
		final int numParts;
		if (type == ShapeElementType.MULTIPOINT || type == ShapeElementType.MULTIPOINT_Z
				|| type == ShapeElementType.MULTIPOINT_M) {
			numParts = 0;
		} else {
			numParts = readLEInt();
		}

		// Count of points
		final int numPoints = readLEInt();

		// Read the parts' indexes
		final int[] parts = new int[numParts];
		for (int idxParts = 0; idxParts < numParts; ++idxParts) {
			parts[idxParts] = readLEInt();
		}

		// Read the points
		final ESRIPoint[] points = new ESRIPoint[numPoints];

		for (int idxPoints = 0; idxPoints < numPoints; ++idxPoints) {
			// Read coordinates
			final double x = fromESRI_x(readLEDouble());
			final double y = fromESRI_y(readLEDouble());

			// Create point
			if (!Double.isNaN(x) && !Double.isNaN(y)) {
				points[idxPoints] = new ESRIPoint(x, y);
			} else {
				throw new ShapeFileException("invalid (x,y) coordinates"); //$NON-NLS-1$
			}
		} // for i= 0 to numPoints

		if (hasZ) {
			// Zmin and Zmax: 2*Double - ignored
			skipBytes(2 * 8);
			// Z array: numpoints*Double
			double z;
			for (int i = 0; i < numPoints; ++i) {
				z = fromESRI_z(readLEDouble());
				if (!Double.isNaN(z)) {
					points[i].setZ(z);
				}
			}
		}

		if (hasM) {
			// Mmin and Mmax: 2*Double - ignored
			skipBytes(2 * 8);
			// M array: numpoints*Double
			double measure;
			for (int i = 0; i < numPoints; ++i) {
				measure = fromESRI_m(readLEDouble());
				if (!Double.isNaN(measure)) {
					points[i].setM(measure);
				}
			}
		}

		// Create the instance of the element
		E newElement = null;
		switch (type) {
		case POLYGON_Z:
		case POLYGON_M:
		case POLYGON:
			newElement = createPolygon(createAttributeCollection(elementIndex), elementIndex, parts, points, hasZ);
			break;
		case POLYLINE_Z:
		case POLYLINE_M:
		case POLYLINE:
			newElement = createPolyline(createAttributeCollection(elementIndex), elementIndex, parts, points, hasZ);
			break;
		case MULTIPOINT:
		case MULTIPOINT_M:
		case MULTIPOINT_Z:
			newElement = createMultiPoint(createAttributeCollection(elementIndex), elementIndex, points, hasZ);
			break;
			//$CASES-OMITTED$
		default:
		}

		return newElement;
	}
121046
@Override
    public void startElement( String uri, String localName, String qName, Attributes attributes )
        throws SAXException
    {
        flushCharacters();
        IndentCheckSaxHandler.ElementEntry currentEntry = new ElementEntry( qName, lastIndent );
        if ( !stack.isEmpty() )
        {
            IndentCheckSaxHandler.ElementEntry parentEntry = stack.peek();
            /*
             * note that we use parentEntry.expectedIndent rather than parentEntry.foundIndent this is to make the
             * messages more useful
             */
            int indentDiff = currentEntry.foundIndent.size - parentEntry.expectedIndent.size;
            int expectedIndent = parentEntry.expectedIndent.size + indentSize;
            if ( indentDiff == 0 && currentEntry.foundIndent.lineNumber == parentEntry.foundIndent.lineNumber )
            {
                /*
                 * Zero foundIndent acceptable only if current is on the same line as parent This is OK, therefore do
                 * nothing
                 */
            }
            else if ( indentDiff != indentSize )
            {
                /* generally unexpected foundIndent */
                int opValue = expectedIndent - currentEntry.foundIndent.size;
                String op = opValue > 0 ? "Insert" : "Delete";
                String message = op + " " + Math.abs( opValue ) + " spaces. Expected " + expectedIndent + " found "
                    + currentEntry.foundIndent.size + " spaces before start element <" + currentEntry.elementName + ">";

                XmlFormatViolation violation =
                    new XmlFormatViolation( file, locator.getLineNumber(), locator.getColumnNumber(), message );
                violationHandler.handle( violation );

                /* reset the expected indent in the entry we'll push */
                currentEntry =
                    new ElementEntry( qName, lastIndent, new Indent( lastIndent.lineNumber, expectedIndent ) );
            }
        }
        stack.push( currentEntry );
    }
1372148
public <T extends Collection<V>, V> T readAsCollection(byte[] content,
                                                           Class<? extends Collection> collectionType,
                                                           Class<V> elementsType) {
        return readAsCollection(new String(content), collectionType, elementsType);
    }
697910
def __shapeIndex(self, i=None):
        """"""
        shx = self.shx
        if not shx:
            return None
        if not self._offsets:
            # File length (16-bit word * 2 = bytes) - header length
            shx.seek(24)
            shxRecordLength = (unpack(">i", shx.read(4))[0] * 2) - 100
            numRecords = shxRecordLength // 8
            # Jump to the first record.
            shx.seek(100)
            for r in range(numRecords):
                # Offsets are 16-bit words just like the file length
                self._offsets.append(unpack(">i", shx.read(4))[0] * 2)
                shx.seek(shx.tell() + 4)
        if not i == None:
            return self._offsets[i]
787406
protected AstNode parseCreateIndex( DdlTokenStream tokens,
                                        AstNode parentNode ) throws ParsingException {
        assert tokens != null;
        assert parentNode != null;

        markStartOfStatement(tokens);
        // CREATE [UNIQUE] INDEX index-Name
        // ON table-Name ( Simple-column-Name [ ASC | DESC ] [ , Simple-column-Name [ ASC | DESC ]] * )
        tokens.consume(CREATE); // CREATE

        boolean isUnique = tokens.canConsume("UNIQUE");

        tokens.consume("INDEX");
        String indexName = parseName(tokens);
        tokens.consume("ON");
        String tableName = parseName(tokens);

        AstNode indexNode = nodeFactory().node(indexName, parentNode, TYPE_CREATE_INDEX_STATEMENT);

        indexNode.setProperty(UNIQUE_INDEX, isUnique);
        indexNode.setProperty(TABLE_NAME, tableName);

        parseIndexTableColumns(tokens, indexNode);

        parseUntilTerminator(tokens);

        markEndOfStatement(tokens, indexNode);

        return indexNode;
    }
979138
@Override
    public T get(int index) {
        /* Check that this is a valid index. */
        if (index < 0 || index >= size())
            throw new IndexOutOfBoundsException("Index " + index + ", size " + size());

        /* Look up the element. */
        return mArrays[computeOffset(index)][computeIndex(index)];
    }
595256
private long readPointer(int logicalPosition) {
		if (logicalPosition < 0 || logicalPosition >= this.numRecords) {
			throw new IndexOutOfBoundsException();
		}
		
		final int bufferNum = logicalPosition / this.indexEntriesPerSegment;
		final int segmentOffset = logicalPosition % this.indexEntriesPerSegment;
		
		return (this.sortIndex.get(bufferNum).getLong(segmentOffset * this.indexEntrySize)) & POINTER_MASK;
	}
123617
def element(i)
      unless i.matched?
        unless (0 ... shape.last).member? i
          raise "Index must be in 0 ... #{shape.last} (was #{i})"
        end
        i = INT.new i
      end
      i.size = @index.size if i.is_a?(Variable) and @index.size.get
      @term.subst @index => i
    end
1306691
Set<ElementPosition> print(
        ChronoDisplay formattable,
        Appendable buffer,
        AttributeQuery attributes,
        boolean withPositions
    ) throws IOException {

        if (buffer == null) {
            throw new NullPointerException("Missing text result buffer.");
        }

        int index = 0;
        int len = this.steps.size();

        Set<ElementPosition> positions = null;
        boolean quickPath = (attributes == this.globalAttributes);

        if (withPositions) {
            positions = new LinkedHashSet<>(len);
        }

        if (this.hasOrMarkers) {
            Deque<StringBuilder> collectorStack = new LinkedList<>();
            StringBuilder buf = new StringBuilder(len << 2);
            collectorStack.push(buf);

            Deque<Set<ElementPosition>> positionStack = null;
            if (withPositions) {
                positionStack = new LinkedList<>();
                positionStack.push(positions);
            }

            int previous = 0;
            int current = 0;

            while (index < len) {
                FormatStep step = this.steps.get(index);
                current = step.getLevel();
                int level = current;

                // Start einer optionalen Sektion: Stack erweitern
                while (level > previous) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(collectorStack.peek());
                    collectorStack.push(sb);
                    if (withPositions) {
                        positions = new LinkedHashSet<>();
                        positions.addAll(positionStack.peek());
                        positionStack.push(positions);
                    }
                    level--;
                }

                // Ende einer optionalen Sektion: Werte im Stack sichern
                while (level < previous) {
                    buf = collectorStack.pop();
                    collectorStack.pop();
                    collectorStack.push(buf);
                    if (withPositions) {
                        positions = positionStack.pop();
                        positionStack.pop();
                        positionStack.push(positions);
                    }
                    level++;
                }

                buf = collectorStack.peek();
                if (withPositions) {
                    positions = positionStack.peek();
                }

                RuntimeException re = null;
                int printed = -1;

                try {
                    printed = step.print(formattable, buf, attributes, positions, quickPath);
                } catch (ChronoException | IllegalArgumentException ex) {
                    re = ex;
                }

                if (printed == -1) {
                    // Fehlerfall: nächsten oder-Block suchen
                    int section = step.getSection();
                    int last = index;

                    if (!step.isNewOrBlockStarted()) {
                        for (int j = index + 1; j < len; j++) {
                            FormatStep test = this.steps.get(j);
                            if (test.isNewOrBlockStarted() && (test.getSection() == section)) {
                                last = j;
                                break;
                            }
                        }
                    }

                    if ((last > index) || step.isNewOrBlockStarted()) {
                        // wenn gefunden, zum nächsten oder-Block springen
                        collectorStack.pop();
                        StringBuilder sb = new StringBuilder();
                        if (!collectorStack.isEmpty()) {
                            sb.append(collectorStack.peek());
                        }
                        collectorStack.push(sb);
                        if (withPositions) {
                            positionStack.pop();
                            Set<ElementPosition> ep = new LinkedHashSet<>();
                            if (!positionStack.isEmpty()) {
                                ep.addAll(positionStack.peek());
                            }
                            positionStack.push(ep);
                        }
                        index = last;
                    } else if (re == null) {
                        throw new IllegalArgumentException("Not formattable: " + formattable);
                    } else {
                        throw new IllegalArgumentException("Not formattable: " + formattable, re);
                    }
                } else if (step.isNewOrBlockStarted()) {
                    index = step.skipTrailingOrBlocks();
                }

                // Schleifenzähler inkrementieren
                previous = current;
                index++;
            }

            // Verbleibende optionale Sektionen auflösen und Ergebnis schreiben
            buf = collectorStack.peek();
            collectorStack.clear();
            buffer.append(buf);

            if (withPositions) {
                positions = positionStack.peek();
                positionStack.clear();
            }
        } else {
            try {
                while (index < len) {
                    FormatStep step = this.steps.get(index);
                    step.print(formattable, buffer, attributes, positions, quickPath);

                    if (step.isNewOrBlockStarted()) {
                        index = step.skipTrailingOrBlocks();
                    }

                    index++;
                }
            } catch (ChronoException ex) {
                throw new IllegalArgumentException("Not formattable: " + formattable, ex);
            }
        }

        if (withPositions) {
            return Collections.unmodifiableSet(positions);
        } else {
            return null;
        }

    }
297851
@Override
    public <T> T read(final Class<T> projectionInterface) throws IOException {
        try {
            Document document = projector.config().createDocumentBuilder().parse(file);
            return projector.projectDOMNode(document, projectionInterface);
        } catch (SAXException e) {
            throw new XBDocumentParsingException(e);
        }
    }
416516
public PathElement getElement(int index) {
        final List<PathElement> list = pathAddressList;
        return list.get(index);
    }
254231
public void setIndex(int index) {
        ElementBase parent = getParent();
        
        if (parent == null) {
            CWFException.raise("Element has no parent.");
        }
        
        int currentIndex = parent.children.indexOf(this);
        
        if (currentIndex < 0 || currentIndex == index) {
            return;
        }
        
        parent.moveChild(currentIndex, index);
    }
156588
@Override
    public Object set(int index, Object element) {
        if (cleared) {
            throw new JeppettoException("set() after clear() not supported");
        }

        return updates.put(String.format(indexFormat, index), element);
    }
721787
public long indexOf(final String element) {
        return doWithJedis(new JedisCallable<Long>() {
            @Override
            public Long call(Jedis jedis) {
                return doIndexOf(jedis, element);
            }
        });
    }
827526
def readPiece(pieceIndex)
      id = returnAndIncrRequestId
      return id if @state == :after_stop
      @requests.push [id, :read_piece, pieceIndex]
      @requestsSemaphore.signal
      id
    end
71403
@Pure
	public static ShapeElementType toESRI(Class<? extends MapElement> type) {
		if (MapPolyline.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYLINE;
		}
		if (MapPolygon.class.isAssignableFrom(type)) {
			return ShapeElementType.POLYGON;
		}
		if (MapMultiPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.MULTIPOINT;
		}
		if (MapPoint.class.isAssignableFrom(type)) {
			return ShapeElementType.POINT;
		}
		throw new IllegalArgumentException();
	}
561217
protected synchronized void makeIndex() throws Exception {
        File indexFile = getIndexFile(filename);
        if (indexFile.exists()) try {
            loadIndex(indexFile);
            setIndexCreated(true);
            return;
        } catch (Exception x) {
            logger.warn(x.getMessage());
        }
        indexCreated = false;
        long now = System.currentTimeMillis();
        int recordLength = 1000;
        int maxRecords = 1;
        int maxRecordLength = 0;
        maxRecords = (int) raFile.length() / recordLength;
        if (maxRecords == 0) maxRecords = 1;
        index = new long[maxRecords][3];

        String s = null;
        long start = 0;
        long end = 0;
        raFile.seek(0);
        records = 0;
        recordLength = 0;
        while ((s = raFile.readLine()) != null) {
            if (start == -1) start = raFile.getFilePointer();
            if (isRecordEnd(s)) {
                //fireFrameRead();
                if (records >= maxRecords) {
                    index = resize(index,
                            records
                                    + (int) (records + (raFile.length() - records * raFile.getFilePointer())
                                            / recordLength));
                }
                end += 4;
                index[records][0] = start;
                index[records][1] = end - start;
                index[records][2] = -1;
                if (maxRecordLength < index[records][1]) maxRecordLength = (int) index[records][1];
                records++;
                recordLength += end - start;

                start = raFile.getFilePointer();
            } else {
                end = raFile.getFilePointer();
            }

        }
        b = new byte[maxRecordLength];
        //fireFrameRead();
        logger.info("Index created in " + (System.currentTimeMillis() - now) + " ms.");
        try {
            saveIndex(indexFile);
        } catch (Exception x) {
            logger.error(x);
        }
    }