@Override public void flatMap(String line, Collector<Properties> out) { // Check if the line is an empty line if (line.isEmpty()) { return; } String[] propertyValues = line.split(tokenSeparator); // If the line to read is equals to the header and the checkReoccurringHeader flag is set to // TRUE, we do not import this line. if (checkReoccurringHeader && propertyNames.containsAll(Arrays.asList(propertyValues))) { return; } // clear the properties reuseProperties.clear(); for (int i = 0; i < propertyValues.length; i++) { // if a value is empty, do not add a property if (!propertyValues[i].isEmpty()) { reuseProperties.set(propertyNames.get(i), PropertyValue.create(propertyValues[i])); } } out.collect(reuseProperties); } }
/** * Parses the given property values according to the meta data associated with the specified * label. * * @param type element type * @param label element label * @param propertyValueString string representation of elements' property values * @return parsed properties */ Properties parseProperties(String type, String label, String propertyValueString) { String[] propertyValues = propertyValueString.split(valueDelimiter); List<PropertyMetaData> metaDataList = metaData.getPropertyMetaData(type, label); properties.clear(); for (int i = 0; i < propertyValues.length; i++) { if (propertyValues[i].length() > 0) { properties.set(metaDataList.get(i).getKey(), metaDataList.get(i).getValueParser().apply(propertyValues[i])); } } return properties; }
/** * Parses the given property values according to the meta data associated with the specified * label. * * @param type element type * @param label element label * @param propertyValueString string representation of elements' property values * @return parsed properties */ Properties parseProperties(String type, String label, String propertyValueString) { String[] propertyValues = propertyValueString.split(valueDelimiter); List<PropertyMetaData> metaDataList = metaData.getPropertyMetaData(type, label); properties.clear(); for (int i = 0; i < propertyValues.length; i++) { if (propertyValues[i].length() > 0) { properties.set(metaDataList.get(i).getKey(), metaDataList.get(i).getValueParser().apply(propertyValues[i])); } } return properties; }
/** * Parses the given property values according to the meta data associated with the specified * label. * * @param type element type * @param label element label * @param propertyValueString string representation of elements' property values * @return parsed properties */ Properties parseProperties(String type, String label, String propertyValueString) { String[] propertyValues = StringEscaper .split(propertyValueString, CSVConstants.VALUE_DELIMITER); List<PropertyMetaData> metaDataList = metaData.getPropertyMetaData(type, label); properties.clear(); for (int i = 0; i < propertyValues.length; i++) { if (propertyValues[i].length() > 0) { properties.set(metaDataList.get(i).getKey(), metaDataList.get(i).getValueParser().apply(propertyValues[i])); } } return properties; }
/** * Parses the given property values according to the meta data associated with the specified * label. * * @param type element type * @param label element label * @param propertyValueString string representation of elements' property values * @return parsed properties */ Properties parseProperties(String type, String label, String propertyValueString) { String[] propertyValues = StringEscaper .split(propertyValueString, CSVConstants.VALUE_DELIMITER); List<PropertyMetaData> metaDataList = metaData.getPropertyMetaData(type, label); properties.clear(); for (int i = 0; i < propertyValues.length; i++) { if (propertyValues[i].length() > 0) { properties.set(metaDataList.get(i).getKey(), metaDataList.get(i).getValueParser().apply(propertyValues[i])); } } return properties; }
/** * Constructs a vertex from a given JSON string representation. * * @param jsonString The String representation of a JSON object. * @return A new vertex from the JSON object. */ @Override public Vertex map(String jsonString) throws Exception { JSONObject jsonVertex = new JSONObject(jsonString); Properties properties = reuse.getProperties(); if (properties == null) { properties = Properties.create(); reuse.setProperties(properties); } properties.clear(); for (Iterator it = jsonVertex.keys(); it.hasNext();) { String key = (String) it.next(); PropertyValue propertyValue = getPropertyValue(jsonVertex, key); properties.set(key, propertyValue); } return reuse; }
@Test public void testClear() throws Exception { Properties properties = Properties.create(); properties.set(KEY_1, BOOL_VAL_1); properties.clear(); assertEquals("wrong size", 0, properties.size()); }