Java Code Examples for java.util.LinkedList#toArray()
The following examples show how to use
java.util.LinkedList#toArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisualisationUtilities.java From chipster with MIT License | 6 votes |
public static Variable[] getVariablesFilteredInclusive(DataBean dataBean, String startsWith, boolean removeStart) { String exprHeader = "/column/"; LinkedList<Variable> vars = new LinkedList<Variable>(); try (Table columns = dataBean.queryFeatures("/column/*").asTable()) { for (String columnName : columns.getColumnNames()) { if (columnName.startsWith(startsWith)) { String chipName; if (removeStart) { chipName = columnName.substring(startsWith.length()); } else { chipName = columnName; } String expression = exprHeader + columnName; vars.add(new Variable(chipName, expression)); } } } catch (MicroarrayException e) { application.reportException(new MicroarrayException("no chips to visualise")); } return vars.toArray(new Variable[0]); }
Example 2
Source File: ZipFileUtil.java From java-trader with Apache License 2.0 | 6 votes |
public static ZipEntry[] listEntries(File zip, String classification) throws IOException { if ( !zip.exists() ) { return new ZipEntry[0]; } LinkedList<ZipEntry> result = new LinkedList<>(); ZipFile originalZip = new ZipFile(zip); Enumeration<? extends ZipEntry> entries = originalZip.entries(); while (entries.hasMoreElements()) { ZipEntry e = entries.nextElement(); if ( e.isDirectory() ) { continue; } if ( classification==null ){ result.add(e); continue; } String entryName = e.getName(); if ( entryName.indexOf(classification)>0 ) { result.add(e); } } originalZip.close(); return result.toArray(new ZipEntry[result.size()]); }
Example 3
Source File: GitUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Normalize flat files, Git treats folder as normal file * so it's necessary explicitly list direct descendants to * get classical flat behaviour. * <strong>Does not return up-to-date files</strong> * * <p> E.g. revert on package node means: * <ul> * <li>revert package folder properties AND * <li>revert all modified (including deleted) files in the folder * </ul> * * @return files with given status and direct descendants with given status. */ public static File[] flatten(File[] files, Set<Status> statuses) { LinkedList<File> ret = new LinkedList<File>(); FileStatusCache cache = Git.getInstance().getFileStatusCache(); for (int i = 0; i<files.length; i++) { File dir = files[i]; FileInformation info = cache.getStatus(dir); if (info.containsStatus(statuses)) { ret.add(dir); } File[] entries = cache.listFiles(dir); // comparing to dir.listFiles() lists already deleted too for (int e = 0; e<entries.length; e++) { File entry = entries[e]; info = cache.getStatus(entry); if (info.containsStatus(statuses)) { ret.add(entry); } } } return ret.toArray(new File[ret.size()]); }
Example 4
Source File: Heap.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void restoreFromBundle( Bundle bundle ) { pos = bundle.getInt( POS ); seen = bundle.getBoolean( SEEN ); type = Type.valueOf( bundle.getString( TYPE ) ); items = new LinkedList( bundle.getCollection( ITEMS ) ); items.removeAll(Collections.singleton(null)); //remove any document pages that either don't exist anymore or that the player already has for (Item item : items.toArray(new Item[0])){ if (item instanceof DocumentPage && ( !((DocumentPage) item).document().pages().contains(((DocumentPage) item).page()) || ((DocumentPage) item).document().hasPage(((DocumentPage) item).page()))){ items.remove(item); } } haunted = bundle.getBoolean( HAUNTED ); }
Example 5
Source File: FanField3.java From IngressAnimations with GNU General Public License v3.0 | 6 votes |
@Override protected Portal[] getPortals() { Random rr = new Random(32324524); int n = getNumberOfPortalsExcludingAnchor(); LinkedList<Portal> pp = new LinkedList<>(); double p1X = 200; double p1Y = -400; double p2X = -500; double p2Y = 200; double p3X = 600; double p3Y = 300; pp.add(new Portal(p1X,p1Y, Faction.ENL.getColor())); pp.add(new Portal(p2X,p2Y, Color.GRAY)); pp.add(new Portal(p3X,p3Y, Color.GRAY)); for (int i=3; i<=n; i++) { double theta = Math.PI/2*(i-2)/(n-1)+rr.nextGaussian()*0.02*Math.PI/2/n; double r = rr.nextDouble()*0.7+0.2; double a= r*Math.cos(theta); double b= r*Math.sin(theta); double x = p1X + (p2X-p1X)*a + (p3X-p1X)*b; double y = p1Y + (p2Y-p1Y)*a + (p3Y-p1Y)*b; pp.add(new Portal(x, y, Color.GRAY)); } return pp.toArray(new Portal[0]); }
Example 6
Source File: ProcessDocumentProvider.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * @generated */ protected ISchedulingRule getSynchronizeRule(Object element) { ResourceSetInfo info = getResourceSetInfo(element); if (info != null) { LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>(); for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = it.next(); IFile file = WorkspaceSynchronizer.getFile(nextResource); if (file != null) { rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().refreshRule(file)); } } return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()])); } return null; }
Example 7
Source File: ModuleOverrideHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
/** * Retrieves an array of spell chain elements ordered by their occurrence in the chain, * which implement at least one override. * * @param spellRing the head element of the spell chain. * @return the array containing all elements having an override. */ private static SpellRing[] getSequenceFromSpellChain(SpellRing spellRing) { SpellRing cur = spellRing; LinkedList<SpellRing> instances = new LinkedList<>(); while (cur != null) { ModuleInstance module = cur.getModule(); if (module == null) continue; if (module.getFactory().hasOverrides()) { instances.add(cur); } cur = cur.getChildRing(); } return instances.toArray(new SpellRing[instances.size()]); }
Example 8
Source File: ValidationUtils.java From para with Apache License 2.0 | 6 votes |
/** * Validates objects using Hibernate Validator. * @param content an object to be validated * @return a list of error messages or empty if object is valid */ public static String[] validateObject(ParaObject content) { if (content == null) { return new String[]{"Object cannot be null."}; } LinkedList<String> list = new LinkedList<>(); try { for (ConstraintViolation<ParaObject> constraintViolation : getValidator().validate(content)) { String prop = "'".concat(constraintViolation.getPropertyPath().toString()).concat("'"); list.add(prop.concat(" ").concat(constraintViolation.getMessage())); } } catch (Exception e) { logger.error(null, e); } return list.toArray(new String[]{}); }
Example 9
Source File: DataSelectionManager.java From chipster with MIT License | 5 votes |
public DataBean[] getSelectedDatasAsArray() { LinkedList<DataBean> beans = new LinkedList<DataBean>(); for (DataBean bean : getSelectedDataBeans()) { beans.add(bean); } return beans.toArray(new DataBean[0]); }
Example 10
Source File: XMLUtil.java From ns4_frame with Apache License 2.0 | 5 votes |
public static Element[] getChildrenByName(Element e, String name) { NodeList nl = e.getChildNodes(); int max = nl.getLength(); LinkedList list = new LinkedList(); for (int i = 0; i < max; i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { list.add(n); } } return (Element[]) list.toArray(new Element[list.size()]); }
Example 11
Source File: LinkedListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * toArray(null) throws NullPointerException */ public void testToArray_NullArg() { LinkedList l = new LinkedList(); l.add(new Object()); try { l.toArray(null); shouldThrow(); } catch (NullPointerException success) {} }
Example 12
Source File: PlatformClasses.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static synchronized String[] getNames() { if (names == null) { LinkedList<String> list = new LinkedList<String>(); InputStream str = PlatformClasses.class .getResourceAsStream("/com/sun/tools/hat/resources/platform_names.txt"); if (str != null) { try { BufferedReader rdr = new BufferedReader(new InputStreamReader(str)); for (;;) { String s = rdr.readLine(); if (s == null) { break; } else if (s.length() > 0) { list.add(s); } } rdr.close(); str.close(); } catch (IOException ex) { ex.printStackTrace(); // Shouldn't happen, and if it does, continuing // is the right thing to do anyway. } } names = list.toArray(new String[list.size()]); } return names; }
Example 13
Source File: Evaluator.java From vn.vitk with GNU General Public License v3.0 | 5 votes |
/** * Pads two strings before comparing them. * @param s1 an array of words (an automatically tokenized sentence) * @param s2 an array of words (a manually tokenized sentence) * @return */ private static String[][] padStrings(String[] s1, String[] s2) { String[][] result = new String[2][]; LinkedList<String> l1 = new LinkedList<String>(Arrays.asList(s1)); LinkedList<String> l2 = new LinkedList<String>(Arrays.asList(s2)); int i1 = 0; int i2 = 0; while (i1 < l1.size() && i2 < l2.size()) { String e1 = l1.get(i1); String[] a1 = e1.split("_"); String e2 = l2.get(i2); String[] a2 = e2.split("_"); if (a1.length >= a2.length) { for (int j = 0; j < a1.length - a2.length; j++) { l1.add(i1+1, PADDING_STRING_1); } } else { for (int j = 0; j < a2.length - a1.length; j++) { l2.add(i2+1, PADDING_STRING_2); } } i1++; i2++; } if (l1.size() != l2.size()) { System.err.println("Error: After padding, two lists must be equal in size!"); System.err.println(l1); System.err.println(l2); } result[0] = l1.toArray(new String[l1.size()]); result[1] = l2.toArray(new String[l2.size()]); return result; }
Example 14
Source File: ColorStateListUtils.java From timecat with Apache License 2.0 | 5 votes |
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { final int innerDepth = parser.getDepth() + 1; int depth; int type; LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) { continue; } TypedArray a1 = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.color}); final int value = a1.getResourceId(0, Color.MAGENTA); final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value); a1.recycle(); TypedArray a2 = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.alpha}); final float alphaMod = a2.getFloat(0, 1.0f); a2.recycle(); colorList.add(alphaMod != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod)) : baseColor); stateList.add(extractStateSet(attrs)); } if (stateList.size() > 0 && stateList.size() == colorList.size()) { int[] colors = new int[colorList.size()]; for (int i = 0; i < colorList.size(); i++) { colors[i] = colorList.get(i); } return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors); } return null; }
Example 15
Source File: Blade.java From Gaalop with GNU Lesser General Public License v3.0 | 5 votes |
public static Blade createBladeFromExpression(Expression expr) { final LinkedList<String> list = new LinkedList<String>(); DFGTraversalVisitor visitor = new DFGTraversalVisitor() { @Override public void visit(BaseVector node) { list.add(node.toString()); super.visit(node); } }; expr.accept(visitor); return new Blade(list.toArray(new String[0])); }
Example 16
Source File: WebViewEventDispatcher.java From oim-fx with MIT License | 5 votes |
private static TransferMode[] getFXDndAction(int wkDndAction) { LinkedList<TransferMode> tms = new LinkedList<TransferMode>(); if ((wkDndAction & WK_DND_ACTION_COPY) != 0) tms.add(TransferMode.COPY); if ((wkDndAction & WK_DND_ACTION_MOVE) != 0) tms.add(TransferMode.MOVE); if ((wkDndAction & WK_DND_ACTION_LINK) != 0) tms.add(TransferMode.LINK); return tms.toArray(new TransferMode[0]); }
Example 17
Source File: PlatformClasses.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static synchronized String[] getNames() { if (names == null) { LinkedList<String> list = new LinkedList<String>(); InputStream str = PlatformClasses.class .getResourceAsStream("/com/sun/tools/hat/resources/platform_names.txt"); if (str != null) { try { BufferedReader rdr = new BufferedReader(new InputStreamReader(str)); for (;;) { String s = rdr.readLine(); if (s == null) { break; } else if (s.length() > 0) { list.add(s); } } rdr.close(); str.close(); } catch (IOException ex) { ex.printStackTrace(); // Shouldn't happen, and if it does, continuing // is the right thing to do anyway. } } names = list.toArray(new String[list.size()]); } return names; }
Example 18
Source File: Serializer.java From Diorite with MIT License | 4 votes |
private void serializeNode(Node node, @Nullable Node parent, LinkedList<String> commentPath, boolean mappingScalar) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); String[] pathNodes = commentPath.toArray(new String[commentPath.size()]); String comment; if (this.checkCommentsSet(pathNodes)) { comment = this.comments.getComment(pathNodes); } else { comment = null; } ImplicitTuple tuple = new ImplicitTupleExtension(node.getTag().equals(detectedTag), node.getTag().equals(defaultTag), comment); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true)); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); List<Node> list = seqNode.getValue(); for (Node item : list) { this.serializeNode(item, node, commentPath, false); } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = node.getTag().equals(implicitTag); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); if (key instanceof ScalarNode) { commentPath.add(((ScalarNode) key).getValue()); } this.serializeNode(key, mnode, commentPath, true); this.serializeNode(value, mnode, commentPath, false); if (key instanceof ScalarNode) { commentPath.removeLast(); } } this.emitter.emit(new MappingEndEvent(null, null)); } } }
Example 19
Source File: GTInfo.java From kylin with Apache License 2.0 | 4 votes |
private void validateColumnBlocks() { colAll = new ImmutableBitSet(0, nColumns); if (colBlocks == null) { colBlocks = new ImmutableBitSet[2]; colBlocks[0] = primaryKey; colBlocks[1] = colAll.andNot(primaryKey); } colBlocksAll = new ImmutableBitSet(0, colBlocks.length); if (colPreferIndex == null) colPreferIndex = ImmutableBitSet.EMPTY; // column blocks must not overlap for (int i = 0; i < colBlocks.length; i++) { for (int j = i + 1; j < colBlocks.length; j++) { if (colBlocks[i].intersects(colBlocks[j])) throw new IllegalStateException(); } } // column block must cover all columns ImmutableBitSet merge = ImmutableBitSet.EMPTY; for (int i = 0; i < colBlocks.length; i++) { merge = merge.or(colBlocks[i]); } if (!merge.equals(colAll)) throw new IllegalStateException(); // primary key must be the first column block if (!primaryKey.equals(colBlocks[0])) throw new IllegalStateException(); // drop empty column block LinkedList<ImmutableBitSet> list = new LinkedList<ImmutableBitSet>(Arrays.asList(colBlocks)); Iterator<ImmutableBitSet> it = list.iterator(); while (it.hasNext()) { ImmutableBitSet cb = it.next(); if (cb.isEmpty()) it.remove(); } colBlocks = list.toArray(new ImmutableBitSet[list.size()]); // for dynamic dimensions if (dynamicDims == null) dynamicDims = ImmutableBitSet.EMPTY; }
Example 20
Source File: MatchBlockRMA2Formatter.java From megan-ce with GNU General Public License v3.0 | 4 votes |
private void decode(String format) { LinkedList<Object[]> list = new LinkedList<>(); StringTokenizer tokenizer = new StringTokenizer(format, ";"); while (tokenizer.hasMoreElements()) { String[] split = tokenizer.nextToken().split(":"); String name = split[0]; String type = split[1]; Object[] object = new Object[]{name, type.charAt(0), null}; switch (type.charAt(0)) { case 'i': case 'f': numberOfBytes += 4; break; case 'l': numberOfBytes += 8; break; case 'b': numberOfBytes += 1; break; case 'B': numberOfBytes += 6; break; case 'c': numberOfBytes += 2; break; } name2data.put(name, object); list.add(object); } data = list.toArray(new Object[list.size()][]); // access to standard items set here: bitScore = name2data.get("BitScore"); expected = name2data.get("Expected"); percentIdentity = name2data.get("Identity"); taxonId = name2data.get("TaxonId"); seedId = name2data.get("SeedId"); cogId = name2data.get("CogId"); keggId = name2data.get("KeggId"); pfamId = name2data.get("PfamId"); refSeqId = name2data.get("RefSeqID"); }