本文整理汇总了Java中gnu.trove.map.hash.TObjectIntHashMap.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java TObjectIntHashMap.containsKey方法的具体用法?Java TObjectIntHashMap.containsKey怎么用?Java TObjectIntHashMap.containsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.hash.TObjectIntHashMap
的用法示例。
在下文中一共展示了TObjectIntHashMap.containsKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findDepVarsOf
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
private void findDepVarsOf(TreePatternNode node, TObjectIntHashMap<String> depMap)
{
if (node.isLeaf())
{
if (node.getLeafValue() instanceof DefInit)
{
if (depMap.containsKey(node.getName()))
depMap.put(node.getName(), depMap.get(node.getName()) + 1);
else
depMap.put(node.getName(), 1);
}
}
else
{
for (int i = 0, e = node.getNumChildren(); i != e; i++)
findDepVarsOf(node.getChild(i), depMap);
}
}
示例2: loadInputMetadataID
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public static void loadInputMetadataID(String metadata_file_index, String input_uri,
TIntIntHashMap input_metadata_id){
TObjectIntHashMap<String> metadata_index = new TObjectIntHashMap<String>();
loadIndex(metadata_file_index, metadata_index);
try{
BufferedReader br = new BufferedReader(new FileReader(input_uri));
String line = null;
while((line=br.readLine()) != null){
String[] vals = line.split("\t");
if(metadata_index.containsKey(vals[1]));
input_metadata_id.put(Integer.parseInt(vals[0]), metadata_index.get(vals[1]));
}
br.close();
}
catch(Exception e){
e.printStackTrace();
}
}
示例3: StrippedPartition
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public StrippedPartition(String[] columnContent) {
TObjectIntHashMap<String> valueToIndex = new TObjectIntHashMap<>();
LinkedHashMap<Integer, TEquivalence> helpMap = new LinkedHashMap<>();
for (int rowIndex = 0; rowIndex < columnContent.length; rowIndex++) {
String value = columnContent[rowIndex];
// if the value wasn't there yet, the row index becomes the representative
// for that equivalence class
if (!valueToIndex.containsKey(value)) {
valueToIndex.put(value, rowIndex);
TEquivalence equivalenceGroup = new EquivalenceGroupTIntHashSet();
equivalenceGroup.add(rowIndex);
helpMap.put(rowIndex, equivalenceGroup);
}
// otherwise find the right equivalence class and add the current element index
else {
int equivalenceGroupIndex = valueToIndex.get(value);
TEquivalence equivalenceClass = helpMap.get(equivalenceGroupIndex);
equivalenceClass.add(rowIndex);
}
}
// remove equivalence classes with only one element
for(Iterator<Map.Entry<Integer, TEquivalence>> it=helpMap.entrySet().iterator(); it.hasNext();) {
Map.Entry<Integer, TEquivalence> entry = it.next();
if (entry.getValue().size() <= 1) {
it.remove();
}
}
// sort the stripped partition by equivalence group sizes
this.addAll(helpMap.values());
}
示例4: getTermProbGivenField
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public double getTermProbGivenField(String t, String f) {
TObjectIntHashMap<String> fieldMap = termInFieldFrequencies.get(f);
if (fieldMap == null) {
return smoothing;
//throw new IllegalArgumentException(String.format("Field %s not found.", f));
} else {
if (!fieldMap.containsKey(t)) {
return smoothing;
} else {
double num = fieldMap.get(t) + 0.0;
return num / fieldLengths.get(f);
}
}
}
示例5: collectPubDates
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public static List<ScoredDocument> collectPubDates(List<ScoredDocument> docs, TObjectIntHashMap<String> pubDates) {
ArrayList<ScoredDocument> yearScores = new ArrayList<ScoredDocument>();
for (ScoredDocument doc : docs) {
if (pubDates.containsKey(doc.documentName)) {
ScoredDocument faked = new ScoredDocument();
faked.documentName = DateUtil.YearToString(pubDates.get(doc.documentName));
faked.score = doc.score;
faked.rank = doc.rank;
yearScores.add(faked);
}
}
return yearScores;
}
示例6: loadRelatedURIs
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public static void loadRelatedURIs(String file, TIntObjectHashMap<TIntArrayList> related_uri,
TObjectIntHashMap<String> uri_id){
try{
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
TIntArrayList tmp = null;
while((line=br.readLine()) != null){
tmp = new TIntArrayList();
String[] vals = line.split(",");
for(int i = 1; i < vals.length; i++){
if(!vals[i].contentEquals("null") && uri_id.containsKey(vals[i]))
tmp.add(uri_id.get(vals[i]));
}
if(uri_id.containsKey(vals[0]))
related_uri.put(uri_id.get(vals[0]), tmp);
}
br.close();
}
catch(Exception e){
e.printStackTrace();
}
}
示例7: readAscii
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
/**
* Reads an ASCII STL file.
*
* @param is InputStream to read from.
* @return Mesh
* @throws IOException If an error occurs during reading.
*/
private Mesh readAscii(InputStream is) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
/* Prepare empty mesh. */
Mesh mesh = new Mesh(100,100);
/* Prepare helper structures. */
TObjectIntHashMap<Vector3f> vertexBuffer = new TObjectIntHashMap<>();
int index = 0;
int[] vertexindices = new int[3];
while ((line = br.readLine()) != null && !line.startsWith("endsolid")) {
line = line.trim();
/* Detect end of STL file. */
if (line.startsWith("endsolid")) {
break;
}
/* Detect begin of facet. */
if (line.startsWith("facet normal ")) {
int vidx = 0;
while ((line = br.readLine()) != null) {
line = line.trim(); /* Trim line. */
/* Detect end of facet. */
if (line.equals("endfacet")) {
break;
}
/* Detect vertex. */
if (line.startsWith("vertex")) {
String[] splitVertex = line.split("\\s+");
Vector3f vertex = new Vector3f(Float.parseFloat(splitVertex[1]),Float.parseFloat(splitVertex[2]), Float.parseFloat(splitVertex[3]));
if (!vertexBuffer.containsKey(vertex)) {
mesh.addVertex(vertex);
vertexBuffer.put(vertex, index);
index++;
}
vertexindices[vidx] = vertexBuffer.get(vertex);
vidx++;
}
}
/* Add a new face to the Mesh. */
mesh.addFace(new Vector3i(vertexindices[0], vertexindices[1], vertexindices[2]));
}
}
/* Close the buffered reader. */
br.close();
/* This covers the case, where the file starts with 'solid ' but is not an ASCII file. Unfortunately, such files do exist. */
if (mesh.numberOfVertices() == 0) {
LOGGER.warn("The provided ASCII STL file does not seem to contain any normals or vertices. Trying to decode it as binary STL even though it was marked as being ASCII.");
InputStream newIs = Files.newInputStream(this.inputFile);
return this.readBinary(newIs, 80);
} else {
return mesh;
}
}
示例8: readBinary
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
/**
* Reads a binary STL file.
*
* @param is InputStream to read from.
* @param skip Number of bytes to skip before reading the STL file.
* @return Mesh
* @throws IOException If an error occurs during reading.
*/
private Mesh readBinary(InputStream is, int skip) throws IOException {
/* Prepare a ByteBuffer to read the rest of the STL file. */
byte[] bytes = new byte[50];
ByteBuffer buffer = ByteBuffer.wrap(bytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
/* Skip the STL header! */
is.skip(skip);
/* Read the bytes for the size (unsigned 32 bit int, little-endian). */
byte[] sizeBytes = new byte[4];
is.read(sizeBytes, 0, 4);
long triangles = ((sizeBytes[0] & 0xFF)) | ((sizeBytes[1] & 0xFF) << 8) | ((sizeBytes[2] & 0xFF) << 16) | ((sizeBytes[3] & 0xFF) << 24);
/* TODO: Properly handle models whose triangles > MAX_TRIANGLES. */
if (triangles <= 0) {
LOGGER.error("The number of triangles in the Mesh seems to be smaller than zero. This STL file is probably corrupt!");
return null;
} else if (triangles > MAX_TRIANGLES) {
LOGGER.error("The number of triangles in the Mesh exceeds the limit that can currently be processed by STLMeshDecoder. The Mesh will be downsampled!");
return null;
}
/* Prepare Mesh. */
Mesh mesh = new Mesh((int)triangles, (int)triangles);
/* Prepare helper structures. */
TObjectIntHashMap<Vector3f> vertexBuffer = new TObjectIntHashMap<>();
int index = 0;
int[] vertexindices = new int[3];
/* Now add all triangles. */
for (int i=0; i<triangles; i++) {
/* Ready 48 bytes from the stream. */
buffer.rewind();
is.read(bytes);
/* Read and ignore three floats. */
buffer.getFloat();
buffer.getFloat();
buffer.getFloat();
/* Add the vertices and the vertex-normal to the mesh. */
for (int vidx = 0; vidx < 3; vidx++) {
Vector3f vertex = new Vector3f(buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
if (!vertexBuffer.containsKey(vertex)) {
mesh.addVertex(vertex);
vertexBuffer.put(vertex, index);
index++;
}
vertexindices[vidx] = vertexBuffer.get(vertex);
}
/* Add a new face to the Mesh. */
if (!mesh.addFace(new Vector3i(vertexindices[0], vertexindices[1], vertexindices[2]))) {
LOGGER.warn("Could not add face {}/{}/{} because index points to non-existing vertex.", vertexindices[0], vertexindices[1], vertexindices[2]);
}
}
/* Closes the InputStream. */
is.close();
return mesh;
}
示例9: parseThreeJSV4Geometry
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
/**
* Parses a Base64 encoded data url and treats it as Geometry JSON used by the Three.js JavaScript library.
* Tries to parse the structure into a 3D mesh.
*
* @param dataUrl Data URL that should be parsed.
* @return Mesh, if parsing fails that Mesh will be empty!
*/
public static Mesh parseThreeJSV4Geometry(String dataUrl) {
/* Convert Base64 string into byte array. */
byte[] bytes = dataURLtoByteArray(dataUrl, MIME_TYPE);
ObjectMapper mapper = new ObjectMapper();
try {
/* Read the JSON structure of the transmitted mesh data. */
JsonNode node = mapper.readTree(bytes);
JsonNode vertices = node.get(VERTICES_PROPERTY_NAME_THREEV4);
if (vertices == null || !vertices.isArray() || vertices.size() == 0) {
LOGGER.error("Submitted mesh does not contain any vertices. Aborting...");
return Mesh.EMPTY;
}
/* Create new Mesh. */
Mesh mesh = new Mesh(vertices.size()/9, vertices.size()/3);
/* Prepare helper structures. */
TObjectIntHashMap<Vector3f> vertexBuffer = new TObjectIntHashMap<>();
int index = 0;
int[] vertexindices = new int[3];
/* Add all the vertices and normals in the structure. */
for (int i=0; i<=vertices.size()-9; i+=9) {
for (int j=0; j<3; j++) {
int idx = i + 3*j;
Vector3f vertex = new Vector3f((float)vertices.get(idx).asDouble(), (float)vertices.get(idx+1).asDouble(),(float)vertices.get(idx+2).asDouble());
if (!vertexBuffer.containsKey(vertex)) {
vertexBuffer.put(vertex, index++);
mesh.addVertex(vertex);
}
vertexindices[j] = vertexBuffer.get(vertex);
}
mesh.addFace(new Vector3i(vertexindices[0], vertexindices[1], vertexindices[2]));
}
return mesh;
} catch (IOException e) {
LOGGER.error("Could not create 3d mesh from Base64 input because the file-format is not supported. {}", LogHelper.getStackTrace(e));
return Mesh.EMPTY;
}
}