List of usage examples for org.apache.commons.lang StringUtils right
public static String right(String str, int len)
Gets the rightmost len
characters of a String.
From source file:org.openhab.binding.miele.internal.handler.MieleApplianceHandler.java
@Override public void onApplianceStateChanged(String UID, DeviceClassObject dco) { String myUID = "hdm:ZigBee:" + (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID); String modelID = StringUtils.right(dco.DeviceClass, dco.DeviceClass.length() - new String("com.miele.xgw3000.gateway.hdm.deviceclasses.Miele").length()); if (myUID.equals(UID)) { if (modelID.equals(this.modelID)) { for (JsonElement prop : dco.Properties.getAsJsonArray()) { try { DeviceProperty dp = gson.fromJson(prop, DeviceProperty.class); dp.Value = StringUtils.trim(dp.Value); dp.Value = StringUtils.strip(dp.Value); onAppliancePropertyChanged(UID, dp); } catch (Exception p) { // Ignore - this is due to an unrecognized and not yet reverse-engineered array property }//from www. j a v a2s . c om } for (JsonElement operation : dco.Operations.getAsJsonArray()) { try { DeviceOperation devop = gson.fromJson(operation, DeviceOperation.class); DeviceMetaData pmd = gson.fromJson(devop.Metadata, DeviceMetaData.class); } catch (Exception p) { // Ignore - this is due to an unrecognized and not yet reverse-engineered array property } } } } }
From source file:org.openhab.binding.plugwise.internal.Energy.java
public Energy(String logdate, long l, int interval) { if (logdate.length() == 8) { if (!logdate.equals("FFFFFFFF")) { int year = 0; int month = 0; long minutes = 0; year = Integer.parseInt(StringUtils.left(logdate, 2), 16) + 2000; month = Integer.parseInt(StringUtils.mid(logdate, 2, 2), 16); minutes = Long.parseLong(StringUtils.right(logdate, 4), 16); time = new DateTime(year, month, 1, 0, 0, DateTimeZone.UTC).plusMinutes((int) minutes) .toDateTime(DateTimeZone.getDefault()).minusHours(1); } else {/*ww w . j a v a 2s. co m*/ time = DateTime.now(); this.interval = interval; this.pulses = 0; } } else { time = DateTime.now(); } this.interval = interval; this.pulses = l; }
From source file:org.openhab.binding.plugwise.protocol.InformationResponseMessage.java
@Override protected void parsePayLoad() { Pattern RESPONSE_PATTERN = Pattern .compile("(\\w{16})(\\w{2})(\\w{2})(\\w{4})(\\w{8})(\\w{2})(\\w{2})(\\w{12})(\\w{8})(\\w{2})"); Matcher matcher = RESPONSE_PATTERN.matcher(payLoad); if (matcher.matches()) { MAC = matcher.group(1);/*from w w w . ja va2s .co m*/ year = Integer.parseInt(matcher.group(2), 16) + 2000; month = Integer.parseInt(matcher.group(3), 16); minutes = Integer.parseInt(matcher.group(4), 16); logAddress = (Integer.parseInt(matcher.group(5), 16) - 278528) / 8; powerState = (matcher.group(6).equals("01")); hertz = Integer.parseInt(matcher.group(7), 16); hardwareVersion = StringUtils.left(matcher.group(8), 4) + "-" + StringUtils.mid(matcher.group(8), 4, 4) + "-" + StringUtils.right(matcher.group(8), 4); firmwareVersion = Integer.parseInt(matcher.group(9), 16); unknown = Integer.parseInt(matcher.group(10), 16); } else { logger.debug("Plugwise protocol RoleCallResponseMessage error: {} does not match", payLoad); } }
From source file:org.openhab.binding.plugwise.protocol.InitialiseResponseMessage.java
@Override protected void parsePayLoad() { Pattern RESPONSE_PATTERN = Pattern.compile("(\\w{16})(\\w{2})(\\w{2})(\\w{16})(\\w{4})(\\w{2})"); Matcher matcher = RESPONSE_PATTERN.matcher(payLoad); if (matcher.matches()) { MAC = matcher.group(1);//w w w.j av a 2s .c o m unknown1 = matcher.group(2); online = (Integer.parseInt(matcher.group(3), 16) == 1); networkID = matcher.group(4); shortNetworkID = matcher.group(5); unknown2 = matcher.group(6); // now some serious protocol reverse-engineering assumption. Circle+ MAC = networkID with first two bytes replaced by 00 circlePlusMAC = "00" + StringUtils.right(networkID, StringUtils.length(networkID) - 2); } else { logger.debug("Plugwise protocol InitialiseResponse error: {} does not match", payLoad); } }
From source file:org.openmrs.module.referencedemodata.ReferenceDemoDataActivator.java
static String randomSuffix(int digits) { // Last n digits of the current time. return StringUtils.right(String.valueOf(System.currentTimeMillis()), digits); }
From source file:org.openremote.controller.protocol.domintell.DomintellAddress.java
public String toString() { return StringUtils.right(" " + Integer.toString(address, 16).toUpperCase(), 6); }
From source file:org.owasp.jbrofuzz.version.JBroFuzzFormat.java
/** * <p>/*from w w w. j a v a 2 s. c o m*/ * Method for abbreviating the given String to a particular length, by * removing characters from the middle of the String. * </p> * <p> * This method does not, yet guarantee a return String of length len. * </p> * * @param input * @param len * @return String */ public static final String centerAbbreviate(final String input, final int len) { if (input.length() <= len) { return input; } if (len < 5) { return input; } if (input.length() < len) { return input; } else { return StringUtils.abbreviate(input, len / 2) + StringUtils.right(input, len / 2); } }
From source file:org.xwiki.platform.patchservice.hook.PatchCreator.java
private void getContentChanges(XWikiDocument oldDoc, XWikiDocument newDoc, RWPatch patch, XWikiContext context) throws DifferentiationFailedException, XWikiException { List<Delta> contentChanges = newDoc.getContentDiff(oldDoc, newDoc, context); for (Delta change : contentChanges) { if (change instanceof ChangeDelta) { RWOperation delete = OperationFactoryImpl.getInstance().newOperation(Operation.TYPE_CONTENT_DELETE); String deletedText = StringUtils.join(change.getOriginal().chunk().iterator(), "\n"); Position p = new PositionImpl(change.getRevised().first(), 0); delete.delete(deletedText, p); patch.addOperation(delete);/*from w w w .j a v a 2 s.c om*/ RWOperation insert = OperationFactoryImpl.getInstance().newOperation(Operation.TYPE_CONTENT_INSERT); String insertedText = StringUtils.join(change.getRevised().chunk().iterator(), "\n"); p = new PositionImpl(change.getRevised().first(), 0); insert.insert(insertedText, p); patch.addOperation(insert); } else if (change instanceof AddDelta) { RWOperation insert = OperationFactoryImpl.getInstance().newOperation(Operation.TYPE_CONTENT_INSERT); String insertedText = StringUtils.join(change.getRevised().chunk().iterator(), "\n"); Position p = new PositionImpl(change.getRevised().first(), 0); insert.insert(insertedText, p); patch.addOperation(insert); } else if (change instanceof DeleteDelta) { RWOperation delete = OperationFactoryImpl.getInstance().newOperation(Operation.TYPE_CONTENT_DELETE); String deletedText = StringUtils.join(change.getOriginal().chunk().iterator(), "\n"); Position p = new PositionImpl(change.getRevised().first(), 0); delete.delete(deletedText, p); patch.addOperation(delete); } } // suigeneris-jrcs diff does not take into account a newline at the end of file, so it must be manually // removed or added. String oldContent = oldDoc.getContent(); String newContent = newDoc.getContent(); if ("\n".equals(StringUtils.right(oldContent, 1)) && !"\n".equals(StringUtils.right(newContent, 1))) { RWOperation delete = OperationFactoryImpl.getInstance().newOperation(Operation.TYPE_CONTENT_DELETE); String[] lines = newContent.split("\n"); Position p = new PositionImpl(lines.length - 1, lines[lines.length - 1].length()); delete.delete("\n", p); patch.addOperation(delete); } else if (!"\n".equals(StringUtils.right(oldContent, 1)) && "\n".equals(StringUtils.right(newContent, 1))) { RWOperation insert = OperationFactoryImpl.getInstance().newOperation(Operation.TYPE_CONTENT_INSERT); String[] lines = newContent.split("\n"); Position p; if (lines.length == 0) { p = new PositionImpl(0, 0); } else { p = new PositionImpl(lines.length - 1, lines[lines.length - 1].length()); } insert.insert("\n", p); patch.addOperation(insert); } }