This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Random IO  RSS feed

 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a thread that came from a question in one of the general Java forums about replacing a string in a file. I suggested one solution might be to update the file in place and to test that out I made a little class that reads and writes and updates a text file with fixed length records.
As a teaser, here's the JUnit tests that helped me build it. These tests are in the order they were written and implemented. They don't show the history of refactoring of method granularity and names that went on through the process. I'd like to refactor this as well - get rid of all the quoted filename literals - but no time now.

For grins, think about what it would take to make this thing truly useful. A way to remove records. Hmmm, can't shift the file contents down, so we'd have to save empty slots. A way to track empty slots for future inserts. A way to track the order records were added, not just the order they're in now. An indexing scheme so we could find records by key. Maybe a way to store records physically in key order. Pretty soon you've invented VSAM!
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For that matter, you're probably halfway through the SCJD assignment at this point.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading about ternary search trees today and wondering if I could stick multiple indices on one of these files. Dangerous road, could really chew up a lot of time! Anyhow, here's my simple implementation to run those tests:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!