• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Random IO  RSS feed

 
(instanceof Sidekick)
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
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)
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!