public void checkCollisions() { Rectangle r3 = link.getBounds(); for (int j = 0; j < enemies.size(); j++) { Enemy en = (Enemy) enemies.get(j); Rectangle r2 = en.getBounds(); if (r3.intersects(r2)) { link.setVisible(false); en.setVisible(false); ingame = false; gamewin = false; } // end if } // end for loop ArrayList as = link.getArrows(); for (int i = 0; i < as.size(); i++) { Arrow aa = (Arrow) as.get(i); Rectangle r1 = aa.getBounds(); for (int j = 0; j < enemies.size(); j++) { Enemy a = (Enemy) enemies.get(j); Rectangle r2 = a.getBounds(); if (r1.intersects(r2)) { aa.setVisible(false); a.setVisible(false); } // end of if } // end inner for loop } // end outer for loop } // end checkCollisions
public String editLink() { if (editedLinks == null) throw new IllegalStateException("Not in editing state"); Link currentLink = getCurrentLink(); editingLinks.add(currentLink); originalLinks.add((Link) currentLink.clone()); return ""; }
public String editLinks() { editedLinks = new ArrayList<Link>(links.size()); for (Link link : links) { editedLinks.add((Link) link.clone()); } return ""; }
public Content get(Key key) throws Exception { // TODO retrieve the bkp address, then look at their content // if the content is a link (LINK:<key>), then recursively retrieve the // content // of the link. // JLG.debug("getFromKey:" + key); Content result = null; Queue<Address> queue = new LinkedList<Address>(); Address[] address = getAddressList(key); Content[] contentArray = new Content[address.length]; for (int i = 0; i < address.length; i++) { contentArray[i] = get(address[i]); if (contentArray[i] == null) { queue.offer(address[i]); // TODO reassign content to address } else { result = contentArray[i]; } } if (result == null) { return null; } if (result.isLink()) { Link link = (Link) result; // JLG.debug("key " + key + " is a link on " + link.getTargetKey()); result = get(link.getTargetKey()); } return result; }
public Patient addLink(String url, String rel) { Link link = new Link(); link.setLink(url); link.setRel(rel); links.add(link); return this; }
public void setWithLink(OCPUser user, Content data, Link link) throws Exception { // if a link already exists with the same key, then delete it. Key key = link.getKey(); if (exists(key)) { // remove both the link and its targets recursively remove(user, key); } Key targetKey = link.getTargetKey(); if (exists(targetKey)) { remove(user, targetKey); } // check that the link targetKey is the data key checkLink(data, link); Address[] address = getAddressList(key); for (byte i = 0; i < address.length; i++) { store(address[i], link); } address = getAddressList(targetKey); for (byte i = 0; i < address.length; i++) { store(address[i], data); } }
public void displayList() { Link current = first; while (current != null) { current.displayLink(); current = current.next; } }
private int maxMin(Link temp, int d) { if (d == depth) return static_estimation(temp.b_pos); // if the current node is the leaf node else { int num_WhitePieces = 0, num_BlackPieces = 0; for (int i = 0; i < temp.b_pos.length(); i++) { if (temp.b_pos.charAt(i) == 'W') num_WhitePieces++; if (temp.b_pos.charAt(i) == 'B') num_BlackPieces++; } if (num_WhitePieces == 3) temp.LL = generateHopping(temp.b_pos, temp.LL); else temp.LL = generateMove(temp.b_pos, temp.LL); if (temp.LL.first == null || num_WhitePieces <= 2 || num_BlackPieces <= 2) { return static_estimation(temp.b_pos); } d++; // increase the current depth value int v = -10000; int temp_minMax = 0; Link extra; extra = temp.LL.first; // for each child y of x: while (extra != null) { temp_minMax = minMax(extra, d); extra.pos_estimate = temp_minMax; if (temp_minMax > v) v = temp_minMax; extra = extra.nextLink; } return v; } }
/** Sorts the static LinkedList mainlineLinks in the order they appear on the freeway */ private LinkedList<Link> recursiveLinkSort(LinkedList<Link> links2) { if (links2.size() == 1) { return links2; } else { boolean swapMade = false; ListIterator<Link> itr1 = links2.listIterator(); while (itr1.hasNext()) { Link temp = itr1.next(); int tempindex = itr1.nextIndex(); // if this loop makes any switches, set the flag to true if (links2.getFirst().getUpNode().getNodeID() == temp.getDownNode().getNodeID()) { swapMade = true; links2.addFirst(temp); links2.remove(tempindex); return this.recursiveLinkSort(links2); } } if (!swapMade) { // assign last n-1 links to links3 LinkedList<Link> links3 = new LinkedList<Link>(); Link temp = links2.getFirst(); links2.removeFirst(); links3 = this.recursiveLinkSort(links2); links3.addFirst(temp); return links3; } else { return links2; } } }
/** * Write a MouseEvent on the link to the server. * * @param descriptor the MASK that describes the event. * @param me the MouseEvent * @param latPoint the latitude of the mouse event. * @param lonPoint the longitude of the mouse event. * @param props an array of strings representing key-value pairs. * @param link the link to write the gesture to. */ public static void write( int descriptor, MouseEvent me, float latPoint, float lonPoint, LinkProperties props, Link link) throws IOException { if (props.getProperty(LPC_GRAPHICID) != null) { descriptor = LinkUtil.setMask(descriptor, GRAPHIC_ID_MASK); } link.start(Link.ACTION_REQUEST_HEADER); link.dos.writeFloat(version); link.dos.writeInt(descriptor); link.dos.writeInt(me.getX()); link.dos.writeInt(me.getY()); link.dos.writeInt(me.getClickCount()); link.dos.writeInt(me.getModifiers()); link.dos.writeFloat(latPoint); link.dos.writeFloat(lonPoint); props.write(link); link.end(Link.END_TOTAL); }
/** * Retrieve all links of with the given type * * @param type attribute of link to search for * @return List of found Links */ public List<Link> findLinksByType(String type) { List<Link> foundLinks = new ArrayList<Link>(); for (Link link : this) { if (type.equals(link.getType())) foundLinks.add(link); } return foundLinks; }
@Override public void recordstate(double time, boolean exportflows, int outsteps) throws SiriusException { success = false; double min = Math.floor(time / 60); double hrs = Math.floor(min / 60); ts.set(Calendar.HOUR_OF_DAY, (int) hrs); ts.set(Calendar.MINUTE, (int) (min - hrs * 60)); ts.set(Calendar.SECOND, (int) (time - min * 60)); OutputParameters params = new OutputParameters( exportflows, 0 == scenario.clock.getCurrentstep() ? 1 : outsteps, scenario.getSimDtInSeconds() * outsteps); for (com.relteq.sirius.jaxb.Network network : scenario.getNetworkList().getNetwork()) { for (com.relteq.sirius.jaxb.Link link : network.getLinkList().getLink()) { Link _link = (Link) link; try { LinkDataTotal db_ldt = fill_total(_link, params); fill_detailed(_link, params, db_ldt.getSpeed()); } catch (Exception exc) { throw new SiriusException(exc); } finally { _link.reset_cumulative(); } } } success = true; }
@Test public void testGetNextFeature() throws Exception { Lane n = mock(Lane.class); when(n.getID()).thenReturn(new ID("next lane")); link.out = n; assertEquals(new ID("next lane"), link.getNextFeature().getID()); }
@Test public void testGetPreviousFeature() throws Exception { Lane p = mock(Lane.class); when(p.getID()).thenReturn(new ID("previous lane")); link.in = p; assertEquals(new ID("previous lane"), link.getPreviousFeature().getID()); }
public void print() throws IOException { /*BufferedWriter bw = new BufferedWriter(new FileWriter("out/salidaH.txt"));*/ System.out.println("\n ---- CAPA OCULTA ----\n"); // el for recorre todas las neuronas menos la ultima q es el bias for (int index = 0; index < this.neuronList.size() - 1; index++) { Neuron neuron = this.neuronList.get(index); System.out.println( "Neurona " + String.valueOf(index) + ": Entrada=>" + String.valueOf(neuron.getInput()) + " || Salida: " + String.valueOf(neuron.getOutput()) + "\n"); List<Link> inputs = neuron.getInputs(); for (int i = 0; i < inputs.size(); i++) { Link enlace = inputs.get(i); System.out.println( " Conexion => Valor: " + String.valueOf(enlace.getNeuron().getOutput()) + " || Peso: " + String.valueOf(enlace.getWeight()) + "\n"); } } /*bw.append("Bias Capa Oculta: "+String.valueOf(this.bias.getInput())); bw.close();*/ }
public void print() { Link current = head; while (current != null) { System.out.println(current.Data()); current = current.next; } }
// Move curr one step left; no change if now at front public void prev() { if (head.next() == curr) return; // No previous element Link temp = head; // March down list until we find the previous element while (temp.next() != curr) temp = temp.next(); curr = temp; }
// Return the position of the current element public int currPos() { Link temp = head.next(); int i; for (i=0; curr != temp; i++) temp = temp.next(); return i; }
/** * Constructor used by a server to let the client know what types of gestures the server can * receive. This constructor automatically writes out the header and descriptor to the link. It * does not call the link.end() method to end the transmission, since this will probably be sent * along with other sections in a communication to the client. * * @param link the link to write to. * @param descriptor a masked integer (see constants) describing the event to receive. * @param sectionEnder the endType string to use for this description, either Link.END_TOTAL if * this is the last section to the client, or END_SECTION if there are more sections * following. */ public LinkActionRequest(Link link, int descriptor, String sectionEnder) throws IOException { link.start(Link.ACTION_REQUEST_HEADER); link.dos.writeFloat(version); descriptor = LinkUtil.setMask(descriptor, CLIENT_NOTIFICATION_MASK); link.dos.writeInt(descriptor); link.end(sectionEnder); }
private static Set<Link> getLinks(ArrayList<String> linkList, Entry entry) { Set<Link> existingLinks = entry.getLinks(); Set<Link> links = new HashSet<>(); if (existingLinks == null) existingLinks = new HashSet<>(); if (linkList == null) return existingLinks; for (int i = 0; i < linkList.size(); i++) { String currentItem = linkList.get(i); Link link; if (existingLinks.size() > i) { link = (Link) existingLinks.toArray()[i]; } else { link = new Link(); existingLinks.add(link); } link.setLink(currentItem); link.setEntry(entry); links.add(link); } return links; }
/** * Retrieve all links of with the given rel * * @param rel attribute of link to search for * @return List of found Links */ public List<Link> findLinksByRel(String rel) { List<Link> foundLinks = new ArrayList<Link>(); for (Link link : this) { if (rel.equals(link.getRel())) foundLinks.add(link); } return foundLinks; }
@Override public void prepareView(ContentContext ctx) throws Exception { super.prepareView(ctx); ctx = ctx.getContextWithArea(getMainArea(ctx)); MenuElement myPage = getPage(); ContentElementList content = myPage.getContent(ctx); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); PrintStream out = new PrintStream(outStream); Collection<Link> links = new LinkedList<Link>(); while (content.hasNext(ctx)) { IContentVisualComponent comp = content.next(ctx); if (comp instanceof ISubTitle) { ISubTitle subTitle = (ISubTitle) comp; if (subTitle.getSubTitleLevel(ctx) > 1) { Link link = new Link(); link.setLabel(subTitle.getSubTitle(ctx)); link.setUrl("#" + subTitle.getXHTMLId(ctx)); link.setLevel("" + subTitle.getSubTitleLevel(ctx)); links.add(link); } } } out.close(); ctx.getRequest().setAttribute("links", links); }
public static void toCRAWDAD(LinkTrace links, OutputStream out, double timeMul) throws IOException { StatefulReader<LinkEvent, Link> linkReader = links.getReader(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); Map<Link, Long> activeContacts = new AdjacencyMap.Links<Long>(); linkReader.seek(links.minTime()); for (Link l : linkReader.referenceState()) activeContacts.put(l, links.minTime()); while (linkReader.hasNext()) { for (LinkEvent lev : linkReader.next()) { Link l = lev.link(); if (lev.isUp()) { activeContacts.put(l, linkReader.time()); } else { double b = activeContacts.get(l) * timeMul; double e = linkReader.time() * timeMul; activeContacts.remove(l); bw.write(l.id1() + "\t" + l.id2() + "\t" + b + "\t" + e + "\n"); } } } linkReader.close(); bw.close(); }
public static void readData(File f) { Scanner sc = null; try { sc = new Scanner(f); while (sc.hasNextLine()) { String line = sc.nextLine(); // Split the line by space String[] links = line.trim().split("\\s+"); Link currentLink = linkMap.get(links[0]); if (currentLink == null) { currentLink = new Link(links[0]); linkMap.put(links[0], currentLink); } for (int idx = 1; idx < links.length; idx++) { Link inLink = linkMap.get(links[idx]); if (inLink == null) { inLink = new Link(links[idx]); linkMap.put(links[idx], inLink); } currentLink.getInLinks().add(inLink); inLink.getOutLinks().add(currentLink); } } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (sc != null) { sc.close(); } } }
/** * This method will authenticate the map, whether its an acceptable map or not. * * @return A string which indicates the map problems (null string for no problem) */ public String validateMap() { // boolean verifyMap = true; String result = ""; // Check if a state is isolated for (State tempState : myStateList) { Boolean isolated = true; for (Link tempLink : myLinkList) { if (tempLink.getSourceState().getStateID() == tempState.getStateID() || tempLink.getDestintionState().getStateID() == tempState.getStateID()) { isolated = false; break; } } if (isolated) result += "<br>" + tempState.getStateName() + " is an isolated state."; } // Check if there are more than one country if (myCountryList.size() <= 1) result += "<br>" + "The map has less than two countries."; // Check if each country has exactly one capital for (Country tempCountry : myCountryList) { int capitalCount = 0; for (State tempState : myStateList) { if (tempState.getCountryID() == tempCountry.getCountryID() && tempState.getIsCapital()) capitalCount++; } if (capitalCount == 0) result += "<br>" + tempCountry.getCountryName() + " doesn't have any capital."; else if (capitalCount > 1) result += "<br>" + tempCountry.getCountryName() + " has more than one capital."; } return result; }
/** * Translates the link structure into the cell structure depending on healthy detector locations */ public void createCellStructure() { int i = 0; while (i < mainlineLinks.size() - 1) { if (mainlineLinks.get(i).isHasDetector() & mainlineLinks.get(i).getDetectorML().getHealthStatus() == 100) { Cell c = new Cell((int) totalTimeInHours * 60 / 5); c.addLink(mainlineLinks.get(i)); c.setDetectorML(mainlineLinks.get(i).getDetectorML()); c.setDetectorHOV(mainlineLinks.get(i).getDetectorHOV()); while (!mainlineLinks.get(i + 1).isHasDetector() & i < mainlineLinks.size() - 2 | (mainlineLinks.get(i + 1).isHasDetector() & mainlineLinks.get(i + 1).getDetectorML().getHealthStatus() != 100)) { c.addLink(mainlineLinks.get(i + 1)); i++; } // Onramps and Offramps in the Cell for (Link l : c.getLinks()) { c.addToOnrampPerLink(l.getUpNode().getInLinks().size() - 1); c.addToOfframpPerLink(l.getDownNode().getOutLinks().size() - 1); for (int linkID : l.getUpNode().getInLinks()) { if (links.get(linkID).getLinkType().equals("onramp")) { if (links.get(linkID).getDetectorML().getFlowData().isEmpty() | links.get(linkID).getDetectorML().getHealthStatus() != 100) { c.addToImputeOR(true); c.appendZeroColumnToMeasuredOnrampFlow(); } else { c.appendColumnToMeasuredOnrampFlow( links.get(linkID).getDetectorML().getFlowDataArray()); c.addToImputeOR(false); } } } for (int linkID : l.getDownNode().getOutLinks()) { if (links.get(linkID).getLinkType().equals("offramp")) { if (links.get(linkID).getDetectorML().getFlowData().isEmpty() | links.get(linkID).getDetectorML().getHealthStatus() != 100) { c.addToImputeFR(true); c.appendZeroColumnToMeasuredOfframpFlow(); } else { c.appendColumnToMeasuredOfframpFlow( links.get(linkID).getDetectorML().getFlowDataArray()); c.addToImputeFR(false); } } } } cells.add(c); } i++; } i = 0; }
public Attachement(String name, Interface from, Interface to) throws NoDifferentsTypesException { super(name); if (from.getType().equals(to.getType())) { throw new NoDifferentsTypesException(); } super.setFrom(from); super.setTo(to); }
public Link getAt(int index) { if (index < 0 || index >= listCount) return null; // if the index wasn't found do not continue Link c = first; // begin at the beginning for (int i = 0; i < index; i++) { // loop until index c = c.getNext(); // get the next Link } return c; }
@Test public void testIsDeadEnd() throws Exception { assertTrue(link.isDeadEnd()); link.in = mock(Lane.class); assertTrue(link.isDeadEnd()); link.out = mock(Lane.class); assertFalse(link.isDeadEnd()); }
private static double getEntropyAndResetRank() { double entropy = 0; for (Link link : linkMap.values()) { entropy -= link.getNewPageRank() * (Math.log(link.getNewPageRank()) / Math.log(2)); link.setOldPageRank(link.getNewPageRank()); } return entropy; }