本文整理匯總了Java中org.javatuples.Pair.with方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.with方法的具體用法?Java Pair.with怎麽用?Java Pair.with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.javatuples.Pair
的用法示例。
在下文中一共展示了Pair.with方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: chooseSerializer
import org.javatuples.Pair; //導入方法依賴的package包/類
private Pair<String,MessageTextSerializer> chooseSerializer(final String acceptString) {
final List<Pair<String,Double>> ordered = Stream.of(acceptString.split(",")).map(mediaType -> {
// parse out each mediaType with its params - keeping it simple and just looking for "quality". if
// that value isn't there, default it to 1.0. not really validating here so users better get their
// accept headers straight
final Matcher matcher = pattern.matcher(mediaType);
return (matcher.matches()) ? Pair.with(matcher.group(1), Double.parseDouble(matcher.group(2))) : Pair.with(mediaType, 1.0);
}).sorted((o1, o2) -> o2.getValue0().compareTo(o1.getValue0())).collect(Collectors.toList());
for (Pair<String,Double> p : ordered) {
// this isn't perfect as it doesn't really account for wildcards. that level of complexity doesn't seem
// super useful for gremlin server really.
final String accept = p.getValue0().equals("*/*") ? "application/json" : p.getValue0();
if (serializers.containsKey(accept))
return Pair.with(accept, (MessageTextSerializer) serializers.get(accept));
}
return null;
}
示例2: shouldConstructDetachedEdgeFromParts
import org.javatuples.Pair; //導入方法依賴的package包/類
@Test
public void shouldConstructDetachedEdgeFromParts() {
final Map<String, Object> properties = new HashMap<>();
properties.put("x", "a");
properties.put("y", "b");
final DetachedEdge de = new DetachedEdge(10, "bought", properties, Pair.with(1, "person"), Pair.with(2, "product"));
assertEquals(10, de.id());
assertEquals("bought", de.label());
assertEquals("person", de.vertices(Direction.OUT).next().label());
assertEquals(1, de.vertices(Direction.OUT).next().id());
assertEquals("product", de.vertices(Direction.IN).next().label());
assertEquals(2, de.vertices(Direction.IN).next().id());
assertEquals("a", de.properties("x").next().value());
assertEquals(1, IteratorUtils.count(de.properties("x")));
assertEquals("a", de.property("x").value());
assertEquals("x", de.property("x").key());
assertEquals("b", de.property("y").value());
assertEquals("y", de.property("y").key());
}
示例3: doReleaseRole
import org.javatuples.Pair; //導入方法依賴的package包/類
@Override
public Pair<SwitchRoleResult, String> doReleaseRole(IRole role) {
if (!getRolesCache().getAdvancedCache().startBatch()) {
throw new IllegalStateException("Nested batch detected!");
}
boolean commit = true;
boolean releaseDone = false;
getRolesCache().getAdvancedCache().lock(role);
try {
IRoleAttribution attribution = getRolesCache().get(role);
if (attribution != null && attribution.match(getAddress())) {
getRolesCache().remove(role);
releaseDone = true;
}
} finally {
getRolesCache().getAdvancedCache().endBatch(commit);
}
if (getRolesCache().get(role) == null) {
return Pair.with(SwitchRoleResult.SWITCH_STEP_SUCCESS, "OK");
} else if (releaseDone) {
return Pair.with(SwitchRoleResult.SWITCH_STEP_INCONSISTENCY, "Map remove done, but role not released !");
} else {
return Pair.with(SwitchRoleResult.SWITCH_STEP_INCONSISTENCY, "Map remove cannot be done !");
}
}
示例4: doCaptureRole
import org.javatuples.Pair; //導入方法依賴的package包/類
@Override
public Pair<SwitchRoleResult, String> doCaptureRole(IRole role) {
// role request checked in a insecure way (but role capture is safe)
if (getRolesRequestsCache().get(role) != null && !getRolesRequestsCache().get(role).match(getAddress())) {
return Pair.with(SwitchRoleResult.SWITCH_STEP_INCONSISTENCY, "Role is already requested by another node");
}
getRolesCache().putIfAbsent(role, RoleAttribution.from(getAddress(), new Date()));
// request release not safe as it can conflict with another capture
getRolesRequestsCache().remove(role);
if (getRolesCache().get(role) == null) {
return Pair.with(SwitchRoleResult.SWITCH_STEP_INCONSISTENCY, "Role is available but was not captured");
} else if (!getRolesCache().get(role).match(getAddress())) {
return Pair.with(SwitchRoleResult.SWITCH_CAPTURE_NOT_AVAILABLE, "Role is not available at capture time");
} else {
return Pair.with(SwitchRoleResult.SWITCH_STEP_SUCCESS, "OK");
}
}
示例5: queryByField
import org.javatuples.Pair; //導入方法依賴的package包/類
/**
* @deprecated Utiliser QueryDSL
*/
@Deprecated
private <E extends GE, V extends Comparable<?>> Pair<EntityPath<E>, JPAQuery<E>> queryByField(Class<E> clazz, SingularAttribute<? super E, V> field, V fieldValue,
EnabledFilter enabledFilter) {
PathBuilder<E> pathBuilder = new PathBuilder<E>(clazz, "entityAlias");
QGenericLocalizedGenericListItem entityPath = new QGenericLocalizedGenericListItem(pathBuilder);
JPAQuery<E> query;
if (field != null) {
query = queryEntityByField(pathBuilder, field.getBindableJavaType(), field.getName(), fieldValue);
} else {
query = queryByPredicate(pathBuilder, null);
}
if (EnabledFilter.ENABLED_ONLY.equals(enabledFilter)) {
// l'appel au where ajoute la condition aux conditions précédentes
query = query.where(entityPath.enabled.isTrue());
}
return Pair.with((EntityPath<E>) pathBuilder, query);
}
示例6: queryByField
import org.javatuples.Pair; //導入方法依賴的package包/類
@Deprecated
private <E extends GenericListItem<?>, V extends Comparable<?>> Pair<EntityPath<E>, JPAQuery<E>> queryByField(Class<E> clazz, SingularAttribute<? super E, V> field, V fieldValue,
EnabledFilter enabledFilter) {
PathBuilder<E> pathBuilder = new PathBuilder<E>(clazz, "entityAlias");
QGenericListItem entityPath = new QGenericListItem(pathBuilder);
JPAQuery<E> query;
if (field != null) {
query = queryEntityByField(pathBuilder, field.getBindableJavaType(), field.getName(), fieldValue);
} else {
query = queryByPredicate(pathBuilder, null);
}
if (EnabledFilter.ENABLED_ONLY.equals(enabledFilter)) {
// l'appel au where ajoute la condition aux conditions précédentes
query = query.where(entityPath.enabled.isTrue());
}
return Pair.with((EntityPath<E>) pathBuilder, query);
}
示例7: getContents
import org.javatuples.Pair; //導入方法依賴的package包/類
/**
* @return <upldDS, dwnlDS>
*/
public Pair<List<String>, List<String>> getContents() throws ThirdPartyException {
if(!delaStateController.transferDelaAvailable()) {
throw new ThirdPartyException(Response.Status.BAD_REQUEST.getStatusCode(), "dela transfer not available",
ThirdPartyException.Source.LOCAL, "bad request");
}
HopsContentsSummaryJSON.Contents contents = TransferDelaController.this.getContents(new LinkedList<>());
List<String> upldDSIds = new LinkedList<>();
List<String> dwnlDSIds = new LinkedList<>();
for (ElementSummaryJSON[] ea : contents.getContents().values()) {
for (ElementSummaryJSON e : ea) {
if (e.getTorrentStatus().toLowerCase().equals("uploading")) {
upldDSIds.add(e.getTorrentId().getVal());
} else if (e.getTorrentStatus().toLowerCase().equals("downloading")) {
dwnlDSIds.add(e.getTorrentId().getVal());
}
}
}
return Pair.with(upldDSIds, dwnlDSIds);
}
示例8: fields
import org.javatuples.Pair; //導入方法依賴的package包/類
/**
* Find the fields of the given element type, and field predicate.
*/
public static <E extends Element> List<Field> fields(Class<E> elementType,
Predicate<Field> predicate) {
Pair<Class, Predicate<Field>> predicatedType = Pair.with(elementType, predicate);
Map<String, Field> cachedFields =
ELEMENT_CACHE.computeIfAbsent(
predicatedType, Fields::fieldsByName);
List<Field> matchingFields = cachedFields.values().stream()
.collect(Collectors.toList());
Collections.sort(matchingFields, BY_KEYS);
return matchingFields;
}
示例9: readEdge
import org.javatuples.Pair; //導入方法依賴的package包/類
/**
* Read an {@link Edge} from output generated by {@link GraphSONWriter#writeEdge(OutputStream, Edge)} or via
* an {@link Edge} passed to {@link GraphSONWriter#writeObject(OutputStream, Object)}.
*
* @param inputStream a stream containing at least one {@link Edge} as defined by the accompanying
* {@link GraphWriter#writeEdge(OutputStream, Edge)} method.
* @param edgeAttachMethod a function that creates re-attaches a {@link Edge} to a {@link Host} object.
*/
@Override
public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException {
final Map<String, Object> edgeData = mapper.readValue(inputStream, mapTypeReference);
final Map<String,Object> edgeProperties = edgeData.containsKey(GraphSONTokens.PROPERTIES) ?
(Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES) : Collections.EMPTY_MAP;
final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
edgeData.get(GraphSONTokens.LABEL).toString(),
edgeProperties,
Pair.with(edgeData.get(GraphSONTokens.OUT), edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
Pair.with(edgeData.get(GraphSONTokens.IN), edgeData.get(GraphSONTokens.IN_LABEL).toString()));
return edgeAttachMethod.apply(edge);
}
示例10: clockWithResult
import org.javatuples.Pair; //導入方法依賴的package包/類
public static <S> Pair<Double, S> clockWithResult(final int loops, final Supplier<S> supplier) {
final S result = supplier.get(); // warm up
return Pair.with(IntStream.range(0, loops).mapToDouble(i -> {
long t = System.nanoTime();
supplier.get();
return (System.nanoTime() - t) * 0.000001;
}).sum() / loops, result);
}
示例11: serializeDeserialize
import org.javatuples.Pair; //導入方法依賴的package包/類
private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph);
return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例12: createSearchBuilder
import org.javatuples.Pair; //導入方法依賴的package包/類
private <E extends Element, S extends DocumentSchema<E>> Pair<S, SearchSourceBuilder> createSearchBuilder(Map.Entry<S, QueryBuilder> kv, SearchQuery<E> query) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(kv.getValue())
.size(query.getLimit() == -1 ? 10000 : query.getLimit());
if (query.getPropertyKeys() == null) searchSourceBuilder.fetchSource(true);
else {
Set<String> fields = kv.getKey().toFields(query.getPropertyKeys());
if (fields.size() == 0) searchSourceBuilder.fetchSource(false);
else searchSourceBuilder.fetchSource(fields.toArray(new String[fields.size()]), null);
}
List<Pair<String, Order>> orders = query.getOrders();
if (orders != null) {
orders.forEach(order -> {
Order orderValue = order.getValue1();
switch (orderValue) {
case decr:
searchSourceBuilder.sort(kv.getKey()
.getFieldByPropertyKey(order.getValue0()), SortOrder.DESC);
break;
case incr:
searchSourceBuilder.sort(kv.getKey()
.getFieldByPropertyKey(order.getValue0()), SortOrder.ASC);
break;
case shuffle:
break;
}
});
}
return Pair.with(kv.getKey(), searchSourceBuilder);
}
示例13: create
import org.javatuples.Pair; //導入方法依賴的package包/類
@Override
public Pair<ILinkParameterMappingEntry, Collection<ILinkParameterValidator>> create(TTuple parameters) {
ILinkParameterMappingEntry entry = factory.create(parameters);
ImmutableList.Builder<ILinkParameterValidator> validatorsListBuilder = ImmutableList.<ILinkParameterValidator>builder();
if (mandatory) {
validatorsListBuilder.add(entry.mandatoryValidator());
}
validatorsListBuilder.addAll(parameterValidators);
Collection<ILinkParameterValidator> validators = validatorsListBuilder.build();
return Pair.with(entry, validators);
}
示例14: extractParameters
import org.javatuples.Pair; //導入方法依賴的package包/類
private static Tuple extractParameters(Tuple parameters, List<Integer> indices) {
int size = indices.size();
switch (size) {
case 0:
return null;
case 1:
return Unit.with(parameters.getValue(indices.get(0)));
case 2:
return Pair.with(
parameters.getValue(indices.get(0)),
parameters.getValue(indices.get(1))
);
case 3:
return Triplet.with(
parameters.getValue(indices.get(0)),
parameters.getValue(indices.get(1)),
parameters.getValue(indices.get(2))
);
case 4:
return Quartet.with(
parameters.getValue(indices.get(0)),
parameters.getValue(indices.get(1)),
parameters.getValue(indices.get(2)),
parameters.getValue(indices.get(3))
);
default:
throw new IllegalStateException("Only Unit, Pair, Triplet and Quartet parameters are supported for ILinkParameterMappingEntryFactory");
}
}
示例15: createObject
import org.javatuples.Pair; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Edge createObject(final Map<String, Object> edgeData) {
return new DetachedEdge(
newORecordId(edgeData.get(GraphSONTokens.ID)),
edgeData.get(GraphSONTokens.LABEL).toString(),
(Map) edgeData.get(GraphSONTokens.PROPERTIES),
Pair.with(newORecordId(edgeData.get(GraphSONTokens.OUT)), edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
Pair.with(newORecordId(edgeData.get(GraphSONTokens.IN)), edgeData.get(GraphSONTokens.IN_LABEL).toString()));
}