Search Results

Search found 11153 results on 447 pages for 'count zero'.

Page 39/447 | < Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >

  • How to count occurrence of an element in a List

    - by MM
    I have an ArrayList a collection class of java as follows. ArrayList<String>animals = new ArrayList<String>(); animals.add("bat"); animals.add("owl"); animals.add("bat"); animals.add("bat"); As you can see the animals ArrayList consists of 3 bat elements and one owl element. I was wondering if there is any API in collection framework that returns the number of bat occurrences or is there a way to determine number of occurrences. I found that google's collection multiset does have an api that returns total number of occurrences of an element. But that is compatible only with jdk1.5. Our product is currently in jdk 1.6. Hence cannot use it.

    Read the article

  • How to get the git commit count?

    - by Splo
    I'd like to get the number of commits of my git repository, a bit like SVN revision numbers. The goal is to use it as a unique, incrementing build number. I currently do like that, on Unix/Cygwin/msysGit: git log --pretty=format:'' | wc -l But I feel it's a bit of a hack. Is there a better way to do that? It would be cool if I actually didn't need wc or even git, so it could work on a bare Windows. Just read a file or a directory structure ...

    Read the article

  • Nhibernate mapping: fixed count multiple members instead of collection

    - by AhmetC
    I don't want to put wheels into a collection. How can i map kind of relation? Class Wheel { int id; Car Owner; } Class Car { int id; Wheel Wheel1; Wheel Wheel2; Wheel Wheel3; Wheel Wheel4; } I tried this but Wheelmap.Owner comes always null : Class WheelMap : ClassMap<Wheel> { Id(x=>x.Id); References(x=>x.Owner); } Class CarMap : ClassMap<Car> { Id(x=>x.Id); References(x=>x.Wheel1).Cascade.All(); References(x=>x.Wheel2).Cascade.All(); References(x=>x.Wheel3).Cascade.All(); References(x=>x.Wheel4).Cascade.All(); }

    Read the article

  • how calculate the count of views?

    - by Syom
    just yesterday i finished one site, which provides video watching. but now i need to show the number of views of each film. i never wrote such thing, so i don't know what to do. maybe i must add one field in mysql database, and increase it every time the video opened? but i use flash player, and i can't wrote script onclick of player. so, could you give me an idea... thanks

    Read the article

  • Count bits used in int

    - by sigvardsen
    If you have the binary number 10110 how can I get it to return 5? e.g a number that tells how many bits are used? There are some likewise examples listed below: 101 should return 3 000000011 should return 2 11100 should return 5 101010101 should return 9 How can this be obtained the easiest way in Java? I have come up with the following method but can i be done faster: public static int getBitLength(int value) { int l = 1; if (value >> 16 > 0) { value = value >> 16; l += 16; } if (value >> 8 > 0) { value = value >> 8; l += 8; } if (value >> 4 > 0) { value = value >> 4; l += 4; } if (value >> 2 > 0) { value = value >> 2; l += 2; } if (value >> 1 > 0) { value = value >> 1; l += 1; } return l; }

    Read the article

  • Truncate a UTF-8 string to fit a given byte count in PHP

    - by fsb
    Say we have a UTF-8 string $s and we need to shorten it so it can be stored in N bytes. Blindly truncating it to N bytes could mess it up. But decoding it to find the character boundaries is a drag. Is there a tidy way? [Edit 20100414] In addition to S.Mark’s answer: mb_strcut(), I recently found another function to do the job: grapheme_extract($s, $n, GRAPHEME_EXTR_MAXBYTES); from the intl extension. Since intl is an ICU wrapper, I have a lot of confidence in it.

    Read the article

  • Count the number of lines in a Java String

    - by Simon Guo
    Need some compact code for counting the number of lines in a string in Java. The string is to be separated by \r or \n. Each instance of those newline characters will be considered as a separate line. For example, "Hello\nWorld\nThis\nIs\t" should return 4. The prototype is private static int countLines(String str) {...} Can someone provide a compact set of statements? I have solution at here but it is too long, I think. Thank you.

    Read the article

  • Split comma separated string to count duplicates

    - by josepv
    I have the following data in my database (comma separated strings): "word, test, hello" "test, lorem, word" "test" ... etc How can I transform this data into a Dictionary whereby each string is separated into each distinct word together with the number of times that it occurs, i.e. {"test", 3}, {"word", 2}, {"hello", 1}, {"lorem", 1} I will have approximately 3000 rows of data in case this makes a difference to any solution offered. Also I am using .NET 3.5 (and would be interested to see any solution using linq)

    Read the article

  • PHP: Count-IF for Arrays

    - by st4ck0v3rfl0w
    Hi All, What would be the most efficient way of counting the number of times a value appears inside an array? Example Array ('apple','apple','banana','banana','kiwi') Ultimately I want a function to spit out the percentages for charting purposes (e.g. apple = 40%, banana = 40%, kiwi = 20%)

    Read the article

  • Incremement Page Hit Count in Django

    - by Andrew C
    I have a table with an IntegerField (hit_count), and when a page is visited (ie. http://site/page/3) I want record id 3 'hit_count' column in the database to increment by 1. The query should be like: update table set hit_count = hit_count + 1 where id=3 Can I do this with the standard Django Model conventions? Or should I just write the query by hand? I'm starting a new project, so I am trying to avoid hacks. We'll see how long this lasts! Thanks!

    Read the article

  • PHP Menu Items Count then add under more button

    - by Adrian M.
    Hello, I use the bellow code to load the main menu elements from some CMS, the present code is perfect except that it loads ALL the main items on a single line of menu - which will make the width of it unusable in any centered design (under 1000px).. I want to change this script so after 15 main elements will add a "MORE" button under which the rest of the main menu items will show as sub-items of this "MORE" button (they will not have their own sub-items as the first 15 do).. How can I do it? Thanks! <?php require_once( '../../../inc/header.inc.php' ); require_once( DIRECTORY_PATH_INC . 'membership_levels.inc.php' ); require_once( DIRECTORY_PATH_ROOT . "templates/tmpl_{$tmpl}/scripts/TemplMenu.php" ); class SimpleMenu extends TemplMenu { function getCode() { $this->iElementsCntInLine = 100; $this->getMenuInfo(); $this->genTopItems(); return $this->sCode; } function genTopItem($sText, $sLink, $sTarget, $sOnclick, $bActive, $iItemID, $isBold = false, $sPicture = '') { $sActiveStyle = ($bActive) ? ' id="tm_active"' : ''; if (!$bActive) { $sAlt= $sOnclick ? ( ' alt="' . $sOnclick . '"' ) : ''; $sTarget = $sTarget ? ( ' target="_parent"' ) : ''; } $sLink = (strpos($sLink, 'http://') === false && !strlen($sOnclick)) ? $this->sSiteUrl . $sLink : $sLink; $sSubMenu = $this->getAllSubMenus($iItemID); $sImgTabStyle = $sPictureRep = ''; if ($isBold && $sPicture != '') { $sPicturePath = getTemplateIcon($sPicture); $sPictureRep = "<img src='{$sPicturePath}' style='vertical-align:middle;width:16px;height:16px;' />"; $sText = '&nbsp;'; $sImgTabStyle = 'style="width:38px;"'; } $sMainSubs = ($sSubMenu=='') ? '' : " {$sSubMenu} </a>"; $this->sCode .= " <li><a href='{$sLink}' {$sOnclick} target='_parent'>{$sPictureRep}{$sText}</a> <div id='submenu'> <ul> <li>{$sMainSubs}</li> </ul> </div> </li> "; } } $objMenu = new SimpleMenu(); echo "<ul id='ddmenu'>"; echo $objMenu->getCode(); echo "</ul>"; ?>

    Read the article

  • count how many days within a date range are within another date range

    - by joko13
    From October 1st to March 31 the fee is $1 (season 1). From April 1st to September 30 the fee is $2 (season 2). How can I calculate the total fee of a given date range (user input) depending on how many days of this date range fall into season 1 and season 2? The following gives me the number of days of the user´s date range, but I have no idea how to test against season 1 or season 2: $user_input_start_date = getdate( $a ); $user_input_end_date = getdate( $b ); $start_date_new = mktime( 12, 0, 0, $user_input_start_date['mon'], $user_input_start_date['mday'], $user_input_start_date['year'] ); $end_date_new = mktime( 12, 0, 0, $user_input_end_date['mon'], $user_input_end_date['mday'], $user_input_end_date['year'] ); return round( abs( $start_date_new - $end_date_new ) / 86400 ); Thanks for your help! EDIT: Given that a date range starts and ends in 2012 or starts in 2012 and ends in 2013 alone gives me 10 different possibilities of in which season a date range can start and where it can end. There must be a better solution than iterating if/else and comparing dates over and over again for the following conditions: Date range is completely within season 1 Date range starts in season 1 and ends in season 2 Date range starts in season 1, spans across season 2 and ends in the second part of season 1 ... and so forth with "Starts in season 2", etc

    Read the article

  • SQL using sum to count results of multiple subqueries

    - by asdas
    I have a table with 2 columns: integer and var char. I am given only the integer values but need to do work on the var char (string) values. Given an integer, and a list of other integers (no overlap), I want to find the string for that single integer. Then I want to take that string and do the INSTR command with that string, and all the other strings for all the other integers. Then I want the sum of all the INSTR so the result is one number. So lets say I have int x, and list y=[y0, y1, y2]. I want to do 3 INSTR commands like SUM(INSTR(string for x, string for y0), INSTR(string for x, string for y1), INSTR(string for x, string for y2)) I think im going in the wrong direction, this is what I have. Im not good with sub queries. SELECT SUM ( SELECT INSTR ( SELECT string FROM pages WHERE int=? LIMIT 1, ( SELECT string FROM pages WHERE id=? OR id=? OR id=? LIMIT 3 ) ) )

    Read the article

  • Count the number of rows of a CSV file, with d3.js

    - by user2934073
    Suppose I have this CSV file Day,What 2013-10-27,Apple 2013-10-27,Cake 2013-10-27,Apple 2013-10-28,Apple 2013-10-28,Apple 2013-10-28,Blueberry 2013-10-28,Orange I would like to drawn with D3.js a time-series graph. All I need to do is to display the sum of the number of rows for each day. As an example, the 27 of November should have 3 as value, the 28th should have 4. Is there a way I can archive it? I've been trying to create a new dataset out of the CSV one with no positive results. var dataset; d3.csv("data.csv", function(d) { return { Day: new Date(d.Day), What: d.What }; }, function(error, rows) { dataset = rows; // I SUPPOSE THE FUNCTION THAT GENERATE THE NEW DATASET SHOULD GO THERE });

    Read the article

  • Count How many lines in a Java String

    - by Simon Guo
    Need some compact code for counting how many lines in a string. It should be Java Code. And the string is separated by \r or \n will be considered as a separate line. For example, "Hello\nWorld\nThis\nIs\t" should return 4. The prototype is private static int countLines(String str) {...} Can someone provide a compact code? I have solution at here but it is too long, I think. Thank you.

    Read the article

  • Retain Count Question: Some Guidance, Please

    - by yar
    [I'm sure this is not odd at all, but I need just a bit of help] I have two retain properties @property (nonatomic, retain) NSArray *listContent; @property (nonatomic, retain) NSArray *filteredListContent; and in the viewDidLoad method I set the second equal to the first (so now the retainCount is two, I think): self.filteredListContent = self.listContent; and then on every search I do this self.filteredListContent = [listContent filteredArrayUsingPredicate:predicate]; I thought I should do a release right above this assignment -- since the property should cause an extra retain, right? -- but that causes the program to explode the second time I run the search method. The retain counts (without the extra release) are 2 the first time I come into the search method, and 1 each subsequent time (which is what I expected, unfortunately). Some guidance would help, thanks! Is it correct to not release?

    Read the article

  • php count rss entries since a specific date/time

    - by Steven
    can anyone tell me why this code don't work: $q = $_GET['q']; // Load and parse the XML document $rss = simplexml_load_file("http://search.twitter.com/search.atom?lang=en&q=$q&rpp=100&page=1"); $Count1 = 0; while(strtotime($rss->entry->published)>1270833600){ foreach ($rss->entry as $item) { $Count1++; } } print "Total Record: ".$Count1;

    Read the article

  • MySQL Select Statement - Two Tables, Sort One Table by Count of Other Table

    - by Robert Boka
    So I have built a voting system for a custom post system i wrote. I want to be able to sort by "most voted", "Most liked", etc. I have two tables. Entry: ID, Title, Post Vote: ID, EntryID, Result I want to be able to query the vote table for each entry and see how many vote's there are, and then sort the entry's by how many vote's each table had. I have messed around with joins, etc. and cannot seem to figure it out. Any suggestions?

    Read the article

  • Suggestions on how to track tag count for a particular object

    - by Robin Fisher
    Hi, I'm looking for suggestions on how to track the number of tags associated with a particular object in Rails. I'm using acts_as_taggable_on and it's working fine. What I would like to be able to do is search for all objects that have no tags, preferably through a scope i.e. Object.untagged.all My first thought was to use an after_save callback to update an attribute called "taggings_count" in my model: def update_taggings_count self.taggings_count = self.tag_list.size self.save end Unfortunately, this does the obvious thing of putting me in an infinite loop. I need to use an after_save callback because the tag_list is not updated until the main object is saved. Would appreciate any suggestions as I'm on the verge of rolling my own tagging system. Regards Robin

    Read the article

< Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >