@Override public CharSequence subSequence(int start, int end) { return new StringValue(this, start, end - start); }
@Override public StringValue copy(StringValue from, StringValue reuse) { reuse.setValue(from); return reuse; }
/** * Gets this StringValue as a String. * * @return A String resembling the contents of this StringValue. */ public String getValue() { return toString(); }
/** * Converts the given <code>StringValue</code> into a lower case variant. * * @param string The string to convert to lower case. */ public static void toLowerCase(StringValue string) { final char[] chars = string.getCharArray(); final int len = string.length(); for (int i = 0; i < len; i++) { chars[i] = Character.toLowerCase(chars[i]); } }
@Test public void testStringValue() { StringValue string0 = new StringValue("This is a test"); StringValue stringThis = new StringValue("This"); StringValue stringIsA = new StringValue("is a"); Assert.assertEquals("This is a test", string0.toString()); StringValue string1 = new StringValue("This is a test"); StringValue string2 = new StringValue("This is a tesa"); StringValue string3 = new StringValue("This is a tesz"); StringValue string4 = new StringValue("Ünlaut ßtring µ avec é y ¢"); CharSequence chars5 = string1.subSequence(0, 4); StringValue string5 = (StringValue) chars5; StringValue string6 = (StringValue) string0.subSequence(0, string0.length()); StringValue string7 = (StringValue) string0.subSequence(5, 9); StringValue string8 = (StringValue) string0.subSequence(0, 0); Assert.assertTrue(string0.compareTo(string0) == 0); Assert.assertTrue(string0.compareTo(string1) == 0); Assert.assertTrue(string0.compareTo(string2) > 0); Assert.assertTrue(string0.compareTo(string3) < 0); Assert.assertTrue(stringThis.equals(chars5)); Assert.assertTrue(stringThis.compareTo(string5) == 0); Assert.assertTrue(string0.compareTo(string6) == 0); Assert.assertTrue(stringIsA.compareTo(string7) == 0); string7.setValue("This is a test"); Assert.assertTrue(stringIsA.compareTo(string7) > 0); Assert.assertTrue(string0.compareTo(string7) == 0); string7.setValue("is a"); Assert.assertTrue(stringIsA.compareTo(string7) == 0);
@Override public void map(Record record, Collector<Record> collector) { // get the first field (as type StringValue) from the record String line = record.getField(1, StringValue.class).getValue(); // normalize the line line = line.replaceAll("\\W+", " ").toLowerCase(); // tokenize the line StringTokenizer tokenizer = new StringTokenizer(line); while (tokenizer.hasMoreTokens()) { String word = tokenizer.nextToken(); // we emit a (word, 1) pair collector.collect(new Record(new StringValue(word), new IntValue(1))); } } }
@Override public void join(Record value1, Record value2, Collector<Record> out) throws Exception { keyString = value1.getField(0, keyString); keyString.setValue(""+ (Integer.parseInt(keyString.getValue())+1)); value1.setField(0, keyString); valueString = value1.getField(1, valueString); int val1 = Integer.parseInt(valueString.getValue())+2; valueString = value2.getField(1, valueString); int val2 = Integer.parseInt(valueString.getValue())+1; value1.setField(1, new IntValue(val1 - val2)); out.collect(value1); if (LOG.isDebugEnabled()) LOG.debug("Processed: [" + keyString.toString() + "," + val1 + "] + " + "[" + keyString.toString() + "," + val2 + "]"); }
if (fromNode.equals(toNode)) { return; sb.append(rec2.getField(4, StringValue.class).getValue()); sb.append(" "); sb.append(rec1.getField(0, StringValue.class).getValue()); sb.append(rec1.getField(4, StringValue.class).getValue()); hopList.setValue(sb.toString().trim()); outputRecord.setField(4, hopList);
@Override public void combine(Iterator<Record> records, Collector<Record> out) throws Exception { int sum = 0; Record record = new Record(); while (records.hasNext()) { record = records.next(); combineValue = record.getField(1, combineValue); sum += Integer.parseInt(combineValue.toString()); LOG.debug("Processed: [" + record.getField(0, StringValue.class).toString() + "," + combineValue.toString() + "]"); } combineValue.setValue(sum + ""); record.setField(1, combineValue); out.collect(record); }
@Override public void writeRecord(Record record) throws IOException { int color = record.getField(0, IntValue.class).getValue(); String names = record.getField(1, StringValue.class).getValue(); System.out.println(color + ": " + names); }
@Test public void testPactMap() { NfIntStringMap map0 = new NfIntStringMap(); map0.put(new IntValue(10), new StringValue("20")); Assert.assertEquals(entry.getValue(), new StringValue("20")); Assert.assertEquals(entry.getKey(), new IntValue(10)); map0.put(new IntValue(10), new StringValue("10")); for (Entry<IntValue, StringValue> entry : map0.entrySet()) { Assert.assertEquals(entry.getValue(), new StringValue("10")); Assert.assertEquals(entry.getKey(), new IntValue(10)); map0.put(new IntValue(20), new StringValue("20")); map0.put(new IntValue(30), new StringValue("30")); map0.put(new IntValue(40), new StringValue("40")); Assert.assertEquals(entry.getKey().getValue(), Integer.parseInt(entry.getValue().toString())); mapinv.put(entry.getValue(), entry.getKey()); Assert.assertEquals(entry.getValue().getValue(), Integer.parseInt(entry.getKey().toString())); Assert.assertEquals(entry.getKey().getValue(), Integer.parseInt(entry.getValue().toString()));
@Override public Record readRecord(Record target, byte[] bytes, int offset, int numBytes) { this.keyString.setValueAscii(bytes, offset, 1); this.valueString.setValueAscii(bytes, offset + 2, 1); target.setField(0, keyString); target.setField(1, valueString); LOG.debug("Read in: [" + keyString.getValue() + "," + valueString.getValue() + "]"); return target; }
@Override public void map(Record record, Collector<Record> out) throws Exception { keyString = record.getField(0, keyString); valueString = record.getField(1, valueString); LOG.debug("Processed: [" + keyString.toString() + "," + valueString.getValue() + "]"); if (Integer.parseInt(keyString.toString()) + Integer.parseInt(valueString.toString()) < 10) { record.setField(0, valueString); record.setField(1, new IntValue(Integer.parseInt(keyString.toString()) + 10)); out.collect(record); } } }
@Override public StringValue readRecord(StringValue reuse, byte[] bytes, int offset, int numBytes) { if (this.ascii) { reuse.setValueAscii(bytes, offset, numBytes); return reuse; reuse.setValue(result); return reuse;
myVertex = new StringValue(); if (otherVertex.compareTo(myVertex) < 0) { this.result.setField(1, otherVertex); this.result.setField(2, myVertex);
StringValue origValue1 = new StringValue("Hello World!"); IntValue origValue2 = new IntValue(1337); Record record1 = new Record(origValue1, origValue2); IntValue rec2Val2 = record2.getField(1, IntValue.class); assertTrue(origValue1.equals(rec1Val1)); assertTrue(origValue2.equals(rec1Val2)); assertTrue(origValue1.equals(rec2Val1)); assertTrue(origValue2.equals(rec2Val2)); } catch (IOException e) {
StringValue.writeString(value, serializer); StringValue.copyString(source, target); String deser = StringValue.readString(validate);
record.addField(this.origVal1); assertTrue(record.getNumFields() == 1); assertTrue(origVal1.getValue().equals(record.getField(0, StringValue.class).getValue())); IntValue recVal3 = record.getField(2, IntValue.class); assertTrue("The value of the first field has changed", recVal1.equals(this.origVal1)); assertTrue("The value of the second field changed", recVal2.equals(this.origVal2)); assertTrue("The value of the third field has changed", recVal3.equals(this.origVal3));