List of usage examples for org.apache.commons.lang ArrayUtils isEmpty
public static boolean isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or null
.
From source file:org.apache.kylin.cube.cli.CubeSignatureRefresher.java
public void update() { logger.info("Reloading Cube Metadata from store: " + store.getReadableResourcePath(ResourceStore.CUBE_DESC_RESOURCE_ROOT)); CubeDescManager cubeDescManager = CubeDescManager.getInstance(config); List<CubeDesc> cubeDescs; if (ArrayUtils.isEmpty(cubeNames)) { cubeDescs = cubeDescManager.listAllDesc(); } else {/*from w ww . java2 s . c o m*/ String[] names = cubeNames[0].split(","); if (ArrayUtils.isEmpty(names)) return; cubeDescs = Lists.newArrayListWithCapacity(names.length); for (String name : names) { cubeDescs.add(cubeDescManager.getCubeDesc(name)); } } for (CubeDesc cubeDesc : cubeDescs) { updateCubeDesc(cubeDesc); } verify(); }
From source file:org.apache.kylin.cube.CubeDescUpgrader.java
private void updateDimensions(CubeDesc oldModel, org.apache.kylin.cube.model.CubeDesc newModel) { List<org.apache.kylin.cube.model.v1.DimensionDesc> oldDimensions = oldModel.getDimensions(); List<DimensionDesc> newDimensions = Lists.newArrayList(); newModel.setDimensions(newDimensions); int dimId = 0; for (org.apache.kylin.cube.model.v1.DimensionDesc dim : oldDimensions) { DimensionDesc newDim = null;/* www .j av a 2 s.c o m*/ // if a dimension defines "column", "derived" and "hierarchy" at the same time, separate it into three dimensions; boolean needNameSuffix = false; if (dim.getColumn() != null && !"{FK}".equals(dim.getColumn())) { //column on fact table newDim = newDimensionDesc(dim, dimId++, dim.getName()); newDimensions.add(newDim); newDim.setColumn(new String[] { dim.getColumn() }); needNameSuffix = true; } else if (ArrayUtils.isEmpty(dim.getDerived()) && ArrayUtils.isEmpty(dim.getHierarchy())) { // user defines a lookup table, but didn't use any column other than the pk, in this case, convert to use fact table's fk newDim = newDimensionDesc(dim, dimId++, dim.getName()); newDimensions.add(newDim); newDim.setTable(getMetadataManager().appendDBName(newModel.getFactTable())); newDim.setColumn(dim.getJoin().getForeignKey()); } if (!ArrayUtils.isEmpty(dim.getDerived())) { newDim = newDimensionDesc(dim, dimId++, dim.getName() + (needNameSuffix ? "_DERIVED" : "")); newDimensions.add(newDim); newDim.setDerived(dim.getDerived()); newDim.setColumn(null); // derived column must come from a lookup table; in this case the fk will be the dimension column, no need to explicitly declare it; needNameSuffix = true; } if (!ArrayUtils.isEmpty(dim.getHierarchy())) { newDim = newDimensionDesc(dim, dimId++, dim.getName() + (needNameSuffix ? "_HIERARCHY" : "")); newDimensions.add(newDim); newDim.setHierarchy(true); List<String> columns = Lists.newArrayList(); for (HierarchyDesc hierarch : dim.getHierarchy()) { String col = hierarch.getColumn(); columns.add(col); } newDim.setColumn(columns.toArray(new String[columns.size()])); } } }
From source file:org.apache.kylin.storage.hbase.cube.v2.coprocessor.endpoint.CubeVisitService.java
private void updateRawScanByCurrentRegion(RawScan rawScan, HRegion region, int shardLength) { if (shardLength == 0) { return;// ww w . j a v a2 s.c o m } byte[] regionStartKey = ArrayUtils.isEmpty(region.getRegionInfo().getStartKey()) ? new byte[shardLength] : region.getRegionInfo().getStartKey(); Bytes.putBytes(rawScan.startKey, 0, regionStartKey, 0, shardLength); Bytes.putBytes(rawScan.endKey, 0, regionStartKey, 0, shardLength); }
From source file:org.apache.kylin.storage.hbase.ii.coprocessor.endpoint.IIEndpoint.java
private Scan prepareScan(IIProtos.IIRequest request, HRegion region) throws IOException { Scan scan = new Scan(); scan.addColumn(IIDesc.HBASE_FAMILY_BYTES, IIDesc.HBASE_QUALIFIER_BYTES); scan.addColumn(IIDesc.HBASE_FAMILY_BYTES, IIDesc.HBASE_DICTIONARY_BYTES); if (request.hasTsRange()) { Range<Long> tsRange = (Range<Long>) SerializationUtils .deserialize(HBaseZeroCopyByteString.zeroCopyGetBytes(request.getTsRange())); byte[] regionStartKey = region.getStartKey(); if (!ArrayUtils.isEmpty(regionStartKey)) { shard = BytesUtil.readUnsigned(regionStartKey, 0, IIKeyValueCodec.SHARD_LEN); } else {/*from w w w. java 2 s. c o m*/ shard = 0; } logger.info("Start key of the region is: " + BytesUtil.toReadableText(regionStartKey) + ", making shard to be :" + shard); if (tsRange.hasLowerBound()) { //differentiate GT and GTE seems not very beneficial Preconditions.checkArgument(shard != -1, "Shard is -1!"); long tsStart = tsRange.lowerEndpoint(); logger.info("ts start is " + tsStart); byte[] idealStartKey = new byte[IIKeyValueCodec.SHARD_LEN + IIKeyValueCodec.TIMEPART_LEN]; BytesUtil.writeUnsigned(shard, idealStartKey, 0, IIKeyValueCodec.SHARD_LEN); BytesUtil.writeLong(tsStart, idealStartKey, IIKeyValueCodec.SHARD_LEN, IIKeyValueCodec.TIMEPART_LEN); logger.info("ideaStartKey is(readable) :" + BytesUtil.toReadableText(idealStartKey)); Result result = region.getClosestRowBefore(idealStartKey, IIDesc.HBASE_FAMILY_BYTES); if (result != null) { byte[] actualStartKey = Arrays.copyOf(result.getRow(), IIKeyValueCodec.SHARD_LEN + IIKeyValueCodec.TIMEPART_LEN); scan.setStartRow(actualStartKey); logger.info("The start key is set to " + BytesUtil.toReadableText(actualStartKey)); } else { logger.info("There is no key before ideaStartKey so ignore tsStart"); } } if (tsRange.hasUpperBound()) { //differentiate LT and LTE seems not very beneficial Preconditions.checkArgument(shard != -1, "Shard is -1"); long tsEnd = tsRange.upperEndpoint(); logger.info("ts end is " + tsEnd); byte[] actualEndKey = new byte[IIKeyValueCodec.SHARD_LEN + IIKeyValueCodec.TIMEPART_LEN]; BytesUtil.writeUnsigned(shard, actualEndKey, 0, IIKeyValueCodec.SHARD_LEN); BytesUtil.writeLong(tsEnd + 1, actualEndKey, IIKeyValueCodec.SHARD_LEN, IIKeyValueCodec.TIMEPART_LEN);//notice +1 here scan.setStopRow(actualEndKey); logger.info("The stop key is set to " + BytesUtil.toReadableText(actualEndKey)); } } return scan; }
From source file:org.apache.log.extractor.App.java
private App() throws IOException, ConfigurationException { logger.info("***Starting App***"); initConfiguration();//w w w. j av a2 s .c o m final String[] logLocations = config.getStringArray("log.oozie.location"); if (ArrayUtils.isEmpty(logLocations)) { throw new ConfigurationException("Please set property: " + "log.oozie.location"); } logFiles = getLogFiles(logLocations); if (logFiles.size() > config.getInt("log.oozie.max.files")) { logger.error("Too many log files: " + logFiles); return; } String writeMayBe = config.getString("log.oozie.write.location"); if (StringUtils.isEmpty(writeMayBe)) { if (logLocations.length == 1 && new File(logLocations[0]).isDirectory()) { writeLocation = logLocations[0] + "/oozie_logs/"; } else { throw new ConfigurationException("Please set property: " + "log.oozie.write.location"); } } else { writeLocation = writeMayBe; } }
From source file:org.apache.niolex.commons.codec.IntegerUtil.java
/** * Check whether the target is in the argument array. *// w ww. j a va 2s . com * @param target the target need be checked * @param args the argument array * @return true if found, false otherwise */ public static final boolean isIn(int target, int... args) { if (ArrayUtils.isEmpty(args)) { return false; } for (int i : args) { if (target == i) return true; } return false; }
From source file:org.apache.niolex.commons.codec.StringUtil.java
/** * Check whether the target is in the argument array. * * @param target the target need be checked * @param caseSensitive true if case sensitive * @param args the argument array/* w w w .j a v a2s . co m*/ * @return true if found, false otherwise */ public static final boolean isIn(String target, boolean caseSensitive, String... args) { if (ArrayUtils.isEmpty(args)) { return false; } for (String s : args) { if (caseSensitive) { if (target.equals(s)) { return true; } } else { if (target.equalsIgnoreCase(s)) { return true; } } } return false; }
From source file:org.apache.niolex.commons.codec.StringUtil.java
/** * Test whether the target contains any of the string in the argument array. * * @param target the target need be checked * @param args the argument array// ww w . j a va 2s .c om * @return true if found, false otherwise */ public static final boolean containsAny(String target, String... args) { if (ArrayUtils.isEmpty(args)) { return false; } for (String s : args) { if (target.contains(s)) { return true; } } return false; }
From source file:org.apache.niolex.commons.file.DirUtil.java
/** * Delete the directory or file represented by this file. * * @param file the file to be deleted//ww w . j ava 2 s . com * @param byForce whether we should recursively delete children. * @return true if deleted or file not exist, false otherwise */ public static final boolean delete(File file, boolean byForce) { if (!file.exists()) { return true; } if (file.isDirectory()) { File[] files = file.listFiles(); if (ArrayUtils.isEmpty(files)) { return file.delete(); } if (byForce) { for (File f : files) { delete(f, true); } return file.delete(); } else { return false; } } else { return file.delete(); } }
From source file:org.apache.niolex.commons.mail.EmailUtil.java
/** * Send an email.// ww w . j ava 2 s. co m * ???? * * @param from the email sender * @param tos the email receivers array * @param ccs the carbon copiers array * @param title the email title * @param text the email body * @param attachments the email attachments list * @param priority priority from 1-5 the smaller is higher * @param isHtml is the text in HTML format or not * @param encoding the encoding of email, i.e. "GBK"?"UTF-8" * @throws MailException * @throws MessagingException */ public static void sendMail(String from, String[] tos, String[] ccs, String title, String text, List<Pair<String, InputStreamSource>> attachments, String priority, boolean isHtml, String encoding) throws MailException, MessagingException { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, encoding); messageHelper.setFrom(from); messageHelper.setBcc(from); if (ArrayUtils.isEmpty(tos)) { throw new IllegalArgumentException("<tos> can not be null or empty!"); } else { messageHelper.setTo(tos); } if (!ArrayUtils.isEmpty(ccs)) { messageHelper.setCc(ccs); } messageHelper.setSubject(title); messageHelper.setText(text, isHtml); if (attachments != null) { for (Pair<String, InputStreamSource> pair : attachments) { messageHelper.addAttachment(pair.a, pair.b); } } mimeMessage = messageHelper.getMimeMessage(); if (priority != null) { mimeMessage.addHeader("X-Priority", priority); } mailSender.send(mimeMessage); }