Coder Social home page Coder Social logo

arbeidskrav's Introduction

  • ⚡ Curious programmer
  • 🔭 Throwing away throwaway society at Tings
  • ❄️ Continually trying to improve at cycling

arbeidskrav's People

Contributors

olaven avatar

Watchers

 avatar  avatar  avatar

arbeidskrav's Issues

MeterArchive.Move bug

public boolean move(String identification, String newLocation) {
Meter meter = fetch(identification);
if (meter == null)
return false;
//the meter was fetched, starting to alter
meter.setLocation(newLocation);
return true;
}

You are not checking whether the position you are moving the Meter to is already in use. If this is the case both Meters will share the same position, but only one will be retrievable from the MeterArchive.

I propose you check whether the position is already in use before you move the Meter, and if so, swap position with the other Meter than had the position you want to move to.

Put the build instructions on two lines

In /V18_1/besvarelse/README.md you write the two build commands on a single line. This might confuse people and render them unable to try the demo! I propose you stick them on two lines like so:

javac *
java Client

Why are you checking for an empty string?

public void setText(String text){
if(text.length() > 0)
this.text = text;
}
public void setAnswer(String answer){
if(answer.length() > 0)
this.answer = answer;
}

You could argue that it makes sense to verify that the string is not null, but I would argument strongly against an empty string.
Firstly, unlike null an empty string will not crash your program, and there are tons of valid reasons why you might want one.
Secondly, I think it is fairly safe to assume that the questions will not change after initialization, and if that is the case then the constructor is the only place where those setters are being used, so if a question is initialized with an empty string then the question will just be an empty string regardless!
Lastly; if questions indeed are immutable after initialization then the setters are entirely redundant altogether.

MeterArchive.fetch is ridiculously slow

public Meter fetch(String identification) {
for (Meter meter : meters) {
if (meter.getIdentification() == identification) {
return meter;
}
}
return null;
}

MeterArchive.fetch (and consequently all of the other methods in MeterArchive) has time complexity O(N) - this is ridiculously slow for a lookup! With as little as a couple of million meters in the archive the user would have to wait for seconds to do a lookup, and in that time they might as well go look themselves. Yuck!

There are approximately two solutions to this:

Change data-structure

Arrays are not meant for lookup, they are for fast access if you know the index of what you want. Consider switching from ArrayList to something like a HashMap that has O(1) lookup.
Have a look at the big o cheat sheet for the time complexity of different data-structures.

Be clever

If you have to store the Meters in an array, you can store them in sorted order (sorted on the reference number). Then when you want to look for a Meter you can play the number guessing game:
Take the middle meter out of the list and compare its reference number against the one you are looking for. If it is smaller/greater you repeat for the lower/upper half of the list. Continue doing this until you find an element that is equal. This has time complexity O(log N).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.