List of usage examples for org.apache.commons.lang3.tuple Pair getRight
public abstract R getRight();
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
From source file:com.quancheng.plugin.common.PrintMessageFile.java
private String getMessageJavaType(String packageName, DescriptorProto sourceMessageDesc, FieldDescriptorProto field) {/* w ww . j a v a 2s .co m*/ String fieldType = CommonUtils.findNotIncludePackageType(field.getTypeName()); Map<String, Pair<DescriptorProto, List<FieldDescriptorProto>>> nestedFieldType = transform( sourceMessageDesc); // isMap if (nestedFieldType.containsKey(fieldType)) { Pair<DescriptorProto, List<FieldDescriptorProto>> nestedFieldPair = nestedFieldType.get(fieldType); if (nestedFieldPair.getRight().size() == 2) { DescriptorProto mapSourceMessageDesc = nestedFieldPair.getLeft(); List<FieldDescriptorProto> mapFieldList = nestedFieldPair.getRight(); String nestedJavaType = "java.util.Map<" + findJavaType(packageName, mapSourceMessageDesc, mapFieldList.get(0)) + "," + findJavaType(packageName, mapSourceMessageDesc, mapFieldList.get(1)) + ">"; return nestedJavaType; } else { return null; } } else { return CommonUtils.findPojoTypeFromCache(field.getTypeName(), pojoTypeCache); } }
From source file:alfio.controller.api.admin.EmailMessageApiController.java
@RequestMapping("/") public PageAndContent<List<LightweightEmailMessage>> loadEmailMessages( @PathVariable("eventName") String eventName, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "search", required = false) String search, Principal principal) { Event event = eventManager.getSingleEvent(eventName, principal.getName()); ZoneId zoneId = event.getZoneId(); Pair<Integer, List<LightweightMailMessage>> found = notificationManager .loadAllMessagesForEvent(event.getId(), page, search); return new PageAndContent<>(found.getRight().stream().map(m -> new LightweightEmailMessage(m, zoneId, true)) .collect(Collectors.toList()), found.getLeft()); }
From source file:com.quartercode.jtimber.rh.agent.asm.InsertChildAccessorsClassAdapter.java
private void generateGetChildrenMethod() { GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, GET_CHILDREN_METHOD, null, null, cv); // Create the list; if the superclass is a node, call the getChildren() method on the superclass and use the result as the list // The leave the list at the bottom of the stack if (hasNodeAsSuperclass) { mg.loadThis();//from w w w . ja va2 s . com mg.invokeConstructor(superclassType, GET_CHILDREN_METHOD); } else { mg.newInstance(ARRAY_LIST_CLASS); mg.dup(); mg.invokeConstructor(ARRAY_LIST_CLASS, DEFAULT_CONSTRUCTOR); } // ----- Stack: [list] // Add all field values to the list for (Pair<String, Type> field : fields) { Type fieldType = field.getRight(); // Duplicate the list; the duplication is necessary because the following invocation of the add() method on the list // will "consume" this reference mg.dup(); // ----- Stack: [list, list] // Push the current field value ASMUtils.generateGetField(mg, classType, field.getLeft(), fieldType); // ----- Stack: [list, list, fieldValue] // Add the field object to the list; the called static method executes some checks and handles wrappers mg.invokeStatic(FUNCS_CLASS, FUNC_ADD_ACTUAL_CHILDREN_TO_LIST); // ----- Stack: [list] } // Return the list (which is at the bottom of the stack) mg.returnValue(); mg.endMethod(); }
From source file:com.baifendian.swordfish.common.hadoop.YarnRestClient.java
/** * ??//from www . j a v a2s. co m * * @param appId * @return ? null, ?? * @throws JSONException * @throws IOException */ public FlowStatus getApplicationStatus(String appId) throws JSONException, IOException { if (StringUtils.isEmpty(appId)) { return null; } String url = ConfigurationUtil.getApplicationStatusAddress(appId); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpget = new HttpGet(url); ResponseHandler<Pair<Integer, String>> rh = response -> { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { if (statusLine.getStatusCode() == 404 || statusLine.getStatusCode() == 330) { return null; } throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } if (entity == null) { throw new ClientProtocolException("Response contains no content"); } String content = EntityUtils.toString(entity); JSONObject o = null; try { o = new JSONObject(content); } catch (JSONException e) { throw new HttpResponseException(statusLine.getStatusCode(), content); } if (!o.has("app") || o.isNull("app")) { throw new RuntimeException("Response content not valid " + content); } try { return Pair.of(statusLine.getStatusCode(), o.getJSONObject("app").getString("finalStatus")); } catch (JSONException e) { throw new HttpResponseException(statusLine.getStatusCode(), content); } }; Pair<Integer, String> pair = httpclient.execute(httpget, rh); if (pair == null) { return null; } switch (pair.getRight()) { case "FAILED": return FlowStatus.FAILED; case "KILLED": return FlowStatus.KILL; case "SUCCEEDED": return FlowStatus.SUCCESS; case "NEW": case "NEW_SAVING": case "SUBMITTED": case "ACCEPTED": return FlowStatus.INIT; case "RUNNING": default: return FlowStatus.RUNNING; } }
From source file:net.malisis.blocks.tileentity.SwapperTileEntity.java
private void storeState(int x, int y, int z, Pair<IBlockState, NBTTagCompound> state) { states[x][y][z] = state.getLeft();/* ww w . j ava 2 s .co m*/ tileEntities[x][y][z] = state.getRight(); }
From source file:com.spotify.heroic.metric.datastax.schema.legacy.MapSerializer.java
@Override public ByteBuffer serialize(final Map<A, B> value) throws IOException { final List<Pair<ByteBuffer, ByteBuffer>> buffers = new ArrayList<>(); short size = 0; for (final Map.Entry<A, B> e : value.entrySet()) { final ByteBuffer key = a.serialize(e.getKey()); final ByteBuffer val = b.serialize(e.getValue()); size += key.limit() + val.limit(); buffers.add(Pair.of(key, val)); }/* w w w . jav a2 s. c o m*/ final ByteBuffer buffer = ByteBuffer.allocate(4 + 8 * value.size() + size); buffer.putShort((short) buffers.size()); for (final Pair<ByteBuffer, ByteBuffer> p : buffers) { buffer.putShort((short) p.getLeft().remaining()); buffer.put(p.getLeft()); buffer.putShort((short) p.getRight().remaining()); buffer.put(p.getRight()); } buffer.flip(); return buffer; }
From source file:com.github.tddts.jet.config.spring.postprocessor.MessageAnnotationBeanPostProcessor.java
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Pair<Class<?>, Object> typeObjectPair = SpringUtil.checkForDinamicProxy(bean); Class<?> type = typeObjectPair.getLeft(); Object target = typeObjectPair.getRight(); Method[] methods = type.getDeclaredMethods(); Field[] fields = type.getDeclaredFields(); for (Method method : methods) { if (checkMethod(method, type)) processMethod(target, method); }//from ww w . j a v a 2 s . c o m for (Field field : fields) { if (checkField(field, type)) processField(target, field); } return bean; }
From source file:de.johni0702.minecraft.gui.layout.CustomLayout.java
@Override @SuppressWarnings("unchecked") public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {// w ww.j a v a2s .c o m result.clear(); if (parent == null) { Collection<GuiElement> elements = container.getChildren(); for (GuiElement element : elements) { result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize()))); } } else { Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> elements = parent.layOut(container, size); for (Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> entry : elements.entrySet()) { Pair<ReadablePoint, ReadableDimension> pair = entry.getValue(); result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight()))); } } layout((T) container, size.getWidth(), size.getHeight()); return (Map) result; }
From source file:additionalpipes.pipes.PipeTransportPowerTeleport.java
@Override protected void sendInternalPower() { PipeLogicTeleport logic = ((PipePowerTeleport) container.pipe).getLogic(); List<Pair<PipeTransportPowerTeleport, Float>> powerQueryList = Lists.newLinkedList(); float totalPowerQuery = 0; for (PipePowerTeleport pipe : logic.<PipePowerTeleport>getConnectedPipes(true)) { PipeTransportPowerTeleport target = (PipeTransportPowerTeleport) pipe.transport; float totalQuery = APUtils.sum(target.powerQuery); if (totalQuery > 0) { powerQueryList.add(Pair.of(target, totalQuery)); totalPowerQuery += totalQuery; }//w w w.j ava2 s . c o m } for (int i = 0; i < 6; i++) { displayPower[i] += displayPower2[i]; displayPower2[i] = 0; float totalWatt = internalPower[i]; if (totalWatt > 0) { for (Pair<PipeTransportPowerTeleport, Float> query : powerQueryList) { float watts = totalWatt / totalPowerQuery * query.getRight(); int energy = MathHelper.ceiling_double_int(watts / AdditionalPipes.unitPower); if (logic.useEnergy(energy)) { PipeTransportPowerTeleport target = query.getLeft(); watts -= target.receiveTeleportedEnergy(watts); displayPower[i] += watts; internalPower[i] -= watts; } } } } super.sendInternalPower(); }
From source file:cn.liutils.vis.animation.CubicSplineCurve.java
@Override public double valueAt(double x) { // Find last point whose value <= x int index = 0; for (; index < pts.size() && pts.get(index).getLeft() < x; ++index) ;//from ww w . ja va2s .c o m if (index > 0) --index; if (index >= pts.size() - 1) index = pts.size() - 2; // Generate 4 refpoints' vals Pair<Double, Double> pt1 = pts.get(index), pt2 = pts.get(index + 1), pt0 = index == 0 ? pt1 : pts.get(index - 1); double dist = pt2.getLeft() - pt1.getLeft(), ldist = pt0 == pt1 ? dist : pt1.getRight() - pt0.getLeft(); double p0 = pt1.getRight(), p1 = pt2.getRight(), m0 = kval(index) * ldist, m1 = kval(index + 1) * dist; double u = (x - pt1.getLeft()) / dist, u2 = u * u, u3 = u2 * u; // Apply calculation return (2 * u3 - 3 * u2 + 1) * p0 + (u3 - 2 * u2 + u) * m0 + (-2 * u3 + 3 * u2) * p1 + (u3 - u2) * m1; }