List of usage examples for org.apache.commons.lang ArrayUtils toPrimitive
public static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives.
From source file:org.global.canvas.services.impl.DrawServiceImpl.java
public void draw(DrawEvent event) { currentUser = event.getUser();/* w ww . ja va 2 s.co m*/ if (event.getType().equals("dragstart")) { domImpl = GenericDOMImplementation.getDOMImplementation(); document = domImpl.createDocument(svgNS, "svg", null); svgGenerator = new SVGGraphics2D(document); System.out.println("Color here: " + event.getColor()); svgGenerator.setColor(Color.decode(event.getColor())); svgGenerator.setStroke( new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0)); } currentX.add(event.getX()); currentY.add(event.getY()); if (event.getType().equals("dragend")) { svgGenerator.drawPolyline(ArrayUtils.toPrimitive(currentX.toArray(new Integer[0])), ArrayUtils.toPrimitive(currentY.toArray(new Integer[0])), currentX.size()); export(); domImpl = null; document = null; svgGenerator = null; currentX.clear(); currentY.clear(); } }
From source file:org.hyperic.hq.measurement.agent.server.MeasurementSchedule.java
private void populateSRNInfo() { srnList.clear();//from w w w . j a va 2s .co m final String lengthBuf = store.getValue(PROP_MSRNS_LENGTH); final List<Byte> encSRNBytes = new ArrayList<Byte>(); if (lengthBuf == null) { final String mSchedBuf = store.getValue(PROP_MSRNS); if (mSchedBuf == null) { log.warn("no srns to retrieve from storage"); return; } final byte[] bytes = Base64.decode(mSchedBuf); encSRNBytes.addAll(Arrays.asList(ArrayUtils.toObject(bytes))); } else { final int length = Integer.parseInt(lengthBuf); for (int i = 0; i < length; i++) { final byte[] bytes = Base64.decode(store.getValue(PROP_MSRNS + "_" + i)); encSRNBytes.addAll(Arrays.asList(ArrayUtils.toObject(bytes))); } } byte[] srnBytes = ArrayUtils.toPrimitive(encSRNBytes.toArray(new Byte[0])); HashSet<AppdefEntityID> seenEnts = new HashSet<AppdefEntityID>(); String srnBuf = new String(srnBytes); ByteArrayInputStream bIs = new ByteArrayInputStream(srnBytes); DataInputStream dIs = new DataInputStream(bIs); try { int numSRNs = dIs.readInt(); int entType, entID, revNo; for (int i = 0; i < numSRNs; i++) { entType = dIs.readInt(); entID = dIs.readInt(); revNo = dIs.readInt(); AppdefEntityID ent = new AppdefEntityID(entType, entID); if (seenEnts.contains(ent)) { log.warn("Entity '" + ent + "' contained more than once in SRN storage. Ignoring"); continue; } seenEnts.add(ent); srnList.add(new SRN(ent, revNo)); } } catch (IOException exc) { this.log.error("Unable to decode SRN list: " + exc + " srn=\"" + srnBuf + "\"", exc); } }
From source file:org.hyperic.hq.measurement.agent.server.MeasurementSchedule.java
private void writeSRNs() throws AgentStorageException { ByteArrayOutputStream bOs;/*w w w .j a va2s .co m*/ DataOutputStream dOs; bOs = new ByteArrayOutputStream(); dOs = new DataOutputStream(bOs); synchronized (srnList) { try { dOs.writeInt(srnList.size()); for (SRN srn : srnList) { AppdefEntityID ent = srn.getEntity(); dOs.writeInt(ent.getType()); dOs.writeInt(ent.getID()); dOs.writeInt(srn.getRevisionNumber()); } List<Byte> bytes = Arrays.asList(ArrayUtils.toObject(bOs.toByteArray())); int size = bytes.size(); if (size > MAX_ELEM_SIZE) { store.setValue(PROP_MSRNS_LENGTH, new Integer((size / MAX_ELEM_SIZE) + 1).toString()); int ii = 0; for (int i = 0; i < size; i += MAX_ELEM_SIZE) { int start = i; int max = Math.min(i + MAX_ELEM_SIZE, size); List<Byte> subList = bytes.subList(start, max); Byte[] b = subList.toArray(new Byte[0]); store.setValue(MeasurementSchedule.PROP_MSRNS + "_" + ii++, Base64.encode(ArrayUtils.toPrimitive(b))); } } else { store.setValue(PROP_MSRNS_LENGTH, "1"); Byte[] b = bytes.toArray(new Byte[0]); store.setValue(MeasurementSchedule.PROP_MSRNS + "_0", Base64.encode(ArrayUtils.toPrimitive(b))); } } catch (IOException exc) { this.log.error("Error encoding SRN list", exc); return; } } }
From source file:org.jage.algorithms.commons.solution.SolutionFactory.java
@Override public IVectorSolution<Integer> createInitializedSolution() { count++;/* w ww . java 2 s .c om*/ LOG.debug("count: " + count); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < problem.getDimension(); i++) { list.add(i); } Collections.shuffle(list); LOG.debug("Initialized solution: " + list); return new VectorSolution<Integer>( new FastIntArrayList(ArrayUtils.toPrimitive(list.toArray(new Integer[problem.getDimension()])))); }
From source file:org.jam.metrics.applicationmetrics.MetricPlot.java
public static synchronized void plot(Metric metricAnnotation, String fieldName, Object target, MetricProperties properties, String group, int refreshRate, int i) { if (i == 0)//w w w . java 2s . c o m plotsUsed.clear(); MetricsCache metricsCacheInstance; metricsCacheInstance = MetricsCacheCollection.getMetricsCacheCollection().getMetricsCacheInstance(group); MetricObject mo = null; if (metricsCacheInstance != null) { String instanceName = fieldName + "_" + target; mo = metricsCacheInstance.searchMetricObject(instanceName); } String plotName = metricAnnotation.plot()[i]; MetricOfPlot mOP = new MetricOfPlot(fieldName, plotName); if (DeploymentMetricProperties.getDeploymentMetricProperties().getDeploymentInternalParameters(group) .getPlotedCount().get(mOP) == null) DeploymentMetricProperties.getDeploymentMetricProperties().getDeploymentInternalParameters(group) .resetPlotedCount(mOP); if (mo != null) { int plotSize = 0; if (refreshRate == 0) { plotSize = mo.getMetric().size(); DeploymentMetricProperties.getDeploymentMetricProperties().getDeploymentInternalParameters(group) .putPlotedCount(mOP, plotSize); } else if (DeploymentMetricProperties.getDeploymentMetricProperties() .getDeploymentInternalParameters(group).getPlotedCount().get(mOP) + refreshRate <= mo.getMetric().size()) { plotSize = DeploymentMetricProperties.getDeploymentMetricProperties() .getDeploymentInternalParameters(group).getPlotedCount().get(mOP) + refreshRate; DeploymentMetricProperties.getDeploymentMetricProperties().getDeploymentInternalParameters(group) .putPlotedCount(mOP, plotSize); } if (plotSize != 0) { Double[] plotArray = mo.getMetric().toArray(new Double[plotSize]); Plot2DPanel plot = properties.getPlots().get(plotName); Color color = null; if (metricAnnotation.color().length != 0) { String colorName = metricAnnotation.color()[i]; color = properties.getColors().get(colorName); } int plotHandler = DeploymentMetricProperties.getDeploymentMetricProperties() .getDeploymentInternalParameters(group).getPlotHandler().get(plotName) == null ? 0 : DeploymentMetricProperties.getDeploymentMetricProperties() .getDeploymentInternalParameters(group).getPlotHandler().get(plotName); try { if (!plotsUsed.contains(plotName)) { plot.removePlot(plotHandler); plotsUsed.add(plotName); } } catch (Exception e) { } String typePlot; try { typePlot = metricAnnotation.typePlot()[i]; } catch (Exception e) { typePlot = "line"; } if (color != null) { if (typePlot.compareTo("bar") == 0) plotHandler = plot.addBarPlot(plotName, color, ArrayUtils.toPrimitive(plotArray)); else if (typePlot.compareTo("scatter") == 0) plotHandler = plot.addScatterPlot(plotName, color, ArrayUtils.toPrimitive(plotArray)); else plotHandler = plot.addLinePlot(plotName, color, ArrayUtils.toPrimitive(plotArray)); } else { if (typePlot.compareTo("bar") == 0) plotHandler = plot.addBarPlot(plotName, ArrayUtils.toPrimitive(plotArray)); else if (typePlot.compareTo("scatter") == 0) plotHandler = plot.addScatterPlot(plotName, ArrayUtils.toPrimitive(plotArray)); else plotHandler = plot.addLinePlot(plotName, ArrayUtils.toPrimitive(plotArray)); } DeploymentMetricProperties.getDeploymentMetricProperties().getDeploymentInternalParameters(group) .getPlotHandler().put(plotName, plotHandler); } } }
From source file:org.janusgraph.diskstorage.log.kcvs.KCVSLogManager.java
/** * Opens a log manager against the provided KCVS store with the given configuration. Also provided is a list * of read-partition-ids. These only apply when readers are registered against an opened log. In that case, * the readers only read from the provided list of partition ids. * @param storeManager/* w ww . j a va2 s . c om*/ * @param config * @param readPartitionIds */ public KCVSLogManager(KeyColumnValueStoreManager storeManager, final Configuration config, final int[] readPartitionIds) { Preconditions.checkArgument(storeManager != null && config != null); if (config.has(LOG_STORE_TTL)) { indexStoreTTL = ConversionHelper.getTTLSeconds(config.get(LOG_STORE_TTL)); StoreFeatures storeFeatures = storeManager.getFeatures(); if (storeFeatures.hasCellTTL() && !storeFeatures.hasStoreTTL()) { // Reduce cell-level TTL (fine-grained) to store-level TTL (coarse-grained) storeManager = new TTLKCVSManager(storeManager); } else if (!storeFeatures.hasStoreTTL()) { log.warn( "Log is configured with TTL but underlying storage backend does not support TTL, hence this" + "configuration option is ignored and entries must be manually removed from the backend."); } } else { indexStoreTTL = -1; } this.storeManager = storeManager; this.configuration = config; openLogs = new HashMap<String, KCVSLog>(); this.senderId = config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID); Preconditions.checkNotNull(senderId); int maxPartitions; if (config.has(LOG_MAX_PARTITIONS)) maxPartitions = config.get(LOG_MAX_PARTITIONS); else maxPartitions = Math.max(1, config.get(CLUSTER_MAX_PARTITIONS) / CLUSTER_SIZE_DIVIDER); Preconditions.checkArgument(maxPartitions <= config.get(CLUSTER_MAX_PARTITIONS), "Number of log partitions cannot be larger than number of cluster partitions"); this.partitionBitWidth = NumberUtil.getPowerOf2(maxPartitions); Preconditions.checkArgument(partitionBitWidth >= 0 && partitionBitWidth < 32); final int numPartitions = (1 << partitionBitWidth); //Partitioning if (partitionBitWidth > 0 && !config.get(LOG_FIXED_PARTITION)) { //Write partitions - default initialization: writing to all partitions int[] writePartitions = new int[numPartitions]; for (int i = 0; i < numPartitions; i++) writePartitions[i] = i; if (storeManager.getFeatures().hasLocalKeyPartition()) { //Write only to local partitions List<Integer> localPartitions = new ArrayList<Integer>(); try { List<PartitionIDRange> partitionRanges = PartitionIDRange.getIDRanges(partitionBitWidth, storeManager.getLocalKeyPartition()); for (PartitionIDRange idrange : partitionRanges) { for (int p : idrange.getAllContainedIDs()) localPartitions.add(p); } } catch (Throwable e) { log.error("Could not process local id partitions", e); } if (!localPartitions.isEmpty()) { writePartitions = ArrayUtils .toPrimitive(localPartitions.toArray(new Integer[localPartitions.size()])); } } this.defaultWritePartitionIds = writePartitions; //Read partitions if (readPartitionIds != null && readPartitionIds.length > 0) { for (int readPartitionId : readPartitionIds) { checkValidPartitionId(readPartitionId, partitionBitWidth); } this.readPartitionIds = Arrays.copyOf(readPartitionIds, readPartitionIds.length); } else { this.readPartitionIds = new int[numPartitions]; for (int i = 0; i < numPartitions; i++) this.readPartitionIds[i] = i; } } else { this.defaultWritePartitionIds = new int[] { 0 }; Preconditions.checkArgument( readPartitionIds == null || (readPartitionIds.length == 0 && readPartitionIds[0] == 0), "Cannot configure read partition ids on unpartitioned backend or with fixed partitions enabled"); this.readPartitionIds = new int[] { 0 }; } this.serializer = new StandardSerializer(); }
From source file:org.janusproject.acl.encoding.bitefficient.BitEfficientACLCodec.java
/** * {@inheritDoc}// w w w . j ava 2 s . c o m * * @see #toBitEfficient(ACLMessage) */ @Override public byte[] encode(ACLMessage aMsg) { return ArrayUtils.toPrimitive(toBitEfficient(aMsg).toArray(new Byte[0])); }
From source file:org.janusproject.acl.encoding.bitefficient.BitEfficientACLCodecHelperDecode.java
/** * List of Byte to array of byte//w ww . j ava 2 s . c om * * @param buffer * @return array of byte from buffer */ private static byte[] toPrimitive(List<Byte> buffer) { return ArrayUtils.toPrimitive(buffer.toArray(new Byte[0])); }
From source file:org.jaulp.wicket.base.util.WicketImageUtils.java
/** * Gets the image.//from w w w . j a va2 s . c o m * * @param wicketId * the id from the image for the html template. * @param contentType * the content type * @param data * the data * @return the image */ public static Image getImage(final String wicketId, final String contentType, final Byte[] data) { byte[] byteArrayData = ArrayUtils.toPrimitive(data); return getImage(wicketId, contentType, byteArrayData); }
From source file:org.jaulp.wicket.base.util.WicketImageUtils.java
/** * Gets a non caching image from the given wicketId, contentType and the Byte array data. * /*from ww w. j a va2s .c o m*/ * @param wicketId * the id from the image for the html template. * @param contentType * the content type of the image. * @param data * the data for the image as an Byte array. * @return the non caching image */ public static NonCachingImage getNonCachingImage(final String wicketId, final String contentType, final Byte[] data) { byte[] byteArrayData = ArrayUtils.toPrimitive(data); return getNonCachingImage(wicketId, contentType, byteArrayData); }