當前位置: 首頁>>代碼示例>>Java>>正文


Java Pair類代碼示例

本文整理匯總了Java中org.apache.commons.math3.util.Pair的典型用法代碼示例。如果您正苦於以下問題:Java Pair類的具體用法?Java Pair怎麽用?Java Pair使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Pair類屬於org.apache.commons.math3.util包,在下文中一共展示了Pair類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wrap

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
/**
     * Create a JsonObject wrapping a raw {@code Pair<Long msec,T reading>>} sample.
     * @param <T> Tuple type
     * @param sample the raw sample
     * @param id the sensor's Id
     * @return the wrapped sample
     */
    public static <T> JsonObject wrap(Pair<Long,T> sample, String id) {
        JsonObject jo = new JsonObject();
        jo.addProperty(KEY_ID, id);
        jo.addProperty(KEY_TS, sample.getFirst());
        T value = sample.getSecond();
        if (value instanceof Number)
            jo.addProperty(KEY_READING, (Number)sample.getSecond());
        else if (value instanceof String)
            jo.addProperty(KEY_READING, (String)sample.getSecond());
        else if (value instanceof Boolean)
            jo.addProperty(KEY_READING, (Boolean)sample.getSecond());
//        else if (value instanceof array) {
//            // TODO cvt to JsonArray
//        }
//        else if (value instanceof Object) {
//            // TODO cvt to JsonObject
//        }
        else {
            Class<?> clazz = value != null ? value.getClass() : Object.class;
            throw new IllegalArgumentException("Unhandled value type: "+ clazz);
        }
        return jo;
    }
 
開發者ID:osswangxining,項目名稱:iot-edge-greengrass,代碼行數:31,代碼來源:JsonTuples.java

示例2: getSlugPostfixPair

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
private Pair<String, Long> getSlugPostfixPair(String slug) {

        if (!slug.contains(SLUG_POSTFIX_DELIMITER)) {
            return new Pair<>(slug, null);
        }

        int indexOfPossiblePostfix = slug.lastIndexOf(SLUG_POSTFIX_DELIMITER);
        String possiblePostfixAsString = slug.substring(indexOfPossiblePostfix + 1, slug.length());

        if (!StringUtils.isNumeric(possiblePostfixAsString)) {
            return new Pair<>(slug, null);
        }

        // slug name has numeric postfix
        String slugNameWithoutNumericPostfix = slug.substring(0, indexOfPossiblePostfix);
        Long postfix = Long.parseLong(possiblePostfixAsString);

        return new Pair<>(slugNameWithoutNumericPostfix, postfix);
    }
 
開發者ID:mapr-demos,項目名稱:mapr-music,代碼行數:20,代碼來源:SlugService.java

示例3: getGreedyRegressors

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
public static Pair<List<AnnotationRegressor>, List<FeatureNormalizer>> getGreedyRegressors(Websearch ws,
        boolean includeS1, boolean includeS2, boolean includeS3) {
	List<AnnotationRegressor> regressors = new Vector<>();
	List<FeatureNormalizer> fns = new Vector<>();
	int i = 0;
	while (true) {
		URL modelI = getDefaultModel(SmaphVersion.GREEDY, ws, includeS1, includeS2, includeS3, i);
		if (modelI == null)
			break;
		URL zscoreI = getDefaultZscoreNormalizer(SmaphVersion.GREEDY, ws, includeS1, includeS2, includeS3, i);
		AnnotationRegressor arI = getCachedAnnotationRegressor(modelI);
		FeatureNormalizer fnI = getCachedFeatureNormalizer(zscoreI, new GreedyFeaturePack());
		regressors.add(arI);
		fns.add(fnI);
		i++;
	}
	return new Pair<>(regressors, fns);
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:19,代碼來源:SmaphBuilder.java

示例4: settingNoOpInjectionsAndQuery

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
@Test
public void settingNoOpInjectionsAndQuery() {
  final long before = countAllocatedMemory();

  final String controls = Controls.newBuilder()
    .addExceptionOnBit(getClass(), "noop", RuntimeException.class, getEndpoint(DRILLBIT_BETA))
    .build();
  setControls(controls);
  final WaitUntilCompleteListener listener = new WaitUntilCompleteListener();
  QueryTestUtil.testWithListener(drillClient, QueryType.SQL, TEST_QUERY, listener);
  final Pair<QueryState, Exception> pair = listener.waitForCompletion();
  assertStateCompleted(pair, QueryState.COMPLETED);

  final long after = countAllocatedMemory();
  assertEquals(String.format("We are leaking %d bytes", after - before), before, after);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:17,代碼來源:TestDrillbitResilience.java

示例5: passThrough

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
@Test // To test pause and resume. Test hangs and times out if resume did not happen.
public void passThrough() {
  final long before = countAllocatedMemory();

  final WaitUntilCompleteListener listener = new WaitUntilCompleteListener() {
    @Override
    public void queryIdArrived(final QueryId queryId) {
      super.queryIdArrived(queryId);
      final ExtendedLatch trigger = new ExtendedLatch(1);
      (new ResumingThread(queryId, ex, trigger)).start();
      trigger.countDown();
    }
  };

  final String controls = Controls.newBuilder()
    .addPause(PojoRecordReader.class, "read-next")
    .build();
  setControls(controls);

  QueryTestUtil.testWithListener(drillClient, QueryType.SQL, TEST_QUERY, listener);
  final Pair<QueryState, Exception> result = listener.waitForCompletion();
  assertStateCompleted(result, QueryState.COMPLETED);

  final long after = countAllocatedMemory();
  assertEquals(String.format("We are leaking %d bytes", after - before), before, after);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:27,代碼來源:TestDrillbitResilience.java

示例6: splitTagAndBasename

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
public Pair<String,Path> splitTagAndBasename(Path path){

    String name = path.getName();
    Path parent = path.getParent();

    if(name.startsWith(LR_PREFIX) == false){
      return null;
    }

    name = name.substring(LR_PREFIX.length());
    int underscore = name.indexOf(LR_TAG_DELIM);

    if(underscore == -1){
      return null;
    }

    String tag = name.substring(0, underscore);
    String basename = name.substring(underscore + 1);

    if(LR_ALL_TAGS.contains(tag) == false){
      return null;
    }


    return new Pair<>(tag, new Path(parent, basename));
  }
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:OwnLocalResources.java

示例7: convertToDouble

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
/**
 * Converts the from the actual {@code Number} type to {@code double}
 *
 * @param <T> Type of the number used to represent the points and
 * weights of the quadrature rules.
 * @param rule Points and weights.
 * @return points and weights as {@code double}s.
 */
private static <T extends Number> Pair<double[], double[]> convertToDouble(Pair<T[], T[]> rule) {
    final T[] pT = rule.getFirst();
    final T[] wT = rule.getSecond();

    final int len = pT.length;
    final double[] pD = new double[len];
    final double[] wD = new double[len];

    for (int i = 0; i < len; i++) {
        pD[i] = pT[i].doubleValue();
        wD[i] = wT[i].doubleValue();
    }

    return new Pair<double[], double[]>(pD, wD);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:24,代碼來源:BaseRuleFactory.java

示例8: run

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
@Override
public Predictions<E, P>[] run() {
	final Pair<List<I>, List<I>> sets = partition();
	final Predictions<E, P>[] preds = new Predictions[learner.length];
	for (int i = 0; i < preds.length; ++i) {
		final long start = System.currentTimeMillis();
		final ModelPipeline<I, P> model = learner[i].run(sets.getFirst(), sets.getSecond(), config, label);
		preds[i] = Predictions
				.create(actualFold, model, sets.getSecond(), (int) (System.currentTimeMillis() - start));
		logger.info("Completed {} on {} train and {} test samples",
				getTitle(),
				sets.getFirst().size(),
				sets.getSecond().size());
	}
	return preds;
}
 
開發者ID:ProfilingIO,項目名稱:insight-ml,代碼行數:17,代碼來源:CrossValidation.java

示例9: sortDescending2

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
public static <T, N extends Number> LinkedList<Pair<T, N>> sortDescending2(final List<Pair<T, N>> list) {
	final LinkedList<Pair<T, N>> newList = new LinkedList<>(list);
	java.util.Collections.sort(newList, (o1, o2) -> {
		int comp = Double.valueOf(o1.getSecond().doubleValue()).compareTo(o2.getSecond().doubleValue());
		if (comp == 0) {
			if (o1.getFirst() instanceof Comparable) {
				comp = ((Comparable<T>) o1.getFirst()).compareTo(o2.getFirst());
				Check.state(comp != 0);
			} else {
				return 0;
			}
		}
		return comp > 0 ? -1 : 1;
	});
	return newList;
}
 
開發者ID:ProfilingIO,項目名稱:insight-ml,代碼行數:17,代碼來源:Collections.java

示例10: transform

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
/**
 * Performs a change of variable so that the integration can be performed
 * on an arbitrary interval {@code [a, b]}.
 * It is assumed that the natural interval is {@code [-1, 1]}.
 *
 * @param rule Original points and weights.
 * @param a Lower bound of the integration interval.
 * @param b Lower bound of the integration interval.
 * @return the points and weights adapted to the new interval.
 */
private static Pair<double[], double[]> transform(Pair<double[], double[]> rule,
                                                  double a,
                                                  double b) {
    final double[] points = rule.getFirst();
    final double[] weights = rule.getSecond();

    // Scaling
    final double scale = (b - a) / 2;
    final double shift = a + scale;

    for (int i = 0; i < points.length; i++) {
        points[i] = points[i] * scale + shift;
        weights[i] *= scale;
    }

    return new Pair<double[], double[]>(points, weights);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:28,代碼來源:GaussIntegratorFactory.java

示例11: run

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
@SuppressWarnings("null")
public final List<Pair<I, O>> run(final Iterable<? extends I> queue, final int directThreshold, final int limit) {
	final List<Callable<Pair<I, O>>> tasks = new LinkedList<>();
	int i = -1;
	for (final I it : queue) {
		final int j = ++i;
		tasks.add(() -> {
			try {
				return new Pair<>(it, exec(j, it));
			} catch (final Exception e) {
				e.printStackTrace();
				throw new IllegalStateException(e);
			}
		});
		if (i + 1 >= limit) {
			break;
		}
	}
	return new LinkedList<>(JobPool.invokeAll(tasks, directThreshold));
}
 
開發者ID:ProfilingIO,項目名稱:insight-ml,代碼行數:21,代碼來源:Threaded.java

示例12: addFile

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
@SuppressWarnings("resource")
private static void addFile(final File file, final String dirBase, final List<Pair<InputStream, String>> streams,
		final File target) {
	if (file.isDirectory()) {
		for (final File fil : file.listFiles()) {
			addFile(fil, dirBase + file.getName() + "/", streams, target);
		}
	} else {
		try {
			if (!file.getName().equals(target.getName())) {
				streams.add(new Pair<InputStream, String>(new FileInputStream(file), dirBase + file.getName()));
			}
		} catch (final FileNotFoundException e) {
			throw new IllegalArgumentException(e);
		}
	}
}
 
開發者ID:ProfilingIO,項目名稱:insight-ml,代碼行數:18,代碼來源:IoUtils.java

示例13: zip2

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
public static void zip2(final List<Pair<InputStream, String>> files, final File target) {
	final byte[] buffer = new byte[1024];
	try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target))) {
		for (final Pair<InputStream, String> file : files) {
			final ZipEntry ze = new ZipEntry(file.getSecond());
			zos.putNextEntry(ze);

			int len;
			while ((len = file.getFirst().read(buffer)) > 0) {
				zos.write(buffer, 0, len);
			}

			file.getFirst().close();
			zos.closeEntry();
		}
	} catch (final IOException e) {
		throw new IllegalStateException(e);
	}
}
 
開發者ID:ProfilingIO,項目名稱:insight-ml,代碼行數:20,代碼來源:IoUtils.java

示例14: updateWordObject

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
/** Updates the current word object from the current caret offset. */
@Override
protected void updateWordObject() {
	Pair<Integer, Integer> wi = getWordIndexAndRelativePosition(text.getCaretOffset());
	TrpWordType newWord = getWordObject(wi.getLeft());
	if (newWord==null)
		return;
	
	logger.debug("updating word object, caret offset: "+text.getCaretOffset()+", word index and relative positon: "+wi+" newWord="+newWord.getId()+" changed="+(newWord != currentWordObject));
	
	if (newWord != currentWordObject) {
		currentWordObject = newWord;
		if (getType() == TranscriptionLevel.WORD_BASED) { // only send signal if in in word based editor -> should be true here always
			sendSelectionChangedSignal();
			text.redraw();
		}
	}
}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:19,代碼來源:WordTranscriptionWidget.java

示例15: computeTopographicError

import org.apache.commons.math3.util.Pair; //導入依賴的package包/類
/**
 * Computes the topographic error.
 * The topographic error is the proportion of data for which first and
 * second best matching units are not adjacent in the map.
 *
 * @param data Feature vectors.
 * @param net Network.
 * @param distance Distance function.
 * @return the error.
 * @throws NoDataException if {@code data} is empty.
 */
public static double computeTopographicError(Iterable<double[]> data,
                                             Network net,
                                             DistanceMeasure distance) {
    int notAdjacentCount = 0;
    int count = 0;
    for (double[] f : data) {
        ++count;
        final Pair<Neuron, Neuron> p = findBestAndSecondBest(f, net, distance);
        if (!net.getNeighbours(p.getFirst()).contains(p.getSecond())) {
            // Increment count if first and second best matching units
            // are not neighbours.
            ++notAdjacentCount;
        }
    }

    if (count == 0) {
        throw new NoDataException();
    }

    return ((double) notAdjacentCount) / count;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:33,代碼來源:MapUtils.java


注:本文中的org.apache.commons.math3.util.Pair類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。