当前位置: 首页>>代码示例>>Java>>正文


Java Pair类代码示例

本文整理汇总了Java中org.apache.accumulo.core.util.Pair的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Pair类属于org.apache.accumulo.core.util包,在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTopKeyValue

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
private void setTopKeyValue() {
    while (!seriesIterator.hasNext() && super.hasTop()) {
        try {
            refillBuffer();
            seriesIterator = series.iterator();
        } catch (IOException e) {
            throw new RuntimeException("Error filling buffer", e);
        }
    }

    if (seriesIterator.hasNext()) {
        Pair<Key, Double> p = seriesIterator.next();
        topKey = p.getFirst();
        topValue = new Value(MetricAdapter.encodeValue(p.getSecond()));
    } else {
        topKey = null;
        topValue = null;
    }
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:20,代码来源:TimeSeriesGroupingIterator.java

示例2: putArray

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
private int putArray(Mutation m, int count, Object o, Pair<Text, Text> col, String fieldName) {

    // First of all we delete array field on accumulo store
    Text rowKey = new Text(m.getRow());
    Query<K, T> query = newQuery();
    query.setFields(fieldName);
    query.setStartKey((K)rowKey.toString());
    query.setEndKey((K)rowKey.toString());
    deleteByQuery(query);
    flush();
    if (o == null){
      return 0;
    }

    List<?> array = (List<?>) o;  // both GenericArray and DirtyListWrapper
    int j = 0;
    for (Object item : array) {
      m.put(col.getFirst(), new Text(toBytes(j++)), new Value(toBytes(item)));
      count++;
    }
    return count;
  }
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:23,代码来源:AccumuloStore.java

示例3: test

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Scanner scanner = conn.createScanner(tableName, new Authorizations());
  scanner.fetchColumn(new Text("dir"), new Text("counts"));
  assertFalse(scanner.iterator().hasNext());

  ScannerOpts scanOpts = new ScannerOpts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  FileCount fc = new FileCount(conn, tableName, Authorizations.EMPTY, new ColumnVisibility(), scanOpts, bwOpts);
  fc.run();

  ArrayList<Pair<String,String>> expected = new ArrayList<>();
  expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
  expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
  expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
  expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));

  int i = 0;
  for (Entry<Key,Value> e : scanner) {
    assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
    assertEquals(e.getValue().toString(), expected.get(i).getSecond());
    i++;
  }
  assertEquals(i, expected.size());
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:26,代码来源:CountIT.java

示例4: getExpectedLoadJob

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
public Job getExpectedLoadJob(String inst, String zookeepers, String user,
        String password, String table, String start, String end,
        Authorizations authorizations,
        List<Pair<Text, Text>> columnFamilyColumnQualifierPairs)
        throws IOException {
    Collection<Range> ranges = new LinkedList<Range>();
    ranges.add(new Range(start, end));

    Job expected = new Job(new Configuration());

    try {
        AccumuloInputFormat.setConnectorInfo(expected, user,
                new PasswordToken(password));
    } catch (AccumuloSecurityException e) {
        Assert.fail(e.getMessage());
    }
    AccumuloInputFormat.setInputTableName(expected, table);
    AccumuloInputFormat.setScanAuthorizations(expected, authorizations);
    AccumuloInputFormat.setZooKeeperInstance(expected, inst, zookeepers);
    AccumuloInputFormat.fetchColumns(expected,
            columnFamilyColumnQualifierPairs);
    AccumuloInputFormat.setRanges(expected, ranges);

    return expected;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:26,代码来源:TestAbstractAccumuloStorage.java

示例5: getDefaultExpectedLoadJob

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
public Job getDefaultExpectedLoadJob() throws IOException {
    String inst = "myinstance";
    String zookeepers = "127.0.0.1:2181";
    String user = "root";
    String password = "secret";
    String table = "table1";
    String start = "abc";
    String end = "z";
    Authorizations authorizations = new Authorizations(
            "PRIVATE,PUBLIC".split(","));

    List<Pair<Text, Text>> columnFamilyColumnQualifierPairs = new LinkedList<Pair<Text, Text>>();
    columnFamilyColumnQualifierPairs.add(new Pair<Text, Text>(new Text(
            "col1"), new Text("cq1")));
    columnFamilyColumnQualifierPairs.add(new Pair<Text, Text>(new Text(
            "col2"), new Text("cq2")));
    columnFamilyColumnQualifierPairs.add(new Pair<Text, Text>(new Text(
            "col3"), null));

    Job expected = getExpectedLoadJob(inst, zookeepers, user, password,
            table, start, end, authorizations,
            columnFamilyColumnQualifierPairs);
    return expected;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:25,代码来源:TestAbstractAccumuloStorage.java

示例6: expandTagValues

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
private Set<Tag> expandTagValues(Entry<String, String> firstTag, Iterator<Pair<String, String>> knownKeyValues) {
    Set<Tag> result = new HashSet<>();
    Matcher matcher = null;
    if (null != firstTag && isTagValueRegex(firstTag.getValue())) {
        matcher = Pattern.compile(firstTag.getValue()).matcher("");
    }
    while (knownKeyValues.hasNext()) {
        Pair<String, String> knownKeyValue = knownKeyValues.next();
        if (firstTag == null) {
            LOG.trace("Adding tag {}={}", knownKeyValue.getFirst(), knownKeyValue.getSecond());
            result.add(new Tag(knownKeyValue.getFirst(), knownKeyValue.getSecond()));
        } else {
            LOG.trace("Testing requested tag {}={}", firstTag.getKey(), firstTag.getValue());
            if (firstTag.getKey().equals(knownKeyValue.getFirst())) {
                if (null != matcher) {
                    matcher.reset(knownKeyValue.getSecond());
                    if (matcher.matches()) {
                        LOG.trace("Adding tag {}={}", knownKeyValue.getFirst(), knownKeyValue.getSecond());
                        result.add(new Tag(knownKeyValue.getFirst(), knownKeyValue.getSecond()));
                    }
                } else {
                    LOG.trace("Adding tag {}={}", knownKeyValue.getFirst(), knownKeyValue.getSecond());
                    result.add(new Tag(knownKeyValue.getFirst(), knownKeyValue.getSecond()));
                }
            }
        }
    }
    return result;
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:30,代码来源:DataStoreImpl.java

示例7: compute

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
@Override
protected Double compute(List<Pair<Key, Double>> values) {

    Iterator<Pair<Key, Double>> iter = values.iterator();
    Pair<Key, Double> first = iter.next();
    Long firstTs = first.getFirst().getTimestamp();
    Double firstVal = first.getSecond();
    LOG.trace("first ts:{}, value:{}", firstTs, firstVal);

    Pair<Key, Double> second = iter.next();
    Long secondTs = second.getFirst().getTimestamp();
    Double secondVal = second.getSecond();
    LOG.trace("second ts:{}, value:{}", secondTs, secondVal);

    if (isCounter && (secondVal < firstVal)) {
        if (maxCounter > 0) {
            secondVal += maxCounter;
            LOG.trace("second counter reset based on max:{} to ts:{}, value:{}", maxCounter, secondTs, secondVal);
        } else {
            secondVal += firstVal;
            LOG.trace("second counter reset based on first:{} to ts:{}, value:{}", firstVal, secondTs, secondVal);
        }
    }

    long timeDiff = secondTs - firstTs;
    if (timeDiff == 0) {
        return 0.0D;
    }
    Double result = ((secondVal - firstVal) / timeDiff);
    LOG.trace("compute - result: {}", result);

    if (isCounter && resetValue > 0 && result > resetValue) {
        result = 0.0D;
        LOG.trace("compute - reset result base on {} to {}", resetValue, result);
    }

    return result;
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:39,代码来源:RateIterator.java

示例8: add

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
public void add(Key key, Double value) {
    super.add(new Pair<>(key, value));
    if (super.size() == this.targetSize) {
        recompute();
        // remove first key as it is no longer needed for any
        // computations
        Pair<Key, Double> e = this.pollFirst();
        LOG.trace("Removing first entry {}", e.getFirst());
    }
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:11,代码来源:TimeSeriesGroupingIterator.java

示例9: put

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
@Override
public TimeSeries put(Metric key, TimeSeries value) {
    TimeSeries old = super.put(key, value);
    Double answer = value.getAndRemoveAnswer();
    if (answer != null) {
        answers.add(new Pair<>(value.getLast().getFirst(), answer));
    }
    return old;
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:10,代码来源:TimeSeriesGroupingIterator.java

示例10: iterator

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
/**
 * Iterates over the time series group and returns for each time series
 * the last key and the filtered value.
 */
@Override
public Iterator<Pair<Key, Double>> iterator() {
    try {
        return answers.iterator();
    } finally {
        answers = new ArrayList<>();
    }
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:13,代码来源:TimeSeriesGroupingIterator.java

示例11: compute

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
protected Double compute(List<Pair<Key, Double>> values) {
    double result = 0D;
    int i = 0;
    for (Pair<Key, Double> e : values) {
        LOG.trace("compute - key:{}, value: {}", e.getFirst(), e.getSecond());
        result += (filters[i] * e.getSecond());
        i++;
    }
    LOG.trace("compute - result: {}", result);
    return result;
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:12,代码来源:TimeSeriesGroupingIterator.java

示例12: getFieldName

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
/**
 * Retrieve field name from entry.
 * @param entry The Key-Value entry
 * @return String The field name
 */
private String getFieldName(Entry<Key, Value> entry) {
  String fieldName = mapping.columnMap.get(new Pair<>(entry.getKey().getColumnFamily(),
      entry.getKey().getColumnQualifier()));
  if (fieldName == null) {
    fieldName = mapping.columnMap.get(new Pair<Text,Text>(entry.getKey().getColumnFamily(), null));
  }
  return fieldName;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:14,代码来源:AccumuloStore.java

示例13: setFetchColumns

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
private void setFetchColumns(Scanner scanner, String fields[]) {
  fields = getFieldsToQuery(fields);
  for (String field : fields) {
    Pair<Text,Text> col = mapping.fieldMap.get(field);
    if (col != null) {
      if (col.getSecond() == null) {
        scanner.fetchColumnFamily(col.getFirst());
      } else {
        scanner.fetchColumn(col.getFirst(), col.getSecond());
      }
    } else {
      LOG.error("Mapping not found for field: " + field);
    }
  }
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:16,代码来源:AccumuloStore.java

示例14: putMap

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
private int putMap(Mutation m, int count, Schema valueType, Object o, Pair<Text, Text> col, String fieldName) throws GoraException {

    // First of all we delete map field on accumulo store
    Text rowKey = new Text(m.getRow());
    Query<K, T> query = newQuery();
    query.setFields(fieldName);
    query.setStartKey((K)rowKey.toString());
    query.setEndKey((K)rowKey.toString());
    deleteByQuery(query);
    flush();
    if (o == null){
      return 0;
    }

    Set<?> es = ((Map<?, ?>)o).entrySet();
    for (Object entry : es) {
      Object mapKey = ((Entry<?, ?>) entry).getKey();
      Object mapVal = ((Entry<?, ?>) entry).getValue();
      if ((o instanceof DirtyMapWrapper && ((DirtyMapWrapper<?, ?>)o).isDirty())
          || !(o instanceof DirtyMapWrapper)) { //mapVal instanceof Dirtyable && ((Dirtyable)mapVal).isDirty()) {
        m.put(col.getFirst(), new Text(toBytes(mapKey)), new Value(toBytes(valueType, mapVal)));
        count++;
      }
      // TODO map value deletion
    }
    return count;
  }
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:28,代码来源:AccumuloStore.java

示例15: run

import org.apache.accumulo.core.util.Pair; //导入依赖的package包/类
@Override
public int run(String[] args) throws Exception {
  Job job = Job.getInstance(getConf());
  job.setJobName(this.getClass().getName());
  job.setJarByClass(this.getClass());
  Opts opts = new Opts();
  opts.parseArgs(RowHash.class.getName(), args);
  job.setInputFormatClass(AccumuloInputFormat.class);
  opts.setAccumuloConfigs(job);

  String col = opts.column;
  int idx = col.indexOf(":");
  Text cf = new Text(idx < 0 ? col : col.substring(0, idx));
  Text cq = idx < 0 ? null : new Text(col.substring(idx + 1));
  if (cf.getLength() > 0)
    AccumuloInputFormat.fetchColumns(job, Collections.singleton(new Pair<>(cf, cq)));

  job.setMapperClass(HashDataMapper.class);
  job.setMapOutputKeyClass(Text.class);
  job.setMapOutputValueClass(Mutation.class);

  job.setNumReduceTasks(0);

  job.setOutputFormatClass(AccumuloOutputFormat.class);

  job.waitForCompletion(true);
  return job.isSuccessful() ? 0 : 1;
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:29,代码来源:RowHash.java


注:本文中的org.apache.accumulo.core.util.Pair类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。