@Override public Properties readProperties(final Result res) { Properties properties = Properties.create(); // Get Map<Qualifier, Value> which is Map<PropertyKey, TypeByte> Map<byte[], byte[]> typeFamilyMap = res.getFamilyMap(CF_PROPERTY_TYPE_BYTES); // Get Map<Qualifier, Value> which is Map<PropertyKey, ValueBytesWithoutType> Map<byte[], byte[]> valueFamilyMap = res.getFamilyMap(CF_PROPERTY_VALUE_BYTES); for (Map.Entry<byte[], byte[]> propertyColumn : typeFamilyMap.entrySet()) { properties.set( Bytes.toString(propertyColumn.getKey()), PropertyValueUtils.Bytes.createFromTypeValueBytes( propertyColumn.getValue(), valueFamilyMap.get(propertyColumn.getKey()))); } return properties; }
@Test public void testEqualsAndHashCode() throws Exception { Properties properties1 = Properties.createFromMap(SUPPORTED_PROPERTIES); Properties properties2 = Properties.createFromMap(SUPPORTED_PROPERTIES); Properties properties3 = Properties.createFromMap(SUPPORTED_PROPERTIES); // override property properties3.set(KEY_1, INT_VAL_2); assertTrue("properties were not equal", properties1.equals(properties2)); assertFalse("properties were equal", properties1.equals(properties3)); assertTrue("different hash code", properties1.hashCode() == properties2.hashCode()); assertTrue("same hash code", properties1.hashCode() != properties3.hashCode()); properties1 = Properties.create(); properties1.set(KEY_1, BOOL_VAL_1); properties1.set(KEY_2, INT_VAL_2); properties2 = Properties.create(); properties2.set(KEY_1, BOOL_VAL_1); assertFalse("properties were equal", properties1.equals(properties2)); assertTrue("same hash code", properties1.hashCode() != properties2.hashCode()); }
/** * {@inheritDoc} */ @Override public GraphHead map(Tuple2<GradoopId, GradoopId> idTuple) { GraphHead head = graphHeadFactory.initGraphHead(idTuple.f0); Properties properties = Properties.createWithCapacity(1); properties.set("lineage", idTuple.f1); head.setProperties(properties); return head; }
protected Properties getProperties(List<String> propertyNames) { Properties properties = new Properties(); for (String propertyName : propertyNames) { properties.set(propertyName, propertyName); } return properties; }
@Test public void testRemove() throws Exception { Properties properties = Properties.create(); PropertyValue removed; properties.set(KEY_1, BOOL_VAL_1); removed = properties.remove(KEY_1); assertEquals(0, properties.size()); assertNotNull(removed); properties.set(KEY_1, BOOL_VAL_1); removed = properties.remove(KEY_2); assertEquals(1, properties.size()); assertNull(removed); }
@Test public void testSize() throws Exception { Properties properties = Properties.create(); assertEquals("wrong size", 0, properties.size()); properties.set(KEY_1, BOOL_VAL_1); assertEquals("wrong size", 1, properties.size()); properties.set(KEY_2, INT_VAL_2); assertEquals("wrong size", 2, properties.size()); // add existing properties.set(KEY_2, LONG_VAL_3); assertEquals("wrong size", 2, properties.size()); }
/** * 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 testContainsKey() throws Exception { Properties properties = Properties.create(); assertFalse("unexpected key found", properties.containsKey(KEY_1)); properties.set(KEY_1, BOOL_VAL_1); assertTrue("key not found", properties.containsKey(KEY_1)); assertFalse("unexpected key found", properties.containsKey("1234")); }
/** * Creates a new EPGMGraph from the GDL Loader. * * @param g graph from GDL Loader * @return EPGM graph head */ private G initGraphHead(Graph g) { G graphHead = (G) config.getGraphHeadFactory().createGraphHead( g.getLabel(), Properties.createFromMap(g.getProperties())); graphHeadIds.put(g.getId(), graphHead.getId()); graphHeads.put(graphHead.getId(), graphHead); return graphHead; }
@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); } }
/** * Constructor */ CSVLineToElement() { this.properties = Properties.create(); }
@Test public void testCreateFromMap() throws Exception { Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); assertEquals(SUPPORTED_PROPERTIES.size(), properties.size()); for (Map.Entry<String, Object> entry : SUPPORTED_PROPERTIES.entrySet()) { String k = entry.getKey(); assertTrue(properties.containsKey(k)); assertEquals(entry.getValue(), properties.get(k).getObject()); } }
@Override public void setProperty(Property property) { Preconditions.checkNotNull(property, "Property was null"); initProperties(); this.properties.set(property); }
final String label = "A"; Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); assert v != null; List<String> propertyKeys = Lists.newArrayList(v.getPropertyKeys()); assertEquals(properties.size(), propertyKeys.size());
@Test public void testGet() throws Exception { Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); assertNotNull("property was null", properties.get(KEY_1)); assertEquals("wrong property", BOOL_VAL_1, properties.get(KEY_1).getBoolean()); assertNull("unexpected property", properties.get("1234")); }
/** * Checks if a property with the given key is contained in the properties. * * @param key property key * @return true, if there is a property with the given key */ public boolean containsKey(String key) { return get(key) != null; }
/** * True, if the properties collection does not store any properties. * * @return true if collection is empty, false otherwise */ public boolean isEmpty() { return size() == 0; }