/*
Gets the glyphs of the given set of PhysicalEntity objects. Does not create anything.

@param pes entities to get their glyphs
@return glyphs of entities
553894
private List<Glyph> getGlyphsOfPEs(Set<PhysicalEntity> pes, String context) {
		List<Glyph> gs = new ArrayList<Glyph>();

		for (PhysicalEntity pe : pes)
			if (glyphMap.containsKey(convertID(pe.getUri())))
				gs.add(getGlyphToLink(pe, context));

		return gs;
	}
571280
function getFlags(glyf, glyfSupport) {

            if (!glyf.contours || 0 === glyf.contours.length) {
                return glyfSupport;
            }

            var flags = [];
            var xCoord = [];
            var yCoord = [];

            var contours = glyf.contours;
            var contour;
            var prev;
            var first = true;

            for (var j = 0, cl = contours.length; j < cl; j++) {
                contour = contours[j];

                for (var i = 0, l = contour.length; i < l; i++) {

                    var point = contour[i];
                    if (first) {
                        xCoord.push(point.x);
                        yCoord.push(point.y);
                        first = false;
                    }
                    else {
                        xCoord.push(point.x - prev.x);
                        yCoord.push(point.y - prev.y);
                    }
                    flags.push(point.onCurve ? glyFlag.ONCURVE : 0);
                    prev = point;
                }
            }

            // compress
            var flagsC = [];
            var xCoordC = [];
            var yCoordC = [];
            var x;
            var y;
            var prevFlag;
            var repeatPoint = -1;

            flags.forEach(function (flag, index) {

                x = xCoord[index];
                y = yCoord[index];

                // 第一个
                if (index === 0) {

                    if (-0xFF <= x && x <= 0xFF) {
                        flag += glyFlag.XSHORT;
                        if (x >= 0) {
                            flag += glyFlag.XSAME;
                        }

                        x = Math.abs(x);
                    }

                    if (-0xFF <= y && y <= 0xFF) {
                        flag += glyFlag.YSHORT;
                        if (y >= 0) {
                            flag += glyFlag.YSAME;
                        }

                        y = Math.abs(y);
                    }

                    flagsC.push(prevFlag = flag);
                    xCoordC.push(x);
                    yCoordC.push(y);
                }
                // 后续
                else {

                    if (x === 0) {
                        flag += glyFlag.XSAME;
                    }
                    else {
                        if (-0xFF <= x && x <= 0xFF) {
                            flag += glyFlag.XSHORT;
                            if (x > 0) {
                                flag += glyFlag.XSAME;
                            }

                            x = Math.abs(x);
                        }

                        xCoordC.push(x);
                    }

                    if (y === 0) {
                        flag += glyFlag.YSAME;
                    }
                    else {
                        if (-0xFF <= y && y <= 0xFF) {
                            flag += glyFlag.YSHORT;
                            if (y > 0) {
                                flag += glyFlag.YSAME;
                            }
                            y = Math.abs(y);
                        }
                        yCoordC.push(y);
                    }

                    // repeat
                    if (flag === prevFlag) {
                        // 记录重复个数
                        if (-1 === repeatPoint) {
                            repeatPoint = flagsC.length - 1;
                            flagsC[repeatPoint] |= glyFlag.REPEAT;
                            flagsC.push(1);
                        }
                        else {
                            ++flagsC[repeatPoint + 1];
                        }
                    }
                    else {
                        repeatPoint = -1;
                        flagsC.push(prevFlag = flag);
                    }
                }

            });

            glyfSupport.flags = flagsC;
            glyfSupport.xCoord = xCoordC;
            glyfSupport.yCoord = yCoordC;

            return glyfSupport;
        }
253224
function getGlyphData($originalGlyphIdx, &$maxdepth, &$depth, &$points, &$contours)
	{
		$depth++;
		$maxdepth = max($maxdepth, $depth);
		if (count($this->glyphdata[$originalGlyphIdx]['compGlyphs'])) {
			foreach ($this->glyphdata[$originalGlyphIdx]['compGlyphs'] as $glyphIdx) {
				$this->getGlyphData($glyphIdx, $maxdepth, $depth, $points, $contours);
			}
		} else {
			if (($this->glyphdata[$originalGlyphIdx]['nContours'] > 0) && $depth > 0) { // simple
				$contours += $this->glyphdata[$originalGlyphIdx]['nContours'];
				$points += $this->glyphdata[$originalGlyphIdx]['nPoints'];
			}
		}
		$depth--;
	}
952222
public static void loadGlyphsFont(InputStream stream, String keyPrefix) throws IOException {
        try {
            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

            docBuilder.setEntityResolver((publicId, systemId) -> {
                // disable dtd entites at runtime
                return new InputSource(new StringReader(""));
            });

            Document doc = docBuilder.parse(stream);
            doc.getDocumentElement().normalize();

            NodeList glyphsList = doc.getElementsByTagName("glyph");
            for (int i = 0; i < glyphsList.getLength(); i++) {
                Node glyph = glyphsList.item(i);
                Node glyphName = glyph.getAttributes().getNamedItem("glyph-name");
                if (glyphName == null) {
                    continue;
                }

                String glyphId = glyphName.getNodeValue();
                SVGGlyphBuilder glyphPane = new SVGGlyphBuilder(i,
                    glyphId,
                    glyph.getAttributes()
                        .getNamedItem("d")
                        .getNodeValue());
                glyphsMap.put(keyPrefix + "." + glyphId, glyphPane);
            }
            stream.close();
        } catch (ParserConfigurationException | SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
552530
def __get_entities(self, etype):
        """"""
        r = fapi.get_entities(self.namespace, self.name,
                              etype, self.api_url)
        fapi._check_response_code(r, 200)
        return [Entity(e['entityType'], e['name'], e['attributes'])
                for e in r.json()]
1287445
public JSONObject physicalElementToJSON(PhysicalElement pe) {
        JSONObject o = new JSONObject();
        if (pe instanceof Node) {
            o.put("type", NODE_LABEL);
            o.put("id", ((Node) pe).id());
        } else if (pe instanceof Switch) {
            o.put("type", SWITCH_LABEL);
            o.put("id", ((Switch) pe).id());
        } else {
            throw new IllegalArgumentException("Unsupported physical element '" + pe.getClass().toString() + "'");
        }
        return o;
    }
766981
private String getPatternCode(final List<Token> tokens) {
        final StringBuilder sb = new StringBuilder();
        sb.append(tokens.size());
        for (final Token token : tokens) {
            sb.append(token.getType().ordinal());
        }
        return sb.toString();
    }
987763
private static void addEquivalentsComplexes(PhysicalEntity pe, Set<PhysicalEntity> pes)
	{
		addEquivalentsComplexes(pe, true, pes);

		// Do not traverse to more specific. This was causing a bug so I commented out. Did not delete it just in case
		// later we realize that this is needed for another use case.
//		addEquivalentsComplexes(pe, false, pes);
	}
628247
private Glyph getCompartment(PhysicalEntity pe) {
		CellularLocationVocabulary cl = pe.getCellularLocation();
		if (cl != null && !cl.getTerm().isEmpty()) {
			String name = null;
			// get a cv term,
			// ignoring IDs (should not be there but happens)
			for(String term : cl.getTerm()) {
				term = term.toLowerCase();
				if(!term.matches("(go|so|mi|bto|cl|pato|mod):")) {
				 name = term;
				 break;
				}
			}
			return getCompartment(name);
		} else
			return null;
	}
228828
def to_glyphs_blue_values(self, ufo, master):
    """"""

    zones = []
    blue_values = _pairs(ufo.info.postscriptBlueValues)
    other_blues = _pairs(ufo.info.postscriptOtherBlues)
    for y1, y2 in blue_values:
        size = y2 - y1
        if y2 == 0:
            pos = 0
            size = -size
        else:
            pos = y1
        zones.append(self.glyphs_module.GSAlignmentZone(pos, size))
    for y1, y2 in other_blues:
        size = y1 - y2
        pos = y2
        zones.append(self.glyphs_module.GSAlignmentZone(pos, size))

    master.alignmentZones = sorted(zones, key=lambda zone: -zone.position)
205197
private Set<PhysicalEntity> getFlattenedMembers(Complex cx) {
		Set<PhysicalEntity> set = new HashSet<PhysicalEntity>();
		for (PhysicalEntity mem : cx.getComponent()) {
			if (mem instanceof Complex) {
				if (!hasNonComplexMember((Complex) mem)) {
					set.add(mem);
				} else {
					set.addAll(getFlattenedMembers((Complex) mem));
				}
			} else set.add(mem);
		}

		return set;
	}
808101
public List<String> getAttributeIdentifiers(EntityType sourceEntityType) {
    Entity entityTypeEntity =
        dataService.findOne(
            ENTITY_TYPE_META_DATA,
            new QueryImpl<>().eq(EntityTypeMetadata.ID, sourceEntityType.getId()));

    if (entityTypeEntity == null)
      throw new MolgenisDataAccessException(
          "Could not find EntityTypeEntity by the name of " + sourceEntityType.getId());

    List<String> attributeIdentifiers = new ArrayList<>();

    recursivelyCollectAttributeIdentifiers(
        entityTypeEntity.getEntities(EntityTypeMetadata.ATTRIBUTES), attributeIdentifiers);

    return attributeIdentifiers;
  }
377317
public List<Object> getEntities() {
		List<Object> entitiesList = new LinkedList<Object>();

		for (Result result : results) {
			entitiesList.add(result.getObject());
		}

		return entitiesList;
	}
13131
protected function dataToGlyphSet($data)
    {
        $glyphs = array();
        foreach ($data->icons as $iconProperties) {
            $glyphs[] = $iconProperties->properties->name;
        }
        return $glyphs;
    }
872693
public List<Link> getConnectedLinks(PhysicalElement pe) {
        List<Link> myLinks = new ArrayList<>();
        for (Link l : this.links) {
            if (l.getElement().equals(pe)) {
                myLinks.add(l);
            } else if (l.getSwitch().equals(pe)) {
                myLinks.add(l);
            }
        }
        return myLinks;
    }
1333612
function getStringGlyfs(ttf, str) {
        let glyphs = [];
        let indexList = ttf.findGlyf({ unicode: str.split('').map(toCharCode) })
        if (indexList.length) glyphs = ttf.getGlyf(indexList);
        glyphs.unshift(ttf.get().glyf[0]);
        return glyphs;
    }
87411
private Glyph createGlyph(Entity e)
	{
		String id = convertID(e.getUri());
		if (glyphMap.containsKey(id))
			return glyphMap.get(id);

		// Create its glyph and register
		Glyph g = createGlyphBasics(e, true);
		glyphMap.put(g.getId(), g);

		//TODO: export metadata (e.g., from bpe.getAnnotations() map) using the SBGN Extension feature
//		SBGNBase.Extension ext = new SBGNBase.Extension();
//		g.setExtension(ext);
//		Element el = biopaxMetaDoc.createElement(e.getModelInterface().getSimpleName());
//		el.setAttribute("uri", e.getUri());
//		ext.getAny().add(el);

		if (g.getClone() != null)
			ubiqueSet.add(g);

		if(e instanceof PhysicalEntity) {
			PhysicalEntity pe = (PhysicalEntity) e;
			assignLocation(pe, g);
			if("or".equalsIgnoreCase(g.getClazz())) {
				buildGeneric(pe, g, null);
			} else if (pe instanceof Complex) {
				createComplexContent((Complex) pe, g);
			}
		}

		return g;
	}